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