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
{
class Collision : Component
public class Collision : Component
{
public Rectangle Rectangle;
+23 -17
View File
@@ -1,17 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DepthsBelow.Component
{
public class Component
{
public Entity Parent;
public Component(Entity parent)
{
Parent = parent;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow.Component
{
public class Component
{
public Entity Parent;
public Component(Entity parent)
{
Parent = parent;
}
public virtual void Update(GameTime gameTime)
{
}
}
}
+47 -41
View File
@@ -1,41 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DepthsBelow
{
public class Entity
{
List<Component.Component> Components;
public Component.PixelTransform pixelTransform;
public Component.GridTransform gridTransform;
public Component.Collision collision;
public Entity()
{
Components = new List<Component.Component>();
pixelTransform = new Component.PixelTransform(this);
AddComponent(pixelTransform);
gridTransform = new Component.GridTransform(this);
AddComponent(gridTransform);
collision = new Component.Collision(this, 32, 32);
AddComponent(collision);
}
public T GetComponent<T>() where T : Component.Component
{
foreach (Component.Component c in Components)
{
if (c is T)
return (T)c;
}
return null;
}
public void AddComponent(Component.Component c)
{
Components.Add(c);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow
{
public class Entity
{
List<Component.Component> Components;
public Component.PixelTransform pixelTransform;
public Component.GridTransform gridTransform;
public Entity()
{
Components = new List<Component.Component>();
pixelTransform = new Component.PixelTransform(this);
AddComponent(pixelTransform);
gridTransform = new Component.GridTransform(this);
AddComponent(gridTransform);
}
public T GetComponent<T>() where T : Component.Component
{
foreach (Component.Component c in Components)
{
if (c is T)
return (T)c;
}
return null;
}
public void AddComponent(Component.Component 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
{
class Soldier : Entity
public class Soldier : Entity
{
Core game;
bool selected = false;
@@ -32,10 +32,14 @@ namespace DepthsBelow
rc.Texture = Texture;
rc.Color = Color.HotPink;
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();
if (ks.IsKeyDown(Keys.Right) && lastKeyboardState.IsKeyUp(Keys.Right))
gridTransform.Position.X += 1;