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 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,
(mainpath.Y - unit.Position.Y)*Grid.TileSize);
var goal = Grid.WorldToGrid(mouseWorldPos - fromMain);
unit.GetComponent<Component.PathFinder>().Goal = goal;
if (unit.GetComponent<Component.PathFinder>().IsMoving == false)
{
// If a path was not found, add the unit to the stack
soldierStack.Push(unit);
}
else
{
collisionMap[goal.X, goal.Y] = 0;
}
Console.WriteLine("First " + unit.AP);
unit.GetComponent<Component.PathFinder>().Goal = goal;
var length = unit.GetComponent<Component.PathFinder>().Length - 1;
if (unit.AP >= length)
{
if (unit.GetComponent<Component.PathFinder>().IsMoving == false)
{
// 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
{
soldier.GetComponent<Component.PathFinder>().Goal = point;
Console.WriteLine(x + " " + y);
Console.WriteLine(soldier.GetComponent<Component.PathFinder>().Goal.X + " " +
soldier.GetComponent<Component.PathFinder>().Goal.Y);
if (soldier.AP >= soldier.GetComponent<Component.PathFinder>().Length)
{
soldier.GetComponent<Component.PathFinder>().Goal = point;
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)
{
unit.AP = 0;
unit.AP = unit.MaxActionPoints;
unit.Fired = false;
}
@@ -227,10 +227,10 @@ namespace DepthsBelow
cost = rocketCost;
type = "Rocket";
}
if (soldier.AP <= soldier.NumberOfActionPoints - cost)
if (soldier.AP >= cost)
{
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), type));
soldier.AP += cost;
soldier.AP -= cost;
soldier.Fired = true;
}
else
+11 -11
View File
@@ -35,16 +35,16 @@ namespace DepthsBelow
}
}
public int NumberOfActionPoints = 10;
int spentActionPoints = 0;
public int MaxActionPoints = 10;
int actionPointsLeft = 0;
public int AP
{
get { return spentActionPoints; }
get { return actionPointsLeft; }
set
{
spentActionPoints = value;
GetComponent<Component.Stat>().GetStep = spentActionPoints;
actionPointsLeft = value;
GetComponent<Component.Stat>().GetStep = actionPointsLeft;
}
}
@@ -174,17 +174,17 @@ namespace DepthsBelow
if (Transform.World == nodeWorldPos)
{
if (AP < NumberOfActionPoints)
{
AP++;
//if (AP < NumberOfActionPoints)
//{
//AP++;
lastLastNode = lastNode;
lastNode = nextNode;
nextNode = GetComponent<PathFinder>().Next();
}
else
//}
/*else
{
GetComponent<PathFinder>().Stop();
}
}*/
}
}
}