This commit is contained in:
Simon Holmberg
2012-09-25 20:58:08 +02:00
parent d4c5282a67
commit 52bb50ce6e
4 changed files with 77 additions and 61 deletions
@@ -6,7 +6,7 @@ using Microsoft.Xna.Framework;
namespace DepthsBelow.Component namespace DepthsBelow.Component
{ {
class Collision : Component public class Collision : Component
{ {
public Rectangle Rectangle; public Rectangle Rectangle;
@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component namespace DepthsBelow.Component
{ {
@@ -13,5 +14,10 @@ namespace DepthsBelow.Component
{ {
Parent = parent; Parent = parent;
} }
public virtual void Update(GameTime gameTime)
{
}
} }
} }
+9 -3
View File
@@ -2,6 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow namespace DepthsBelow
{ {
public class Entity public class Entity
@@ -9,7 +11,6 @@ namespace DepthsBelow
List<Component.Component> Components; List<Component.Component> Components;
public Component.PixelTransform pixelTransform; public Component.PixelTransform pixelTransform;
public Component.GridTransform gridTransform; public Component.GridTransform gridTransform;
public Component.Collision collision;
public Entity() public Entity()
{ {
@@ -18,8 +19,6 @@ namespace DepthsBelow
AddComponent(pixelTransform); AddComponent(pixelTransform);
gridTransform = new Component.GridTransform(this); gridTransform = new Component.GridTransform(this);
AddComponent(gridTransform); AddComponent(gridTransform);
collision = new Component.Collision(this, 32, 32);
AddComponent(collision);
} }
public T GetComponent<T>() where T : Component.Component public T GetComponent<T>() where T : Component.Component
@@ -37,5 +36,12 @@ namespace DepthsBelow
{ {
Components.Add(c); Components.Add(c);
} }
public virtual void Update(GameTime gameTime)
{
// Update components
foreach (Component.Component c in Components)
c.Update(gameTime);
}
} }
} }
+6 -2
View File
@@ -10,7 +10,7 @@ using Microsoft.Xna.Framework.Media;
namespace DepthsBelow namespace DepthsBelow
{ {
class Soldier : Entity public class Soldier : Entity
{ {
Core game; Core game;
bool selected = false; bool selected = false;
@@ -32,10 +32,14 @@ namespace DepthsBelow
rc.Texture = Texture; rc.Texture = Texture;
rc.Color = Color.HotPink; rc.Color = Color.HotPink;
this.AddComponent(rc); this.AddComponent(rc);
Component.Collision cc = new Component.Collision(this, 32, 32);
this.AddComponent(cc);
} }
public void Update(GameTime gameTime) public override void Update(GameTime 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.Position.X += 1; gridTransform.Position.X += 1;