Some pathfinding stuff, modifications to small enemy
This commit is contained in:
@@ -25,7 +25,7 @@ namespace DepthsBelow.Component
|
|||||||
{
|
{
|
||||||
Transform transform = this.Parent.GetComponent<Transform>();
|
Transform transform = this.Parent.GetComponent<Transform>();
|
||||||
//spriteBatch.Draw(Texture, tc.Position, this.Color);
|
//spriteBatch.Draw(Texture, tc.Position, this.Color);
|
||||||
spriteBatch.Draw(Texture, transform.World.Position + transform.World.Origin, null, Color, transform.World.Rotation, transform.World.Origin, Scale, SpriteEffects, 0);
|
spriteBatch.Draw(Texture, transform.World.Position + new Vector2(Grid.TileSize / 2, Grid.TileSize / 2), null, Color, transform.World.Rotation, transform.World.Origin, Scale, SpriteEffects, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace DepthsBelow
|
|||||||
|
|
||||||
this.Swarm = swarm;
|
this.Swarm = swarm;
|
||||||
|
|
||||||
Transform.World.Origin = new Vector2(16, 16);
|
Transform.World.Origin = new Vector2(20, 16);
|
||||||
|
|
||||||
this.Color = Color.White;
|
this.Color = Color.White;
|
||||||
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
||||||
@@ -58,7 +58,7 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
|
|
||||||
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
/*float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
||||||
|
|
||||||
if (nextNode == null)
|
if (nextNode == null)
|
||||||
nextNode = GetComponent<PathFinder>().Next();
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
@@ -101,9 +101,7 @@ namespace DepthsBelow
|
|||||||
nextNode = GetComponent<PathFinder>().Next();
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,8 @@ namespace DepthsBelow
|
|||||||
public List<Soldier> Squad;
|
public List<Soldier> Squad;
|
||||||
|
|
||||||
private PathFinder.Node nextNode;
|
private PathFinder.Node nextNode;
|
||||||
|
private PathFinder.Node lastNode;
|
||||||
|
private PathFinder.Node lastLastNode;
|
||||||
|
|
||||||
public Soldier(Core core, ref List<Soldier> squad) : base(core)
|
public Soldier(Core core, ref List<Soldier> squad) : base(core)
|
||||||
{
|
{
|
||||||
@@ -66,11 +68,21 @@ namespace DepthsBelow
|
|||||||
{
|
{
|
||||||
List<Point> soldierCollisions = new List<Point>();
|
List<Point> soldierCollisions = new List<Point>();
|
||||||
|
|
||||||
|
foreach (var soldier in Squad)
|
||||||
|
{
|
||||||
|
if (soldier != this && !soldier.GetComponent<PathFinder>().IsMoving)
|
||||||
|
{
|
||||||
|
soldierCollisions.Add(soldier.Transform.Grid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var soldier in Squad)
|
foreach (var soldier in Squad)
|
||||||
{
|
{
|
||||||
if (soldier != this)
|
if (soldier != this)
|
||||||
{
|
{
|
||||||
if (soldier.Transform.Grid == nextNode.Position)
|
var pathFinder = soldier.GetComponent<PathFinder>();
|
||||||
|
var position = nextNode.Position;
|
||||||
|
if (soldier.Transform.Grid == position)
|
||||||
{
|
{
|
||||||
soldierCollisions.Add(soldier.Transform.Grid);
|
soldierCollisions.Add(soldier.Transform.Grid);
|
||||||
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
||||||
@@ -80,8 +92,6 @@ namespace DepthsBelow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (nextNode != null)
|
if (nextNode != null)
|
||||||
{
|
{
|
||||||
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
|
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
|
||||||
@@ -97,7 +107,11 @@ namespace DepthsBelow
|
|||||||
Transform.World.Y -= speed;
|
Transform.World.Y -= speed;
|
||||||
|
|
||||||
if (Transform.World == nodeWorldPos)
|
if (Transform.World == nodeWorldPos)
|
||||||
|
{
|
||||||
|
lastLastNode = lastNode;
|
||||||
|
lastNode = nextNode;
|
||||||
nextNode = GetComponent<PathFinder>().Next();
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user