From 76594ddddac86f6bba3e80dcde7f058278911805 Mon Sep 17 00:00:00 2001 From: Simon Holmberg Date: Mon, 24 Sep 2012 16:04:15 +0200 Subject: [PATCH] Did stuff --- .../DepthsBelow/{ => Component}/Component.cs | 2 +- .../DepthsBelow/Component/GridTransform.cs | 40 ++++++++++++++++ .../DepthsBelow/Component/PixelTransform.cs | 45 ++++++++++++++++++ .../DepthsBelow/Component/SpriteRenderer.cs | 26 ++++++++++ DepthsBelow/DepthsBelow/Core.cs | 4 +- DepthsBelow/DepthsBelow/DepthsBelow.csproj | 7 +-- DepthsBelow/DepthsBelow/Entity.cs | 21 ++++---- DepthsBelow/DepthsBelow/RenderComponent.cs | 25 ---------- DepthsBelow/DepthsBelow/Soldier.cs | 18 +++++-- DepthsBelow/DepthsBelow/TransformComponent.cs | 22 --------- .../DepthsBelowContent.contentproj | 2 +- .../DepthsBelowContent/images/soldier.bmp | Bin 1270 -> 0 bytes .../DepthsBelowContent/images/soldier.png | Bin 0 -> 405 bytes 13 files changed, 143 insertions(+), 69 deletions(-) rename DepthsBelow/DepthsBelow/{ => Component}/Component.cs (81%) create mode 100644 DepthsBelow/DepthsBelow/Component/GridTransform.cs create mode 100644 DepthsBelow/DepthsBelow/Component/PixelTransform.cs create mode 100644 DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs delete mode 100644 DepthsBelow/DepthsBelow/RenderComponent.cs delete mode 100644 DepthsBelow/DepthsBelow/TransformComponent.cs delete mode 100644 DepthsBelow/DepthsBelowContent/images/soldier.bmp create mode 100644 DepthsBelow/DepthsBelowContent/images/soldier.png 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 9d0961c06223ef771a54a99055af0346efd26a59..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1270 zcmcJO!41PO2t{3~19XfYJ45eXr)Q7m0g${+PnA-@7-Aa^ky0ll^Z_3?3D4K(ns~kO zdPjSRT~Z5ViBr-|jQo@`pDAbZ(C|Q~l!A968=q<0$V0<}5dF3VV7_`^;8hhgr%}2N z0mDN;L|W9O1`MEqy$bo#VoKM7Ib8~tbSa4VD#JofItxYIlOdsFyt?w(_|M$m<%u-d zKLq@={~J928u0jixf{h#H{xys`l6izo`8ruLTxaXf<8#|Ym+&eJNNWyONPgX(N*|v PEe5Pody$@@15Mxug<0dm diff --git a/DepthsBelow/DepthsBelowContent/images/soldier.png b/DepthsBelow/DepthsBelowContent/images/soldier.png new file mode 100644 index 0000000000000000000000000000000000000000..1aa2d70512fe26cfe737469f3205854ac6da772f GIT binary patch literal 405 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oVGw3ym^DWND9B#o z>FdgVhf{)AMdw#->0_XfY-UJAiF1B#Zfaf$kjuc}T$GwvlA5AWo>`Ki;O^-gkfN8$ z&cMLP?djqe5^?zKblpBCM*+9^(qoAN)eT>p4D z`?GGPh|Y{n+x2Uw-|}GlmFs?;lIU0>xqQsitpu~@)+NnL z;ts$3>-%@z$GP{?zu#XW-Ro{_Aw4Nq8ybv=S!o+3vp4&n{w7#H=M^KRAjW zoL2ejXv*-xhh_2~Znul7;YNXXCZArRp?A_WM&$XAus5&1N(lVDct$R@C)s#6