74 lines
1.5 KiB
C#
74 lines
1.5 KiB
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.Transform Transform;
|
|
public Component.PixelTransform pixelTransform;
|
|
public Component.GridTransform gridTransform;
|
|
public Component.Stat stat;
|
|
public int X
|
|
{
|
|
get { return this.Transform.Grid.X; }
|
|
set
|
|
{
|
|
this.Transform.Grid.X = value;
|
|
}
|
|
}
|
|
public int Y
|
|
{
|
|
get { return this.Transform.Grid.Y; }
|
|
set
|
|
{
|
|
this.Transform.Grid.Y = value;
|
|
}
|
|
}
|
|
|
|
protected Core core;
|
|
|
|
public Entity(Core core)
|
|
{
|
|
this.core = core;
|
|
|
|
Components = new List<Component.Component>();
|
|
Transform = new Component.Transform(this);
|
|
AddComponent(Transform);
|
|
pixelTransform = new Component.PixelTransform(this);
|
|
AddComponent(pixelTransform);
|
|
gridTransform = new Component.GridTransform(this);
|
|
AddComponent(gridTransform);
|
|
stat = new Component.Stat(this);
|
|
AddComponent(stat);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|