You can now fire selected units with S

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-16 16:18:21 +02:00
parent 9df0077257
commit 16f2d57aec
7 changed files with 193 additions and 150 deletions
+3
View File
@@ -127,6 +127,9 @@ namespace DepthsBelow
foreach (var body in Swarm) foreach (var body in Swarm)
body.Update(gameTime); body.Update(gameTime);
foreach (var bullet in Volley)
bullet.Update(gameTime);
TestMonster.Update(gameTime); TestMonster.Update(gameTime);
GUIManager.Update(gameTime); GUIManager.Update(gameTime);
+20 -7
View File
@@ -39,6 +39,7 @@ namespace DepthsBelow
foreach (var unit in core.Squad) foreach (var unit in core.Squad)
{ {
unit.step = 0; unit.step = 0;
unit.Fired = false;
} }
} }
else else
@@ -77,15 +78,27 @@ namespace DepthsBelow
{ {
foreach (var soldier in core.Squad) foreach (var soldier in core.Squad)
{ {
core.Volley.Add(new Shot(core)); if (soldier.Selected == true && soldier.Fired == false)
foreach (var shot in core.Volley)
{ {
if (shot.direction == Vector2.Zero) core.Volley.Add(new Shot(core));
soldier.Fired = true;
foreach (var shot in core.Volley)
{ {
double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation); if (shot.select == false)
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation); {
shot.direction = new Vector2((float)directionX, (float)directionY); shot.select = true;
shot.X = soldier.X;
shot.Y = soldier.Y;
//shot.Transform.World.X += Grid.TileSize / 2;
//shot.Transform.World.Y += Grid.TileSize / 2;
}
if (shot.direction == Vector2.Zero)
{
double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation);
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation);
shot.direction = new Vector2((float)directionX, (float)directionY);
shot.Transform.World.Rotation = soldier.Transform.World.Rotation;
}
} }
} }
} }
+10 -1
View File
@@ -13,7 +13,16 @@ namespace DepthsBelow
public Color Color; public Color Color;
public static Point Origin; public static Point Origin;
private bool _selected; //I guess as in "currently doing something" private bool _selected = false; //I guess as in "currently doing something"
public bool select
{
get { return _selected; }
set
{
_selected = value;
}
}
public List<Shot> Volley; public List<Shot> Volley;
+152 -141
View File
@@ -1,142 +1,153 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using DepthsBelow.Component; using DepthsBelow.Component;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
namespace DepthsBelow namespace DepthsBelow
{ {
public class Soldier : Entity public class Soldier : Entity
{ {
public static Texture2D Texture; public static Texture2D Texture;
public Color Color; public Color Color;
public static Point Origin; public static Point Origin;
private bool _selected; private bool _selected;
public List<Soldier> Squad; public List<Soldier> Squad;
private PathFinder.Node nextNode; private PathFinder.Node nextNode;
private PathFinder.Node lastNode; private PathFinder.Node lastNode;
private PathFinder.Node lastLastNode; private PathFinder.Node lastLastNode;
public int numberOfSteps = 14; private bool hasFiredAlready = false;
public int currentStep = 0;
public bool Fired
public int step {
{ get { return hasFiredAlready; }
get { return currentStep; } set
set {
{ hasFiredAlready = value;
currentStep = value; }
} }
}
public int numberOfSteps = 14;
public Soldier(Core core, ref List<Soldier> squad) : base(core) public int currentStep = 0;
{
if (Texture == null) public int step
LoadContent(core); {
get { return currentStep; }
this.Squad = squad; set
{
Transform.World.Origin = new Vector2(16, 16); currentStep = value;
}
this.Color = Color.White; }
var rc = new SpriteRenderer(this) {Texture = Texture, Color = Color.White};
AddComponent(rc); public Soldier(Core core, ref List<Soldier> squad) : base(core)
{
var cc = new Collision(this, 32, 32); if (Texture == null)
AddComponent(cc); LoadContent(core);
var pfc = new PathFinder(this); this.Squad = squad;
AddComponent(pfc);
} Transform.World.Origin = new Vector2(16, 16);
public bool Selected this.Color = Color.White;
{ var rc = new SpriteRenderer(this) {Texture = Texture, Color = Color.White};
get { return _selected; } AddComponent(rc);
set
{ var cc = new Collision(this, 32, 32);
_selected = value; AddComponent(cc);
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
} var pfc = new PathFinder(this);
} AddComponent(pfc);
}
public static void LoadContent(Core core)
{ public bool Selected
Texture = core.Content.Load<Texture2D>("images/soldier2"); {
} get { return _selected; }
set
public override void Update(GameTime gameTime) {
{ _selected = value;
base.Update(gameTime); GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
}
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; }
if (nextNode == null) public static void LoadContent(Core core)
nextNode = GetComponent<PathFinder>().Next(); {
Texture = core.Content.Load<Texture2D>("images/soldier2");
if (nextNode != null) }
{
List<Point> soldierCollisions = new List<Point>(); public override void Update(GameTime gameTime)
{
foreach (var soldier in Squad) base.Update(gameTime);
{
if (soldier != this && !soldier.GetComponent<PathFinder>().IsMoving) float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
{
soldierCollisions.Add(soldier.Transform.Grid); if (nextNode == null)
} nextNode = GetComponent<PathFinder>().Next();
}
if (nextNode != null)
foreach (var soldier in Squad) {
{ List<Point> soldierCollisions = new List<Point>();
if (soldier != this)
{ foreach (var soldier in Squad)
var pathFinder = soldier.GetComponent<PathFinder>(); {
var position = nextNode.Position; if (soldier != this && !soldier.GetComponent<PathFinder>().IsMoving)
if (soldier.Transform.Grid == position) {
{ soldierCollisions.Add(soldier.Transform.Grid);
soldierCollisions.Add(soldier.Transform.Grid); }
GetComponent<PathFinder>().RecreatePath(soldierCollisions); }
nextNode = GetComponent<PathFinder>().Next();
break; foreach (var soldier in Squad)
} {
} if (soldier != this)
} {
var pathFinder = soldier.GetComponent<PathFinder>();
if (nextNode != null) var position = nextNode.Position;
{ if (soldier.Transform.Grid == position)
var nodeWorldPos = Grid.GridToWorld(nextNode.Position); {
// HACK: Make this work properly with other speeds... soldierCollisions.Add(soldier.Transform.Grid);
float speed = 4f; GetComponent<PathFinder>().RecreatePath(soldierCollisions);
if (Transform.World.X < nodeWorldPos.X) nextNode = GetComponent<PathFinder>().Next();
Transform.World.X += speed; break;
if (Transform.World.X > nodeWorldPos.X) }
Transform.World.X -= speed; }
if (Transform.World.Y < nodeWorldPos.Y) }
Transform.World.Y += speed;
if (Transform.World.Y > nodeWorldPos.Y) if (nextNode != null)
Transform.World.Y -= speed; {
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
if (Transform.World == nodeWorldPos) // HACK: Make this work properly with other speeds...
{ float speed = 4f;
if (currentStep < numberOfSteps) if (Transform.World.X < nodeWorldPos.X)
{ Transform.World.X += speed;
currentStep++; if (Transform.World.X > nodeWorldPos.X)
lastLastNode = lastNode; Transform.World.X -= speed;
lastNode = nextNode; if (Transform.World.Y < nodeWorldPos.Y)
nextNode = GetComponent<PathFinder>().Next(); Transform.World.Y += speed;
} if (Transform.World.Y > nodeWorldPos.Y)
else Transform.World.Y -= speed;
{
GetComponent<PathFinder>().Stop(); if (Transform.World == nodeWorldPos)
} {
} if (currentStep < numberOfSteps)
} {
currentStep++;
} lastLastNode = lastNode;
lastNode = nextNode;
/**/ nextNode = GetComponent<PathFinder>().Next();
} }
} else
{
GetComponent<PathFinder>().Stop();
}
}
}
}
/**/
}
}
} }
@@ -121,7 +121,14 @@
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="images\Shot.bmp"> <Compile Include="images\Shot2.bmp">
<Name>Shot2</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="images\FireBall.PNG">
<Name>Shot</Name> <Name>Shot</Name>
<Importer>TextureImporter</Importer> <Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor> <Processor>TextureProcessor</Processor>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 222 B