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
+28 -5
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,12 +214,31 @@ 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))
{
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; soldier.Fired = true;
}
else
{
enoughActionPoints = false;
}
if (enoughActionPoints == true)
{
foreach (var shot in core.Volley) foreach (var shot in core.Volley)
{ {
if (shot.select == false) if (shot.select == false)
@@ -240,6 +262,7 @@ namespace DepthsBelow
} }
} }
} }
}
if (ks.IsKeyDown(Keys.C)) if (ks.IsKeyDown(Keys.C))
{ {
foreach (var soldier in core.Squad) foreach (var soldier in core.Squad)
+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;
}
}
} }
} }
} }