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 bulletCost = 5;
int rocketCost = 10;
public KeyboardInput(Core core)
{
this.core = core;
@@ -137,7 +140,7 @@ namespace DepthsBelow
{
foreach (var unit in core.Squad)
{
unit.step = 0;
unit.AP = 0;
unit.Fired = false;
}
@@ -211,12 +214,31 @@ namespace DepthsBelow
{
if (soldier.Selected == true && soldier.Fired == false)
{
if (ks.IsKeyDown(Keys.S)) {
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Bullet"));
} else if (ks.IsKeyDown(Keys.R)) {
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>(), "Rocket"));
bool enoughActionPoints = true;
int cost = 0;
string type = "";
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;
}
else
{
enoughActionPoints = false;
}
if (enoughActionPoints == true)
{
foreach (var shot in core.Volley)
{
if (shot.select == false)
@@ -240,6 +262,7 @@ namespace DepthsBelow
}
}
}
}
if (ks.IsKeyDown(Keys.C))
{
foreach (var soldier in core.Squad)
+20 -8
View File
@@ -23,6 +23,9 @@ namespace DepthsBelow
private bool hasFiredAlready = false;
int fireTimer = 0;
int timeSpentFired = 1000;
public bool Fired
{
get { return hasFiredAlready; }
@@ -32,16 +35,16 @@ namespace DepthsBelow
}
}
public int numberOfSteps = 14;
int currentStep = 0;
public int NumberOfActionPoints = 10;
int spentActionPoints = 0;
public int step
public int AP
{
get { return currentStep; }
get { return spentActionPoints; }
set
{
currentStep = value;
GetComponent<Component.Stat>().GetStep = currentStep;
spentActionPoints = value;
GetComponent<Component.Stat>().GetStep = spentActionPoints;
}
}
@@ -171,9 +174,9 @@ namespace DepthsBelow
if (Transform.World == nodeWorldPos)
{
if (step < numberOfSteps)
if (AP < NumberOfActionPoints)
{
step++;
AP++;
lastLastNode = lastNode;
lastNode = nextNode;
nextNode = GetComponent<PathFinder>().Next();
@@ -185,6 +188,15 @@ namespace DepthsBelow
}
}
}
if (Fired == true)
{
fireTimer += gameTime.ElapsedGameTime.Milliseconds;
if (fireTimer > timeSpentFired)
{
fireTimer = 0;
Fired = false;
}
}
}
}
}