Merge branch 'master' of github.com:sippeangelo/DepthsBelow

Conflicts:
	DepthsBelow/DepthsBelow/Core.cs
This commit is contained in:
Simon Holmberg
2012-10-09 19:20:13 +02:00
5 changed files with 390 additions and 294 deletions
+16
View File
@@ -23,6 +23,7 @@ namespace DepthsBelow
public Camera Camera; public Camera Camera;
public bool PlayerTurn = true;
public static MouseInput MouseInput; public static MouseInput MouseInput;
public static KeyboardInput KeyboardInput; public static KeyboardInput KeyboardInput;
public List<Soldier> Squad; public List<Soldier> Squad;
@@ -86,6 +87,8 @@ namespace DepthsBelow
MouseInput.LoadContent(); MouseInput.LoadContent();
KeyboardInput = new KeyboardInput(this); KeyboardInput = new KeyboardInput(this);
TestMonster.X = 12;
TestMonster.Y = 4;
// Test GUI frames // Test GUI frames
var frame = new GUI.Button() var frame = new GUI.Button()
{ {
@@ -134,11 +137,24 @@ namespace DepthsBelow
foreach (var body in Swarm) foreach (var body in Swarm)
body.Update(gameTime); body.Update(gameTime);
TestMonster.Update(gameTime);
GUIManager.Update(gameTime); GUIManager.Update(gameTime);
base.Update(gameTime); base.Update(gameTime);
} }
public int FindDistance(Vector2 target, Vector2 start)
{
Vector2 combine = new Vector2(target.X - start.X, target.Y - start.Y);
int result = 0;
int firstRestult = (int)Math.Sqrt((int)combine.X^2 + (int)combine.Y^2);
result = (int)Vector2.Distance(target, start);
return result;
}
/// <summary> /// <summary>
/// This is called when the game should draw itself. /// This is called when the game should draw itself.
/// </summary> /// </summary>
+44 -1
View File
@@ -13,6 +13,8 @@ namespace DepthsBelow
public class KeyboardInput public class KeyboardInput
{ {
Core core; Core core;
bool Enter = false;
bool turn;
public KeyboardInput(Core core) public KeyboardInput(Core core)
{ {
@@ -23,13 +25,54 @@ namespace DepthsBelow
{ {
KeyboardState ks = Keyboard.GetState(); KeyboardState ks = Keyboard.GetState();
if (ks.IsKeyDown(Keys.Enter)) if (ks.IsKeyUp(Keys.Enter) && Enter == true)
{ {
Enter = false;
}
if (ks.IsKeyDown(Keys.Enter) && Enter == false)
{
Enter = true;
if (core.PlayerTurn == false)
{
core.PlayerTurn = true;
foreach (var unit in core.Squad) foreach (var unit in core.Squad)
{ {
unit.step = 0; unit.step = 0;
} }
} }
else
{
core.TestMonster.step = 0;
core.PlayerTurn = false;
Point target = Point.Zero;
int distance = 7000;
foreach (var unit in core.Squad)
{
Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y);
Vector2 monster = new Vector2(core.TestMonster.Transform.Grid.X, core.TestMonster.Transform.Grid.Y);
int newDistance = core.FindDistance(soldier, monster);
if (newDistance < distance)
{
target = unit.Transform.Grid;
distance = newDistance;
}
}
core.TestMonster.GetComponent<Component.PathFinder>().Goal = target;
distance = 7000;
}
}
if (ks.IsKeyDown(Keys.A))
{
/*foreach (var unit in core.Swarm)
{
unit.X = 200;
unit.Y = 200;
}*/
core.TestMonster.X = 12;
core.TestMonster.Y = 4;
}
} }
} }
} }
+8 -3
View File
@@ -49,7 +49,8 @@ namespace DepthsBelow
MouseState ms = Mouse.GetState(); MouseState ms = Mouse.GetState();
Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); Vector2 mouseWorldPos = core.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y));
KeyboardState ks = Keyboard.GetState(); KeyboardState ks = Keyboard.GetState();
if (core.PlayerTurn == true)
{
// Selection rectangle // Selection rectangle
if (ms.LeftButton == ButtonState.Pressed) if (ms.LeftButton == ButtonState.Pressed)
{ {
@@ -106,12 +107,15 @@ namespace DepthsBelow
// Send orders with right click // Send orders with right click
if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed) if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
{
if (checkingDirection == false)
{ {
foreach (var unit in core.Squad) foreach (var unit in core.Squad)
if (unit.Selected) if (unit.Selected)
{ {
unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos); unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos);
} }
}
} }
if (ms.RightButton == ButtonState.Pressed) if (ms.RightButton == ButtonState.Pressed)
@@ -144,7 +148,8 @@ namespace DepthsBelow
} }
else else
{ {
*/unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y - unit.Transform.World.Origin.Y, mouseWorldPos.X - unit.Transform.World.X - unit.Transform.World.Origin.X);/* */
unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y - unit.Transform.World.Origin.Y, mouseWorldPos.X - unit.Transform.World.X - unit.Transform.World.Origin.X);/*
}*/ }*/
//Console.WriteLine(angle); //Console.WriteLine(angle);
//unit.GetComponent<Component.Transform>().World.Rotation = angle; //unit.GetComponent<Component.Transform>().World.Rotation = angle;
@@ -154,7 +159,7 @@ namespace DepthsBelow
{ {
checkingDirection = false; checkingDirection = false;
} }
}
// Grid highlighting // Grid highlighting
Point mouseGridPos = Grid.WorldToGrid(mouseWorldPos); Point mouseGridPos = Grid.WorldToGrid(mouseWorldPos);
Vector2 rectWorldPos = Grid.GridToWorld(mouseGridPos); Vector2 rectWorldPos = Grid.GridToWorld(mouseGridPos);
+38 -3
View File
@@ -18,6 +18,18 @@ namespace DepthsBelow
private PathFinder.Node nextNode; private PathFinder.Node nextNode;
public int numberOfSteps = 5;
public int currentStep = 0;
public int step
{
get { return currentStep; }
set
{
currentStep = value;
}
}
public SmallEnemy(Core core, ref List<SmallEnemy> swarm) public SmallEnemy(Core core, ref List<SmallEnemy> swarm)
: base(core) : base(core)
{ {
@@ -58,7 +70,7 @@ namespace DepthsBelow
{ {
base.Update(gameTime); base.Update(gameTime);
/*float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
if (nextNode == null) if (nextNode == null)
nextNode = GetComponent<PathFinder>().Next(); nextNode = GetComponent<PathFinder>().Next();
@@ -81,7 +93,18 @@ namespace DepthsBelow
} }
} }
foreach (var soldier in core.Squad)
{
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) if (nextNode != null)
{ {
@@ -98,10 +121,22 @@ namespace DepthsBelow
Transform.World.Y -= speed; Transform.World.Y -= speed;
if (Transform.World == nodeWorldPos) if (Transform.World == nodeWorldPos)
{
if (currentStep < numberOfSteps)
{
currentStep++;
//lastLastNode = lastNode;
//lastNode = nextNode;
nextNode = GetComponent<PathFinder>().Next(); nextNode = GetComponent<PathFinder>().Next();
} }
else
{
GetComponent<PathFinder>().Stop();
}
}
}
}*/ }
} }
} }
} }
+1 -4
View File
@@ -25,10 +25,7 @@ namespace DepthsBelow
public int step public int step
{ {
get get { return currentStep; }
{
return currentStep;
}
set set
{ {
currentStep = value; currentStep = value;