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)
body.Update(gameTime);
foreach (var bullet in Volley)
bullet.Update(gameTime);
TestMonster.Update(gameTime);
GUIManager.Update(gameTime);
+20 -7
View File
@@ -39,6 +39,7 @@ namespace DepthsBelow
foreach (var unit in core.Squad)
{
unit.step = 0;
unit.Fired = false;
}
}
else
@@ -77,15 +78,27 @@ namespace DepthsBelow
{
foreach (var soldier in core.Squad)
{
core.Volley.Add(new Shot(core));
foreach (var shot in core.Volley)
if (soldier.Selected == true && soldier.Fired == false)
{
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);
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation);
shot.direction = new Vector2((float)directionX, (float)directionY);
if (shot.select == false)
{
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 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;
+152 -141
View File
@@ -1,142 +1,153 @@
using System;
using System.Collections.Generic;
using DepthsBelow.Component;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace DepthsBelow
{
public class Soldier : Entity
{
public static Texture2D Texture;
public Color Color;
public static Point Origin;
private bool _selected;
public List<Soldier> Squad;
private PathFinder.Node nextNode;
private PathFinder.Node lastNode;
private PathFinder.Node lastLastNode;
public int numberOfSteps = 14;
public int currentStep = 0;
public int step
{
get { return currentStep; }
set
{
currentStep = value;
}
}
public Soldier(Core core, ref List<Soldier> squad) : base(core)
{
if (Texture == null)
LoadContent(core);
this.Squad = squad;
Transform.World.Origin = new Vector2(16, 16);
this.Color = Color.White;
var rc = new SpriteRenderer(this) {Texture = Texture, Color = Color.White};
AddComponent(rc);
var cc = new Collision(this, 32, 32);
AddComponent(cc);
var pfc = new PathFinder(this);
AddComponent(pfc);
}
public bool Selected
{
get { return _selected; }
set
{
_selected = value;
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
}
}
public static void LoadContent(Core core)
{
Texture = core.Content.Load<Texture2D>("images/soldier2");
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
if (nextNode == null)
nextNode = GetComponent<PathFinder>().Next();
if (nextNode != null)
{
List<Point> soldierCollisions = new List<Point>();
foreach (var soldier in Squad)
{
if (soldier != this && !soldier.GetComponent<PathFinder>().IsMoving)
{
soldierCollisions.Add(soldier.Transform.Grid);
}
}
foreach (var soldier in Squad)
{
if (soldier != this)
{
var pathFinder = soldier.GetComponent<PathFinder>();
var position = nextNode.Position;
if (soldier.Transform.Grid == position)
{
soldierCollisions.Add(soldier.Transform.Grid);
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
nextNode = GetComponent<PathFinder>().Next();
break;
}
}
}
if (nextNode != null)
{
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
// HACK: Make this work properly with other speeds...
float speed = 4f;
if (Transform.World.X < nodeWorldPos.X)
Transform.World.X += speed;
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)
Transform.World.Y -= speed;
if (Transform.World == nodeWorldPos)
{
if (currentStep < numberOfSteps)
{
currentStep++;
lastLastNode = lastNode;
lastNode = nextNode;
nextNode = GetComponent<PathFinder>().Next();
}
else
{
GetComponent<PathFinder>().Stop();
}
}
}
}
/**/
}
}
using System;
using System.Collections.Generic;
using DepthsBelow.Component;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace DepthsBelow
{
public class Soldier : Entity
{
public static Texture2D Texture;
public Color Color;
public static Point Origin;
private bool _selected;
public List<Soldier> Squad;
private PathFinder.Node nextNode;
private PathFinder.Node lastNode;
private PathFinder.Node lastLastNode;
private bool hasFiredAlready = false;
public bool Fired
{
get { return hasFiredAlready; }
set
{
hasFiredAlready = value;
}
}
public int numberOfSteps = 14;
public int currentStep = 0;
public int step
{
get { return currentStep; }
set
{
currentStep = value;
}
}
public Soldier(Core core, ref List<Soldier> squad) : base(core)
{
if (Texture == null)
LoadContent(core);
this.Squad = squad;
Transform.World.Origin = new Vector2(16, 16);
this.Color = Color.White;
var rc = new SpriteRenderer(this) {Texture = Texture, Color = Color.White};
AddComponent(rc);
var cc = new Collision(this, 32, 32);
AddComponent(cc);
var pfc = new PathFinder(this);
AddComponent(pfc);
}
public bool Selected
{
get { return _selected; }
set
{
_selected = value;
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
}
}
public static void LoadContent(Core core)
{
Texture = core.Content.Load<Texture2D>("images/soldier2");
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
if (nextNode == null)
nextNode = GetComponent<PathFinder>().Next();
if (nextNode != null)
{
List<Point> soldierCollisions = new List<Point>();
foreach (var soldier in Squad)
{
if (soldier != this && !soldier.GetComponent<PathFinder>().IsMoving)
{
soldierCollisions.Add(soldier.Transform.Grid);
}
}
foreach (var soldier in Squad)
{
if (soldier != this)
{
var pathFinder = soldier.GetComponent<PathFinder>();
var position = nextNode.Position;
if (soldier.Transform.Grid == position)
{
soldierCollisions.Add(soldier.Transform.Grid);
GetComponent<PathFinder>().RecreatePath(soldierCollisions);
nextNode = GetComponent<PathFinder>().Next();
break;
}
}
}
if (nextNode != null)
{
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
// HACK: Make this work properly with other speeds...
float speed = 4f;
if (Transform.World.X < nodeWorldPos.X)
Transform.World.X += speed;
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)
Transform.World.Y -= speed;
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>
</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>
<Importer>TextureImporter</Importer>
<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