Less pink soldier
This commit is contained in:
@@ -32,14 +32,14 @@ namespace DepthsBelow.Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public float Rotation;
|
public float Rotation;
|
||||||
public Point Origin;
|
public Vector2 Origin;
|
||||||
|
|
||||||
public PixelTransform(Entity parent)
|
public PixelTransform(Entity parent)
|
||||||
: base(parent)
|
: base(parent)
|
||||||
{
|
{
|
||||||
Position = Vector2.Zero;
|
Position = Vector2.Zero;
|
||||||
Rotation = 0.0f;
|
Rotation = 0.0f;
|
||||||
Origin = Point.Zero;
|
Origin = Vector2.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,21 @@ namespace DepthsBelow.Component
|
|||||||
{
|
{
|
||||||
public Texture2D Texture;
|
public Texture2D Texture;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
|
public float Scale;
|
||||||
|
public SpriteEffects SpriteEffects;
|
||||||
|
|
||||||
public SpriteRenderer(Entity parent) : base(parent)
|
public SpriteRenderer(Entity parent) : base(parent)
|
||||||
{
|
{
|
||||||
this.Color = Color.White;
|
this.Color = Color.White;
|
||||||
|
this.Scale = 1;
|
||||||
|
this.SpriteEffects = SpriteEffects.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch)
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
PixelTransform tc = this.Parent.GetComponent<PixelTransform>();
|
PixelTransform transform = this.Parent.GetComponent<PixelTransform>();
|
||||||
spriteBatch.Draw(Texture, tc.Position, this.Color);
|
//spriteBatch.Draw(Texture, tc.Position, this.Color);
|
||||||
|
spriteBatch.Draw(Texture, transform.Position + transform.Origin, null, Color, transform.Rotation, transform.Origin, Scale, SpriteEffects, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ Content\images\soldier.xnb
|
|||||||
Content\maps\tilesets\aztek.xnb
|
Content\maps\tilesets\aztek.xnb
|
||||||
Content\maps\test.xnb
|
Content\maps\test.xnb
|
||||||
Content\aztek.xnb
|
Content\aztek.xnb
|
||||||
|
Content\images\soldier2.xnb
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using DepthsBelow.Component;
|
using System;
|
||||||
|
using DepthsBelow.Component;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
@@ -8,6 +9,7 @@ namespace DepthsBelow
|
|||||||
public class Soldier : Entity
|
public class Soldier : Entity
|
||||||
{
|
{
|
||||||
public static Texture2D Texture;
|
public static Texture2D Texture;
|
||||||
|
public static Point Origin;
|
||||||
private bool _selected;
|
private bool _selected;
|
||||||
private Core game;
|
private Core game;
|
||||||
|
|
||||||
@@ -20,7 +22,9 @@ namespace DepthsBelow
|
|||||||
if (Texture == null)
|
if (Texture == null)
|
||||||
LoadContent(game);
|
LoadContent(game);
|
||||||
|
|
||||||
var rc = new SpriteRenderer(this) {Texture = Texture, Color = Color.HotPink};
|
pixelTransform.Origin = new Vector2(16, 16);
|
||||||
|
|
||||||
|
var rc = new SpriteRenderer(this) {Texture = Texture, Color = Color.White};
|
||||||
AddComponent(rc);
|
AddComponent(rc);
|
||||||
|
|
||||||
var cc = new Collision(this, 32, 32);
|
var cc = new Collision(this, 32, 32);
|
||||||
@@ -39,7 +43,7 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
public static void LoadContent(Core game)
|
public static void LoadContent(Core game)
|
||||||
{
|
{
|
||||||
Texture = game.Content.Load<Texture2D>("images/soldier");
|
Texture = game.Content.Load<Texture2D>("images/soldier2");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
@@ -47,23 +51,36 @@ namespace DepthsBelow
|
|||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
KeyboardState ks = Keyboard.GetState();
|
KeyboardState ks = Keyboard.GetState();
|
||||||
if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right))
|
if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right))
|
||||||
|
{
|
||||||
gridTransform.X += 1;
|
gridTransform.X += 1;
|
||||||
|
pixelTransform.Rotation = (float)0;
|
||||||
|
}
|
||||||
|
|
||||||
if (ks.IsKeyDown(Keys.Left) && lastKeyboardState.IsKeyUp(Keys.Left))
|
if (ks.IsKeyDown(Keys.Left) && lastKeyboardState.IsKeyUp(Keys.Left))
|
||||||
|
{
|
||||||
gridTransform.X -= 1;
|
gridTransform.X -= 1;
|
||||||
|
pixelTransform.Rotation = (float)Math.PI;
|
||||||
|
}
|
||||||
if (ks.IsKeyDown(Keys.Up) && lastKeyboardState.IsKeyUp(Keys.Up))
|
if (ks.IsKeyDown(Keys.Up) && lastKeyboardState.IsKeyUp(Keys.Up))
|
||||||
|
{
|
||||||
gridTransform.Y -= 1;
|
gridTransform.Y -= 1;
|
||||||
|
pixelTransform.Rotation = (float)(3.0f*Math.PI/2.0f);
|
||||||
|
}
|
||||||
if (ks.IsKeyDown(Keys.Down) && lastKeyboardState.IsKeyUp(Keys.Down))
|
if (ks.IsKeyDown(Keys.Down) && lastKeyboardState.IsKeyUp(Keys.Down))
|
||||||
|
{
|
||||||
gridTransform.Y += 1;
|
gridTransform.Y += 1;
|
||||||
|
pixelTransform.Rotation = (float)(Math.PI / 2.0f);
|
||||||
|
}
|
||||||
lastKeyboardState = ks;
|
lastKeyboardState = ks;
|
||||||
|
|
||||||
int speed = 2;
|
int speed = 2;
|
||||||
if (pixelTransform.X < gridTransform.X * 32)
|
if (pixelTransform.X < gridTransform.X * 32)
|
||||||
pixelTransform.X += speed;
|
pixelTransform.X += speed;
|
||||||
if (pixelTransform.X > gridTransform.X * 32)
|
else if (pixelTransform.X > gridTransform.X * 32)
|
||||||
pixelTransform.X -= speed;
|
pixelTransform.X -= speed;
|
||||||
if (pixelTransform.Y < gridTransform.Y * 32)
|
else if (pixelTransform.Y < gridTransform.Y * 32)
|
||||||
pixelTransform.Y += speed;
|
pixelTransform.Y += speed;
|
||||||
if (pixelTransform.Y > gridTransform.Y * 32)
|
else if (pixelTransform.Y > gridTransform.Y * 32)
|
||||||
pixelTransform.Y -= speed;
|
pixelTransform.Y -= speed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,13 @@
|
|||||||
<Processor>TextureProcessor</Processor>
|
<Processor>TextureProcessor</Processor>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="images\soldier2.png">
|
||||||
|
<Name>soldier2</Name>
|
||||||
|
<Importer>TextureImporter</Importer>
|
||||||
|
<Processor>TextureProcessor</Processor>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Reference in New Issue
Block a user