Action Points Movement Perfected

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-29 16:44:59 +01:00
parent 82ad94eb4f
commit d1b3661eed
4 changed files with 786 additions and 759 deletions
@@ -85,6 +85,14 @@ namespace DepthsBelow.Component
} }
} }
public int Length
{
get
{
return (path != null) ? path.Count : 0;
}
}
private AStar.PathFinderFast pathFinder; private AStar.PathFinderFast pathFinder;
private List<AStar.PathFinderNode> path; private List<AStar.PathFinderNode> path;
+33 -14
View File
@@ -177,16 +177,29 @@ namespace DepthsBelow
Vector2 fromMain = new Vector2((mainpath.X - unit.Position.X)*Grid.TileSize, Vector2 fromMain = new Vector2((mainpath.X - unit.Position.X)*Grid.TileSize,
(mainpath.Y - unit.Position.Y)*Grid.TileSize); (mainpath.Y - unit.Position.Y)*Grid.TileSize);
var goal = Grid.WorldToGrid(mouseWorldPos - fromMain); var goal = Grid.WorldToGrid(mouseWorldPos - fromMain);
unit.GetComponent<Component.PathFinder>().Goal = goal; Console.WriteLine("First " + unit.AP);
if (unit.GetComponent<Component.PathFinder>().IsMoving == false) unit.GetComponent<Component.PathFinder>().Goal = goal;
{ var length = unit.GetComponent<Component.PathFinder>().Length - 1;
// If a path was not found, add the unit to the stack if (unit.AP >= length)
soldierStack.Push(unit); {
}
else if (unit.GetComponent<Component.PathFinder>().IsMoving == false)
{ {
collisionMap[goal.X, goal.Y] = 0; // If a path was not found, add the unit to the stack
} soldierStack.Push(unit);
}
else
{
unit.AP -= length;
Console.WriteLine("then " + unit.AP);
collisionMap[goal.X, goal.Y] = 0;
}
}
else
{
unit.GetComponent<Component.PathFinder>().Stop();
}
} }
} }
@@ -217,10 +230,16 @@ namespace DepthsBelow
} }
else else
{ {
soldier.GetComponent<Component.PathFinder>().Goal = point; if (soldier.AP >= soldier.GetComponent<Component.PathFinder>().Length)
Console.WriteLine(x + " " + y); {
Console.WriteLine(soldier.GetComponent<Component.PathFinder>().Goal.X + " " + soldier.GetComponent<Component.PathFinder>().Goal = point;
soldier.GetComponent<Component.PathFinder>().Goal.Y); soldier.AP -= soldier.GetComponent<Component.PathFinder>().Length;
Console.WriteLine(x + " " + y);
Console.WriteLine(soldier.GetComponent<Component.PathFinder>().Goal.X + " " +
soldier.GetComponent<Component.PathFinder>().Goal.Y);
}
} }
} }
+3 -3
View File
@@ -140,7 +140,7 @@ namespace DepthsBelow
{ {
foreach (var unit in core.Squad) foreach (var unit in core.Squad)
{ {
unit.AP = 0; unit.AP = unit.MaxActionPoints;
unit.Fired = false; unit.Fired = false;
} }
@@ -227,10 +227,10 @@ namespace DepthsBelow
cost = rocketCost; cost = rocketCost;
type = "Rocket"; type = "Rocket";
} }
if (soldier.AP <= soldier.NumberOfActionPoints - cost) if (soldier.AP >= cost)
{ {
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), type)); core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), type));
soldier.AP += cost; soldier.AP -= cost;
soldier.Fired = true; soldier.Fired = true;
} }
else else
+11 -11
View File
@@ -35,16 +35,16 @@ namespace DepthsBelow
} }
} }
public int NumberOfActionPoints = 10; public int MaxActionPoints = 10;
int spentActionPoints = 0; int actionPointsLeft = 0;
public int AP public int AP
{ {
get { return spentActionPoints; } get { return actionPointsLeft; }
set set
{ {
spentActionPoints = value; actionPointsLeft = value;
GetComponent<Component.Stat>().GetStep = spentActionPoints; GetComponent<Component.Stat>().GetStep = actionPointsLeft;
} }
} }
@@ -174,17 +174,17 @@ namespace DepthsBelow
if (Transform.World == nodeWorldPos) if (Transform.World == nodeWorldPos)
{ {
if (AP < NumberOfActionPoints) //if (AP < NumberOfActionPoints)
{ //{
AP++; //AP++;
lastLastNode = lastNode; lastLastNode = lastNode;
lastNode = nextNode; lastNode = nextNode;
nextNode = GetComponent<PathFinder>().Next(); nextNode = GetComponent<PathFinder>().Next();
} //}
else /*else
{ {
GetComponent<PathFinder>().Stop(); GetComponent<PathFinder>().Stop();
} }*/
} }
} }
} }