EntityManager now static.
This commit is contained in:
@@ -152,6 +152,8 @@ namespace DepthsBelow.Component
|
||||
{
|
||||
byte[,] mapCollisionMap = Core.Map.GetCollisionMap();
|
||||
|
||||
// Add solid collision component entities
|
||||
|
||||
if (appendCollisionMap != null)
|
||||
foreach (var point in appendCollisionMap)
|
||||
mapCollisionMap[point.X, point.Y] = 0;
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace DepthsBelow
|
||||
|
||||
public Lua Lua;
|
||||
|
||||
public EntityManager EntityManager;
|
||||
public TurnManager TurnManager;
|
||||
|
||||
public Camera Camera;
|
||||
@@ -76,7 +75,6 @@ namespace DepthsBelow
|
||||
|
||||
Lua = new Lua();
|
||||
|
||||
EntityManager = new EntityManager();
|
||||
TurnManager = new TurnManager(new string[] { "Player", "Computer" });
|
||||
|
||||
Camera = new Camera(this);
|
||||
@@ -124,7 +122,7 @@ namespace DepthsBelow
|
||||
MouseInput.LoadContent();
|
||||
KeyboardInput = new KeyboardInput(this);
|
||||
|
||||
TestMonster = new SmallEnemy(EntityManager, ref Swarm);
|
||||
TestMonster = new SmallEnemy(ref Swarm);
|
||||
TestMonster.X = 12;
|
||||
TestMonster.Y = 4;
|
||||
Swarm.Add(TestMonster);
|
||||
|
||||
@@ -18,8 +18,6 @@ namespace DepthsBelow
|
||||
/// </summary>
|
||||
public Component.Transform Transform;
|
||||
|
||||
protected EntityManager entityManager;
|
||||
|
||||
/// <summary>
|
||||
/// Shorthand to the grid transform position.
|
||||
/// </summary>
|
||||
@@ -61,11 +59,10 @@ namespace DepthsBelow
|
||||
/// <summary>
|
||||
/// Creates a game object and adds it to the referenced entity manager.
|
||||
/// </summary>
|
||||
/// <param name="entityManager">An instance of EntityManager to add the entity to.</param>
|
||||
public Entity(EntityManager entityManager)
|
||||
///
|
||||
public Entity()
|
||||
{
|
||||
this.entityManager = entityManager;
|
||||
entityManager.Add(this);
|
||||
EntityManager.Add(this);
|
||||
|
||||
Components = new List<Component.Component>();
|
||||
|
||||
@@ -88,7 +85,7 @@ namespace DepthsBelow
|
||||
/// </summary>
|
||||
public virtual void Remove()
|
||||
{
|
||||
entityManager.Remove(this);
|
||||
EntityManager.Remove(this);
|
||||
Dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,20 +10,15 @@ namespace DepthsBelow
|
||||
/// <summary>
|
||||
/// Manages a group of entities.
|
||||
/// </summary>
|
||||
public class EntityManager : IDisposable
|
||||
public static class EntityManager
|
||||
{
|
||||
public List<Entity> Entities;
|
||||
|
||||
public EntityManager()
|
||||
{
|
||||
Entities = new List<Entity>();
|
||||
}
|
||||
public static List<Entity> Entities = new List<Entity>();
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of IDisposable.
|
||||
/// Dispose of the entity manager, and all entities it contains.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
public static void Dispose()
|
||||
{
|
||||
foreach (var entity in Entities)
|
||||
entity.Dispose();
|
||||
@@ -35,7 +30,7 @@ namespace DepthsBelow
|
||||
/// Add an entity to the entity manager.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to add.</param>
|
||||
public void Add(Entity entity)
|
||||
public static void Add(Entity entity)
|
||||
{
|
||||
Entities.Add(entity);
|
||||
}
|
||||
@@ -44,7 +39,7 @@ namespace DepthsBelow
|
||||
/// Remove an entity from the entity manager.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to remove.</param>
|
||||
public void Remove(Entity entity)
|
||||
public static void Remove(Entity entity)
|
||||
{
|
||||
Entities.Remove(entity);
|
||||
}
|
||||
@@ -52,7 +47,7 @@ namespace DepthsBelow
|
||||
/// <summary>
|
||||
/// Reset the entity manager, disposing any entities it contains.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
public static void Reset()
|
||||
{
|
||||
foreach (var entity in Entities)
|
||||
entity.Dispose();
|
||||
@@ -65,7 +60,7 @@ namespace DepthsBelow
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The component type.</typeparam>
|
||||
/// <returns>Returns the component of requested type.</returns>
|
||||
public List<T> GetComponents<T>() where T : Component.Component
|
||||
public static List<T> GetComponents<T>() where T : Component.Component
|
||||
{
|
||||
List<T> components = new List<T>();
|
||||
|
||||
@@ -83,7 +78,7 @@ namespace DepthsBelow
|
||||
/// Update all entities handled by the entity manager.
|
||||
/// </summary>
|
||||
/// <param name="gameTime"></param>
|
||||
public void Update(GameTime gameTime)
|
||||
public static void Update(GameTime gameTime)
|
||||
{
|
||||
foreach (var entity in Entities.ToList())
|
||||
entity.Update(gameTime);
|
||||
@@ -93,7 +88,7 @@ namespace DepthsBelow
|
||||
/// Draw all entities handled by the entity manager.
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch"></param>
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
public static void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
foreach (var entity in Entities)
|
||||
{
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace DepthsBelow
|
||||
}
|
||||
if (soldier.AP >= cost)
|
||||
{
|
||||
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), type));
|
||||
core.Volley.Add(new Shot(soldier.GetComponent<Component.Stat>(), type));
|
||||
soldier.AP -= cost;
|
||||
soldier.Fired = true;
|
||||
}
|
||||
@@ -297,7 +297,7 @@ namespace DepthsBelow
|
||||
current = 0;
|
||||
if (soldier.Selected == true && soldier.Fired == false && hit == true)
|
||||
{
|
||||
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Bullet"));
|
||||
core.Volley.Add(new Shot(soldier.GetComponent<Component.Stat>(), "Bullet"));
|
||||
soldier.Fired = true;
|
||||
foreach (var shot in core.Volley)
|
||||
{
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace DepthsBelow
|
||||
{
|
||||
if (mapObject.Type == "SquadStart")
|
||||
{
|
||||
var soldier = new Soldier(core.EntityManager, ref core.Squad);
|
||||
var soldier = new Soldier(ref core.Squad);
|
||||
soldier.Name = "Derp";
|
||||
// HACK: For some reason, the tile object coordinates are offset by one tile on the Y-axis in the Tiled map file (https://github.com/bjorn/tiled/issues/91)
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||
@@ -84,7 +84,7 @@ namespace DepthsBelow
|
||||
}
|
||||
if (mapObject.Type == "MonsterSpawn")
|
||||
{
|
||||
var enemy = new MonsterSpawn(core.EntityManager, ref core.Swarm);
|
||||
var enemy = new MonsterSpawn(ref core.Swarm);
|
||||
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
|
||||
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
|
||||
enemy.X = mapObjectGridPos.X;
|
||||
|
||||
@@ -15,8 +15,8 @@ namespace DepthsBelow
|
||||
|
||||
List<SmallEnemy> swarm;
|
||||
|
||||
public MonsterSpawn(EntityManager entityManager, ref List<SmallEnemy> Swarm)
|
||||
: base(entityManager)
|
||||
public MonsterSpawn(ref List<SmallEnemy> Swarm)
|
||||
: base()
|
||||
{
|
||||
//this.entityManager = entityManager;
|
||||
swarm = Swarm;
|
||||
@@ -24,9 +24,9 @@ namespace DepthsBelow
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
for (int index = 0; index < entityManager.Entities.Count; index++)
|
||||
for (int index = 0; index < EntityManager.Entities.Count; index++)
|
||||
{
|
||||
var entity = entityManager.Entities[index];
|
||||
var entity = EntityManager.Entities[index];
|
||||
if (entity is Soldier)
|
||||
{
|
||||
Vector2 distance1 = new Vector2(this.GetComponent<Component.Transform>().Grid.Position.X,
|
||||
@@ -35,7 +35,7 @@ namespace DepthsBelow
|
||||
entity.GetComponent<Component.Transform>().Grid.Position.Y);
|
||||
if (Vector2.Distance(distance1, distance2) < wakingDistance)
|
||||
{
|
||||
var enemy = new SmallEnemy(entityManager, ref swarm);
|
||||
var enemy = new SmallEnemy(ref swarm);
|
||||
enemy.X = this.X;
|
||||
enemy.Y = this.Y;
|
||||
swarm.Add(enemy);
|
||||
|
||||
@@ -38,8 +38,8 @@ namespace DepthsBelow
|
||||
|
||||
public Vector2 direction = Vector2.Zero;
|
||||
|
||||
public Shot(EntityManager entityManager, Stat _soldierStat, string _type)
|
||||
: base(entityManager)
|
||||
public Shot(Stat _soldierStat, string _type)
|
||||
: base()
|
||||
{
|
||||
type = _type;
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace DepthsBelow
|
||||
float speed = 4f;
|
||||
Transform.World.Position += speed * direction;
|
||||
|
||||
foreach (var entity in entityManager.Entities)
|
||||
foreach (var entity in EntityManager.Entities)
|
||||
{
|
||||
if (entity is SmallEnemy)
|
||||
{
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace DepthsBelow
|
||||
}
|
||||
}
|
||||
|
||||
public SmallEnemy(EntityManager entityManager, ref List<SmallEnemy> swarm)
|
||||
: base(entityManager)
|
||||
public SmallEnemy(ref List<SmallEnemy> swarm)
|
||||
: base()
|
||||
{
|
||||
if (Texture == null)
|
||||
LoadContent();
|
||||
@@ -150,7 +150,7 @@ namespace DepthsBelow
|
||||
|
||||
GetComponent<PathFinder>().Stop();
|
||||
}
|
||||
foreach (var entity in entityManager.Entities)
|
||||
foreach (var entity in EntityManager.Entities)
|
||||
{
|
||||
if (entity is Soldier)
|
||||
{
|
||||
|
||||
@@ -48,8 +48,8 @@ namespace DepthsBelow
|
||||
}
|
||||
}
|
||||
|
||||
public Soldier(EntityManager entityManager, ref List<Soldier> squad)
|
||||
: base(entityManager)
|
||||
public Soldier(ref List<Soldier> squad)
|
||||
: base()
|
||||
{
|
||||
if (Texture == null)
|
||||
LoadContent();
|
||||
|
||||
Reference in New Issue
Block a user