diff --git a/DepthsBelow/DepthsBelow/Component/PixelTransform.cs b/DepthsBelow/DepthsBelow/Component/PixelTransform.cs index 1dfb9eb..6a018b0 100644 --- a/DepthsBelow/DepthsBelow/Component/PixelTransform.cs +++ b/DepthsBelow/DepthsBelow/Component/PixelTransform.cs @@ -32,14 +32,14 @@ namespace DepthsBelow.Component } } public float Rotation; - public Point Origin; + public Vector2 Origin; public PixelTransform(Entity parent) : base(parent) { Position = Vector2.Zero; Rotation = 0.0f; - Origin = Point.Zero; + Origin = Vector2.Zero; } } } diff --git a/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs b/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs index 6bd66e7..ab0972b 100644 --- a/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs +++ b/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs @@ -11,16 +11,21 @@ namespace DepthsBelow.Component { public Texture2D Texture; public Color Color; + public float Scale; + public SpriteEffects SpriteEffects; public SpriteRenderer(Entity parent) : base(parent) { this.Color = Color.White; + this.Scale = 1; + this.SpriteEffects = SpriteEffects.None; } public void Draw(SpriteBatch spriteBatch) { - PixelTransform tc = this.Parent.GetComponent(); - spriteBatch.Draw(Texture, tc.Position, this.Color); + PixelTransform transform = this.Parent.GetComponent(); + //spriteBatch.Draw(Texture, tc.Position, this.Color); + spriteBatch.Draw(Texture, transform.Position + transform.Origin, null, Color, transform.Rotation, transform.Origin, Scale, SpriteEffects, 0); } } } diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj.Debug.cachefile b/DepthsBelow/DepthsBelow/DepthsBelow.csproj.Debug.cachefile index 5acaedc..ea6fd92 100644 --- a/DepthsBelow/DepthsBelow/DepthsBelow.csproj.Debug.cachefile +++ b/DepthsBelow/DepthsBelow/DepthsBelow.csproj.Debug.cachefile @@ -2,3 +2,4 @@ Content\images\soldier.xnb Content\maps\tilesets\aztek.xnb Content\maps\test.xnb Content\aztek.xnb +Content\images\soldier2.xnb diff --git a/DepthsBelow/DepthsBelow/Soldier.cs b/DepthsBelow/DepthsBelow/Soldier.cs index d3ff51d..fa3cf02 100644 --- a/DepthsBelow/DepthsBelow/Soldier.cs +++ b/DepthsBelow/DepthsBelow/Soldier.cs @@ -1,4 +1,5 @@ -using DepthsBelow.Component; +using System; +using DepthsBelow.Component; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -8,6 +9,7 @@ namespace DepthsBelow public class Soldier : Entity { public static Texture2D Texture; + public static Point Origin; private bool _selected; private Core game; @@ -20,7 +22,9 @@ namespace DepthsBelow if (Texture == null) 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); var cc = new Collision(this, 32, 32); @@ -39,7 +43,7 @@ namespace DepthsBelow public static void LoadContent(Core game) { - Texture = game.Content.Load("images/soldier"); + Texture = game.Content.Load("images/soldier2"); } public override void Update(GameTime gameTime) @@ -47,23 +51,36 @@ namespace DepthsBelow base.Update(gameTime); KeyboardState ks = Keyboard.GetState(); if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right)) + { gridTransform.X += 1; + pixelTransform.Rotation = (float)0; + } + if (ks.IsKeyDown(Keys.Left) && lastKeyboardState.IsKeyUp(Keys.Left)) + { gridTransform.X -= 1; + pixelTransform.Rotation = (float)Math.PI; + } if (ks.IsKeyDown(Keys.Up) && lastKeyboardState.IsKeyUp(Keys.Up)) + { gridTransform.Y -= 1; + pixelTransform.Rotation = (float)(3.0f*Math.PI/2.0f); + } if (ks.IsKeyDown(Keys.Down) && lastKeyboardState.IsKeyUp(Keys.Down)) + { gridTransform.Y += 1; + pixelTransform.Rotation = (float)(Math.PI / 2.0f); + } lastKeyboardState = ks; int speed = 2; if (pixelTransform.X < gridTransform.X * 32) pixelTransform.X += speed; - if (pixelTransform.X > gridTransform.X * 32) + else if (pixelTransform.X > gridTransform.X * 32) pixelTransform.X -= speed; - if (pixelTransform.Y < gridTransform.Y * 32) + else if (pixelTransform.Y < gridTransform.Y * 32) pixelTransform.Y += speed; - if (pixelTransform.Y > gridTransform.Y * 32) + else if (pixelTransform.Y > gridTransform.Y * 32) pixelTransform.Y -= speed; } } diff --git a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj index 9c0c5e5..2e70a1d 100644 --- a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj +++ b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj @@ -70,6 +70,13 @@ TextureProcessor + + + soldier2 + TextureImporter + TextureProcessor + +