Converted shooting to Action Points

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-29 15:30:53 +01:00
parent e708c62a50
commit 82ad94eb4f
2 changed files with 390 additions and 355 deletions
+46 -23
View File
@@ -18,6 +18,9 @@ namespace DepthsBelow
int checkerSpeed = 2; int checkerSpeed = 2;
int bulletCost = 5;
int rocketCost = 10;
public KeyboardInput(Core core) public KeyboardInput(Core core)
{ {
this.core = core; this.core = core;
@@ -137,7 +140,7 @@ namespace DepthsBelow
{ {
foreach (var unit in core.Squad) foreach (var unit in core.Squad)
{ {
unit.step = 0; unit.AP = 0;
unit.Fired = false; unit.Fired = false;
} }
@@ -211,30 +214,50 @@ namespace DepthsBelow
{ {
if (soldier.Selected == true && soldier.Fired == false) if (soldier.Selected == true && soldier.Fired == false)
{ {
if (ks.IsKeyDown(Keys.S)) { bool enoughActionPoints = true;
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Bullet")); int cost = 0;
} else if (ks.IsKeyDown(Keys.R)) { string type = "";
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Rocket")); if (ks.IsKeyDown(Keys.S))
}
soldier.Fired = true;
foreach (var shot in core.Volley)
{ {
if (shot.select == false) cost = bulletCost;
type = "bullet";
}
else if (ks.IsKeyDown(Keys.R))
{
cost = rocketCost;
type = "Rocket";
}
if (soldier.AP <= soldier.NumberOfActionPoints - cost)
{
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), type));
soldier.AP += cost;
soldier.Fired = true;
}
else
{
enoughActionPoints = false;
}
if (enoughActionPoints == true)
{
foreach (var shot in core.Volley)
{ {
shot.select = true; if (shot.select == false)
shot.X = soldier.X; {
shot.Y = soldier.Y; shot.select = true;
//shot.Transform.World.X += Grid.TileSize / 2; shot.X = soldier.X;
//shot.Transform.World.Y += Grid.TileSize / 2; shot.Y = soldier.Y;
} //shot.Transform.World.X += Grid.TileSize / 2;
if (shot.direction == Vector2.Zero) //shot.Transform.World.Y += Grid.TileSize / 2;
{ }
double directionX = Math.Cos(soldier.Transform.World.Rotation); if (shot.direction == Vector2.Zero)
double directionY = Math.Sin(soldier.Transform.World.Rotation); {
shot.direction = new Vector2((float)directionX, (float)directionY); double directionX = Math.Cos(soldier.Transform.World.Rotation);
shot.Transform.World.Rotation = soldier.Transform.World.Rotation; double directionY = Math.Sin(soldier.Transform.World.Rotation);
Vector2 yo = soldier.Transform.World.Position; shot.direction = new Vector2((float)directionX, (float)directionY);
shot.Stat.Remember = yo; shot.Transform.World.Rotation = soldier.Transform.World.Rotation;
Vector2 yo = soldier.Transform.World.Position;
shot.Stat.Remember = yo;
}
} }
} }
} }
+20 -8
View File
@@ -23,6 +23,9 @@ namespace DepthsBelow
private bool hasFiredAlready = false; private bool hasFiredAlready = false;
int fireTimer = 0;
int timeSpentFired = 1000;
public bool Fired public bool Fired
{ {
get { return hasFiredAlready; } get { return hasFiredAlready; }
@@ -32,16 +35,16 @@ namespace DepthsBelow
} }
} }
public int numberOfSteps = 14; public int NumberOfActionPoints = 10;
int currentStep = 0; int spentActionPoints = 0;
public int step public int AP
{ {
get { return currentStep; } get { return spentActionPoints; }
set set
{ {
currentStep = value; spentActionPoints = value;
GetComponent<Component.Stat>().GetStep = currentStep; GetComponent<Component.Stat>().GetStep = spentActionPoints;
} }
} }
@@ -171,9 +174,9 @@ namespace DepthsBelow
if (Transform.World == nodeWorldPos) if (Transform.World == nodeWorldPos)
{ {
if (step < numberOfSteps) if (AP < NumberOfActionPoints)
{ {
step++; AP++;
lastLastNode = lastNode; lastLastNode = lastNode;
lastNode = nextNode; lastNode = nextNode;
nextNode = GetComponent<PathFinder>().Next(); nextNode = GetComponent<PathFinder>().Next();
@@ -185,6 +188,15 @@ namespace DepthsBelow
} }
} }
} }
if (Fired == true)
{
fireTimer += gameTime.ElapsedGameTime.Milliseconds;
if (fireTimer > timeSpentFired)
{
fireTimer = 0;
Fired = false;
}
}
} }
} }
} }