MonsterSpawn added, reacts to a distance...

Have not tested, I think I failed, I don't think I should transfer
around lists like that... But I didn't make the things static at
least..!
This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-22 00:36:54 +02:00
parent dca73efe29
commit d36592318f
6 changed files with 65 additions and 2 deletions
+5
View File
@@ -36,6 +36,9 @@ namespace DepthsBelow
public DynamicGroupManager GroupManager; public DynamicGroupManager GroupManager;
public List<SmallEnemy> Swarm; public List<SmallEnemy> Swarm;
public List<Shot> Volley; public List<Shot> Volley;
public List<MonsterSpawn> Spawn;
public static Map Map; public static Map Map;
public SmallEnemy TestMonster; public SmallEnemy TestMonster;
@@ -78,6 +81,8 @@ namespace DepthsBelow
Swarm = new List<SmallEnemy>(); Swarm = new List<SmallEnemy>();
Volley = new List<Shot>(); Volley = new List<Shot>();
Spawn = new List<MonsterSpawn>();
base.Initialize(); base.Initialize();
} }
@@ -122,6 +122,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Camera.cs" /> <Compile Include="Camera.cs" />
<Compile Include="DynamicGroupManager.cs" /> <Compile Include="DynamicGroupManager.cs" />
<Compile Include="MonsterSpawn.cs" />
<Compile Include="TurnManager.cs" /> <Compile Include="TurnManager.cs" />
<Compile Include="CustomExtensions.cs" /> <Compile Include="CustomExtensions.cs" />
<Compile Include="EntityManager.cs" /> <Compile Include="EntityManager.cs" />
+1 -1
View File
@@ -18,7 +18,7 @@ namespace DepthsBelow
/// </summary> /// </summary>
public Component.Transform Transform; public Component.Transform Transform;
private EntityManager entityManager; protected EntityManager entityManager;
/// <summary> /// <summary>
/// Shorthand to the grid transform position. /// Shorthand to the grid transform position.
+5
View File
@@ -14,6 +14,11 @@ namespace DepthsBelow
{ {
private List<Entity> entities; private List<Entity> entities;
public List<Entity> Entities
{
get { return entities; }
}
public EntityManager() public EntityManager()
{ {
entities = new List<Entity>(); entities = new List<Entity>();
+8
View File
@@ -82,6 +82,14 @@ namespace DepthsBelow
core.Squad.Add(soldier); core.Squad.Add(soldier);
} }
if (mapObject.Type == "MonsterSpawn")
{
var enemy = new MonsterSpawn(core.EntityManager, ref core.Swarm);
var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
enemy.X = mapObjectGridPos.X;
enemy.Y = mapObjectGridPos.Y;
}
} }
} }
} }
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
namespace DepthsBelow
{
public class MonsterSpawn : Entity
{
//EntityManager entityManager;
int wakingDistance = 13;
List<SmallEnemy> swarm;
public MonsterSpawn(EntityManager entityManager, ref List<SmallEnemy> Swarm)
: base(entityManager)
{
//this.entityManager = entityManager;
swarm = Swarm;
}
public void Update(GameTime gameTime)
{
foreach (var entity in entityManager.Entities)
{
if (entity is Soldier)
{
Vector2 distance1 = new Vector2(this.GetComponent<Component.Transform>().Grid.Position.X, this.GetComponent<Component.Transform>().Grid.Position.Y);
Vector2 distance2 = new Vector2(entity.GetComponent<Component.Transform>().Grid.Position.X, entity.GetComponent<Component.Transform>().Grid.Position.Y);
if (Vector2.Distance(distance1, distance2) > wakingDistance)
{
var enemy = new SmallEnemy(entityManager, ref swarm);
enemy.X = this.X;
enemy.Y = this.Y;
entityManager.Add(enemy);
swarm.Add(enemy);
}
}
}
}
}
}