Test
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -1,17 +1,23 @@
|
|||||||
using System;
|
using System;
|
||||||
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
|
||||||
public class Component
|
{
|
||||||
{
|
public class Component
|
||||||
public Entity Parent;
|
{
|
||||||
|
public Entity Parent;
|
||||||
public Component(Entity parent)
|
|
||||||
{
|
public Component(Entity parent)
|
||||||
Parent = parent;
|
{
|
||||||
}
|
Parent = parent;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public virtual void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,41 +1,47 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
namespace DepthsBelow
|
using Microsoft.Xna.Framework;
|
||||||
{
|
|
||||||
public class Entity
|
namespace DepthsBelow
|
||||||
{
|
{
|
||||||
List<Component.Component> Components;
|
public class Entity
|
||||||
public Component.PixelTransform pixelTransform;
|
{
|
||||||
public Component.GridTransform gridTransform;
|
List<Component.Component> Components;
|
||||||
public Component.Collision collision;
|
public Component.PixelTransform pixelTransform;
|
||||||
|
public Component.GridTransform gridTransform;
|
||||||
public Entity()
|
|
||||||
{
|
public Entity()
|
||||||
Components = new List<Component.Component>();
|
{
|
||||||
pixelTransform = new Component.PixelTransform(this);
|
Components = new List<Component.Component>();
|
||||||
AddComponent(pixelTransform);
|
pixelTransform = new Component.PixelTransform(this);
|
||||||
gridTransform = new Component.GridTransform(this);
|
AddComponent(pixelTransform);
|
||||||
AddComponent(gridTransform);
|
gridTransform = new Component.GridTransform(this);
|
||||||
collision = new Component.Collision(this, 32, 32);
|
AddComponent(gridTransform);
|
||||||
AddComponent(collision);
|
}
|
||||||
}
|
|
||||||
|
public T GetComponent<T>() where T : Component.Component
|
||||||
public T GetComponent<T>() where T : Component.Component
|
{
|
||||||
{
|
foreach (Component.Component c in Components)
|
||||||
foreach (Component.Component c in Components)
|
{
|
||||||
{
|
if (c is T)
|
||||||
if (c is T)
|
return (T)c;
|
||||||
return (T)c;
|
}
|
||||||
}
|
|
||||||
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
public void AddComponent(Component.Component c)
|
||||||
public void AddComponent(Component.Component c)
|
{
|
||||||
{
|
Components.Add(c);
|
||||||
Components.Add(c);
|
}
|
||||||
}
|
|
||||||
}
|
public virtual void Update(GameTime gameTime)
|
||||||
}
|
{
|
||||||
|
// Update components
|
||||||
|
foreach (Component.Component c in Components)
|
||||||
|
c.Update(gameTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user