diff --git a/DepthsBelow/DepthsBelow/Component.cs b/DepthsBelow/DepthsBelow/Component/Component.cs similarity index 81% rename from DepthsBelow/DepthsBelow/Component.cs rename to DepthsBelow/DepthsBelow/Component/Component.cs index 5b8c8e7..9efe208 100644 --- a/DepthsBelow/DepthsBelow/Component.cs +++ b/DepthsBelow/DepthsBelow/Component/Component.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -namespace DepthsBelow +namespace DepthsBelow.Component { public class Component { diff --git a/DepthsBelow/DepthsBelow/Component/GridTransform.cs b/DepthsBelow/DepthsBelow/Component/GridTransform.cs new file mode 100644 index 0000000..4fba34d --- /dev/null +++ b/DepthsBelow/DepthsBelow/Component/GridTransform.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; + +namespace DepthsBelow.Component +{ + public class GridTransform : Component + { + public Vector2 Position; + public float X + { + get + { + return Position.X; + } + set + { + Position.X = X; + } + } + public float Y + { + get + { + return Position.Y; + } + set + { + Position.Y = Y; + } + } + + public GridTransform(Entity parent) : base(parent) + { + Position = Vector2.Zero; + } + } +} diff --git a/DepthsBelow/DepthsBelow/Component/PixelTransform.cs b/DepthsBelow/DepthsBelow/Component/PixelTransform.cs new file mode 100644 index 0000000..5b0d338 --- /dev/null +++ b/DepthsBelow/DepthsBelow/Component/PixelTransform.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; + +namespace DepthsBelow.Component +{ + public class PixelTransform : Component + { + public Vector2 Position; + public float X + { + get + { + return Position.X; + } + set + { + Position.X = X; + } + } + public float Y + { + get + { + return Position.Y; + } + set + { + Position.Y = Y; + } + } + public float Rotation; + public Point Origin; + + public PixelTransform(Entity parent) + : base(parent) + { + Position = Vector2.Zero; + Rotation = 0.0f; + Origin = Point.Zero; + } + } +} diff --git a/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs b/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs new file mode 100644 index 0000000..6bd66e7 --- /dev/null +++ b/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace DepthsBelow.Component +{ + public class SpriteRenderer : Component + { + public Texture2D Texture; + public Color Color; + + public SpriteRenderer(Entity parent) : base(parent) + { + this.Color = Color.White; + } + + public void Draw(SpriteBatch spriteBatch) + { + PixelTransform tc = this.Parent.GetComponent(); + spriteBatch.Draw(Texture, tc.Position, this.Color); + } + } +} diff --git a/DepthsBelow/DepthsBelow/Core.cs b/DepthsBelow/DepthsBelow/Core.cs index da65ce2..19d8d83 100644 --- a/DepthsBelow/DepthsBelow/Core.cs +++ b/DepthsBelow/DepthsBelow/Core.cs @@ -28,7 +28,7 @@ namespace DepthsBelow graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; - graphics.IsFullScreen = false; + graphics.IsFullScreen = true; this.IsMouseVisible = true; } @@ -97,7 +97,7 @@ namespace DepthsBelow // TODO: Add your drawing code here spriteBatch.Begin(); - SpriteRenderComponent rc = soldier.GetComponent(); + Component.SpriteRenderer rc = soldier.GetComponent(); if (rc != null) rc.Draw(spriteBatch); spriteBatch.End(); diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj b/DepthsBelow/DepthsBelow/DepthsBelow.csproj index 4cdb0e8..9494bb8 100644 --- a/DepthsBelow/DepthsBelow/DepthsBelow.csproj +++ b/DepthsBelow/DepthsBelow/DepthsBelow.csproj @@ -120,14 +120,15 @@ - + + - + - + diff --git a/DepthsBelow/DepthsBelow/Entity.cs b/DepthsBelow/DepthsBelow/Entity.cs index d42416d..611a7ec 100644 --- a/DepthsBelow/DepthsBelow/Entity.cs +++ b/DepthsBelow/DepthsBelow/Entity.cs @@ -2,22 +2,26 @@ using System.Collections.Generic; using System.Linq; using System.Text; - namespace DepthsBelow { public class Entity { - List Components; - public TransformComponent transform; + List Components; + public Component.PixelTransform pixelTransform; + public Component.GridTransform gridTransform; public Entity() { - Components = new List(); + Components = new List(); + pixelTransform = new Component.PixelTransform(this); + AddComponent(pixelTransform); + gridTransform = new Component.GridTransform(this); + AddComponent(gridTransform); } - public T GetComponent() where T : Component + public T GetComponent() where T : Component.Component { - foreach (Component c in Components) + foreach (Component.Component c in Components) { if (c is T) return (T)c; @@ -26,12 +30,9 @@ namespace DepthsBelow return null; } - public void AddComponent(Component c) + public void AddComponent(Component.Component c) { Components.Add(c); - - if (c is TransformComponent) - this.transform =(TransformComponent)c; } } } diff --git a/DepthsBelow/DepthsBelow/RenderComponent.cs b/DepthsBelow/DepthsBelow/RenderComponent.cs deleted file mode 100644 index 4bea7b0..0000000 --- a/DepthsBelow/DepthsBelow/RenderComponent.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace DepthsBelow -{ - public class SpriteRenderComponent : Component - { - public Texture2D Texture; - - public SpriteRenderComponent(Entity parent) : base(parent) - { - - } - - public void Draw(SpriteBatch spriteBatch) - { - TransformComponent tc = this.Parent.GetComponent(); - spriteBatch.Draw(Texture, tc.Position, Color.White); - } - } -} diff --git a/DepthsBelow/DepthsBelow/Soldier.cs b/DepthsBelow/DepthsBelow/Soldier.cs index ae82baa..4b18be3 100644 --- a/DepthsBelow/DepthsBelow/Soldier.cs +++ b/DepthsBelow/DepthsBelow/Soldier.cs @@ -15,6 +15,8 @@ namespace DepthsBelow Core game; static Texture2D Texture; + private KeyboardState lastKeyboardState; + static public void LoadContent(Core game) { Texture = game.Content.Load("images/soldier"); @@ -25,18 +27,24 @@ namespace DepthsBelow if (Texture == null) LoadContent(game); - SpriteRenderComponent rc = new SpriteRenderComponent(this); + Component.SpriteRenderer rc = new Component.SpriteRenderer(this); rc.Texture = Texture; + rc.Color = Color.HotPink; this.AddComponent(rc); - - this.AddComponent(new TransformComponent(this)); } public void Update(GameTime gameTime) { KeyboardState ks = Keyboard.GetState(); - if (ks.IsKeyDown(Keys.Left)) - transform.Position.X--; + if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right)) + gridTransform.Position.X += 1; + lastKeyboardState = ks; + + Console.WriteLine(pixelTransform.X + " " + gridTransform.X); + if (pixelTransform.Position.X < gridTransform.X * 32) + { + pixelTransform.Position.X += 2; + } } } } diff --git a/DepthsBelow/DepthsBelow/TransformComponent.cs b/DepthsBelow/DepthsBelow/TransformComponent.cs deleted file mode 100644 index da5a230..0000000 --- a/DepthsBelow/DepthsBelow/TransformComponent.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Xna.Framework; - -namespace DepthsBelow -{ - public class TransformComponent : Component - { - public Vector2 Position; - public float Rotation; - public Point Origin; - - public TransformComponent(Entity parent) : base(parent) - { - Position = Vector2.Zero; - Rotation = 0.0f; - Origin = Point.Zero; - } - } -} diff --git a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj index ac67505..d3cb582 100644 --- a/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj +++ b/DepthsBelow/DepthsBelowContent/DepthsBelowContent.contentproj @@ -42,7 +42,7 @@ - + soldier TextureImporter TextureProcessor diff --git a/DepthsBelow/DepthsBelowContent/images/soldier.bmp b/DepthsBelow/DepthsBelowContent/images/soldier.bmp deleted file mode 100644 index 9d0961c..0000000 Binary files a/DepthsBelow/DepthsBelowContent/images/soldier.bmp and /dev/null differ diff --git a/DepthsBelow/DepthsBelowContent/images/soldier.png b/DepthsBelow/DepthsBelowContent/images/soldier.png new file mode 100644 index 0000000..1aa2d70 Binary files /dev/null and b/DepthsBelow/DepthsBelowContent/images/soldier.png differ