All Monsters now move
This commit is contained in:
@@ -89,7 +89,7 @@ namespace DepthsBelow.Component
|
|||||||
|
|
||||||
public int Penalty(int distance)
|
public int Penalty(int distance)
|
||||||
{
|
{
|
||||||
return panic + GetPenalty(stepsTaken) + (int)(GetPenalty(distance) / 2);
|
return panic/* + GetPenalty(stepsTaken)*/ + (int)(GetPenalty(distance));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stat(Entity parent)
|
public Stat(Entity parent)
|
||||||
|
|||||||
@@ -85,9 +85,9 @@ namespace DepthsBelow
|
|||||||
/// <param name="gameTime"></param>
|
/// <param name="gameTime"></param>
|
||||||
public void Update(GameTime gameTime)
|
public void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
foreach (var entity in Entities.ToList())
|
foreach (var entity in Entities.ToList())
|
||||||
entity.Update(gameTime);
|
entity.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draw all entities handled by the entity manager.
|
/// Draw all entities handled by the entity manager.
|
||||||
|
|||||||
@@ -1,275 +1,298 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using Microsoft.Xna.Framework.Media;
|
using Microsoft.Xna.Framework.Media;
|
||||||
|
|
||||||
namespace DepthsBelow
|
namespace DepthsBelow
|
||||||
{
|
{
|
||||||
public class KeyboardInput
|
public class KeyboardInput
|
||||||
{
|
{
|
||||||
Core core;
|
Core core;
|
||||||
private KeyboardState lastKeyboardState;
|
private KeyboardState lastKeyboardState;
|
||||||
|
|
||||||
int checkerSpeed = 2;
|
int checkerSpeed = 2;
|
||||||
|
|
||||||
public KeyboardInput(Core core)
|
public KeyboardInput(Core core)
|
||||||
{
|
{
|
||||||
this.core = core;
|
this.core = core;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public List<List<Soldier>> GetGroups(List<Soldier> soldiers)
|
/*public List<List<Soldier>> GetGroups(List<Soldier> soldiers)
|
||||||
{
|
{
|
||||||
var ungrouped = soldiers.ToList();
|
var ungrouped = soldiers.ToList();
|
||||||
var groups = new List<List<Soldier>>();
|
var groups = new List<List<Soldier>>();
|
||||||
|
|
||||||
for (int index = 0; index < soldiers.Count; index++)
|
for (int index = 0; index < soldiers.Count; index++)
|
||||||
{
|
{
|
||||||
var checkingSoldier = soldiers[index];
|
var checkingSoldier = soldiers[index];
|
||||||
var group = new List<Soldier>();
|
var group = new List<Soldier>();
|
||||||
|
|
||||||
for (int i = 0; i < soldiers.Count; i++)
|
for (int i = 0; i < soldiers.Count; i++)
|
||||||
{
|
{
|
||||||
var soldier = soldiers[i];
|
var soldier = soldiers[i];
|
||||||
if (ungrouped.Contains(soldier))
|
if (ungrouped.Contains(soldier))
|
||||||
{
|
{
|
||||||
float distance = Vector2.Distance(checkingSoldier.Transform.World + checkingSoldier.Transform.World.Origin,
|
float distance = Vector2.Distance(checkingSoldier.Transform.World + checkingSoldier.Transform.World.Origin,
|
||||||
soldier.Transform.World + soldier.Transform.World.Origin);
|
soldier.Transform.World + soldier.Transform.World.Origin);
|
||||||
if (distance <= ((float) Grid.TileSize * 1f))
|
if (distance <= ((float) Grid.TileSize * 1f))
|
||||||
{
|
{
|
||||||
ungrouped.Remove(soldier);
|
ungrouped.Remove(soldier);
|
||||||
group.Add(soldier);
|
group.Add(soldier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.Count > 0)
|
if (group.Count > 0)
|
||||||
groups.Add(group);
|
groups.Add(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return groups;
|
return groups;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// Get a list of dynamic soldier groups
|
// Get a list of dynamic soldier groups
|
||||||
public List<List<Soldier>> GetGroups(List<Soldier> soldiers, float maxRange)
|
public List<List<Soldier>> GetGroups(List<Soldier> soldiers, float maxRange)
|
||||||
{
|
{
|
||||||
var alreadyGrouped = new List<Soldier>();
|
var alreadyGrouped = new List<Soldier>();
|
||||||
var groups = new List<List<Soldier>>();
|
var groups = new List<List<Soldier>>();
|
||||||
|
|
||||||
for (int index = 0; index < soldiers.Count; index++)
|
for (int index = 0; index < soldiers.Count; index++)
|
||||||
{
|
{
|
||||||
var soldier = soldiers[index];
|
var soldier = soldiers[index];
|
||||||
|
|
||||||
if (!alreadyGrouped.Contains(soldier))
|
if (!alreadyGrouped.Contains(soldier))
|
||||||
{
|
{
|
||||||
var group = new List<Soldier>();
|
var group = new List<Soldier>();
|
||||||
GetNearChain(ref group, soldiers, soldier, maxRange);
|
GetNearChain(ref group, soldiers, soldier, maxRange);
|
||||||
alreadyGrouped.AddRange(group);
|
alreadyGrouped.AddRange(group);
|
||||||
|
|
||||||
if (group.Count > 0)
|
if (group.Count > 0)
|
||||||
groups.Add(group);
|
groups.Add(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all soldiers who are close to each other in a chain
|
// Get all soldiers who are close to each other in a chain
|
||||||
public void GetNearChain(ref List<Soldier> group, List<Soldier> soldiers, Soldier soldier, float maxRange)
|
public void GetNearChain(ref List<Soldier> group, List<Soldier> soldiers, Soldier soldier, float maxRange)
|
||||||
{
|
{
|
||||||
for (int index = 0; index < soldiers.Count; index++)
|
for (int index = 0; index < soldiers.Count; index++)
|
||||||
{
|
{
|
||||||
var nearSoldier = soldiers[index];
|
var nearSoldier = soldiers[index];
|
||||||
|
|
||||||
if (!group.Contains(nearSoldier))
|
if (!group.Contains(nearSoldier))
|
||||||
{
|
{
|
||||||
float distance = Vector2.Distance(nearSoldier.Transform.World + nearSoldier.Transform.World.Origin,
|
float distance = Vector2.Distance(nearSoldier.Transform.World + nearSoldier.Transform.World.Origin,
|
||||||
soldier.Transform.World + soldier.Transform.World.Origin);
|
soldier.Transform.World + soldier.Transform.World.Origin);
|
||||||
if (distance <= maxRange)
|
if (distance <= maxRange)
|
||||||
{
|
{
|
||||||
group.Add(nearSoldier);
|
group.Add(nearSoldier);
|
||||||
GetNearChain(ref group, soldiers, nearSoldier, maxRange);
|
GetNearChain(ref group, soldiers, nearSoldier, maxRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private DynamicGroupManager groupManager;
|
private DynamicGroupManager groupManager;
|
||||||
|
|
||||||
public void Update(GameTime gameTime)
|
public void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
KeyboardState ks = Keyboard.GetState();
|
KeyboardState ks = Keyboard.GetState();
|
||||||
|
|
||||||
// Brightness
|
// Brightness
|
||||||
if (ks.IsKeyUp(Keys.Up) && lastKeyboardState.IsKeyDown(Keys.Up))
|
if (ks.IsKeyUp(Keys.Up) && lastKeyboardState.IsKeyDown(Keys.Up))
|
||||||
core.Brightness = (int)MathHelper.Clamp(core.Brightness + 5, 0, 254);
|
core.Brightness = (int)MathHelper.Clamp(core.Brightness + 5, 0, 254);
|
||||||
if (ks.IsKeyUp(Keys.Down) && lastKeyboardState.IsKeyDown(Keys.Down))
|
if (ks.IsKeyUp(Keys.Down) && lastKeyboardState.IsKeyDown(Keys.Down))
|
||||||
core.Brightness = (int)MathHelper.Clamp(core.Brightness - 5, 0, 254);
|
core.Brightness = (int)MathHelper.Clamp(core.Brightness - 5, 0, 254);
|
||||||
|
|
||||||
// Debug test: grouping
|
// Debug test: grouping
|
||||||
if (ks.IsKeyUp(Keys.K) && lastKeyboardState.IsKeyDown(Keys.K))
|
if (ks.IsKeyUp(Keys.K) && lastKeyboardState.IsKeyDown(Keys.K))
|
||||||
{
|
{
|
||||||
if (groupManager == null)
|
if (groupManager == null)
|
||||||
groupManager = new DynamicGroupManager(core.Squad.Cast<Entity>().ToList(), Grid.TileSize * 1.5f);
|
groupManager = new DynamicGroupManager(core.Squad.Cast<Entity>().ToList(), Grid.TileSize * 1.5f);
|
||||||
groupManager.UpdateGroups();
|
groupManager.UpdateGroups();
|
||||||
//var groups = GetGroups(core.Squad, (float)Grid.TileSize * 1.5f);
|
//var groups = GetGroups(core.Squad, (float)Grid.TileSize * 1.5f);
|
||||||
var groups = groupManager.Groups;
|
var groups = groupManager.Groups;
|
||||||
foreach (var group in groups)
|
foreach (var group in groups)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Group #" + groups.IndexOf(group) + " Panic: " + group.Panic);
|
Debug.WriteLine("Group #" + groups.IndexOf(group) + " Panic: " + group.Panic);
|
||||||
foreach (var entity in group.Entities)
|
foreach (var entity in group.Entities)
|
||||||
{
|
{
|
||||||
var soldier = (Soldier)entity;
|
var soldier = (Soldier)entity;
|
||||||
Debug.WriteLine(soldier.Name + " " + soldier.GetHashCode());
|
Debug.WriteLine(soldier.Name + " " + soldier.GetHashCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next turn
|
// Next turn
|
||||||
if (ks.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter))
|
if (ks.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter))
|
||||||
{
|
{
|
||||||
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
|
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
|
||||||
{
|
{
|
||||||
foreach (var unit in core.Squad)
|
foreach (var unit in core.Squad)
|
||||||
{
|
{
|
||||||
unit.step = 0;
|
unit.step = 0;
|
||||||
unit.Fired = false;
|
unit.Fired = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.TurnManager.EndTurn();
|
core.TurnManager.EndTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core.TurnManager.CurrentTurn == core.TurnManager["Computer"])
|
if (core.TurnManager.CurrentTurn == core.TurnManager["Computer"])
|
||||||
{
|
{
|
||||||
core.TestMonster.step = 0;
|
foreach (var enemy in core.Swarm)
|
||||||
Point target = Point.Zero;
|
{
|
||||||
float distance = 7000;
|
enemy.step = 0;
|
||||||
foreach (var unit in core.Squad)
|
Point target = Point.Zero;
|
||||||
{
|
float distance = 7000;
|
||||||
Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y);
|
foreach (var unit in core.Squad)
|
||||||
Vector2 monster = new Vector2(core.TestMonster.Transform.Grid.X, core.TestMonster.Transform.Grid.Y);
|
{
|
||||||
|
Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y);
|
||||||
float newDistance = Vector2.Distance(soldier, monster);
|
Vector2 monster = new Vector2(enemy.Transform.Grid.X, enemy.Transform.Grid.Y);
|
||||||
|
|
||||||
if (newDistance < distance)
|
float newDistance = Vector2.Distance(soldier, monster);
|
||||||
{
|
|
||||||
target = unit.Transform.Grid;
|
if (newDistance < distance)
|
||||||
distance = newDistance;
|
{
|
||||||
}
|
target = unit.Transform.Grid;
|
||||||
}
|
distance = newDistance;
|
||||||
core.TestMonster.GetComponent<Component.PathFinder>().Goal = target;
|
}
|
||||||
distance = 7000;
|
}
|
||||||
|
enemy.GetComponent<Component.PathFinder>().Goal = target;
|
||||||
core.TurnManager.EndTurn();
|
distance = 7000;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (ks.IsKeyDown(Keys.A))
|
|
||||||
{
|
core.TestMonster.step = 0;
|
||||||
/*foreach (var unit in core.Swarm)
|
Point testTarget = Point.Zero;
|
||||||
{
|
float testDistance = 7000;
|
||||||
unit.X = 200;
|
foreach (var unit in core.Squad)
|
||||||
unit.Y = 200;
|
{
|
||||||
}*/
|
Vector2 soldier = new Vector2(unit.Transform.Grid.X, unit.Transform.Grid.Y);
|
||||||
core.TestMonster.X = 12;
|
Vector2 monster = new Vector2(core.TestMonster.Transform.Grid.X, core.TestMonster.Transform.Grid.Y);
|
||||||
core.TestMonster.Y = 4;
|
|
||||||
}
|
float newDistance = Vector2.Distance(soldier, monster);
|
||||||
if (ks.IsKeyDown(Keys.N))
|
|
||||||
{
|
if (newDistance < testDistance)
|
||||||
|
{
|
||||||
}
|
testTarget = unit.Transform.Grid;
|
||||||
if (ks.IsKeyDown(Keys.S))
|
testDistance = newDistance;
|
||||||
{
|
}
|
||||||
foreach (var soldier in core.Squad)
|
}
|
||||||
{
|
core.TestMonster.GetComponent<Component.PathFinder>().Goal = testTarget;
|
||||||
if (soldier.Selected == true && soldier.Fired == false)
|
testDistance = 7000;
|
||||||
{
|
|
||||||
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>()));
|
core.TurnManager.EndTurn();
|
||||||
soldier.Fired = true;
|
}
|
||||||
foreach (var shot in core.Volley)
|
}
|
||||||
{
|
if (ks.IsKeyDown(Keys.A))
|
||||||
if (shot.select == false)
|
{
|
||||||
{
|
/*foreach (var unit in core.Swarm)
|
||||||
shot.select = true;
|
{
|
||||||
shot.X = soldier.X;
|
unit.X = 200;
|
||||||
shot.Y = soldier.Y;
|
unit.Y = 200;
|
||||||
//shot.Transform.World.X += Grid.TileSize / 2;
|
}*/
|
||||||
//shot.Transform.World.Y += Grid.TileSize / 2;
|
core.TestMonster.X = 12;
|
||||||
}
|
core.TestMonster.Y = 4;
|
||||||
if (shot.direction == Vector2.Zero)
|
}
|
||||||
{
|
if (ks.IsKeyDown(Keys.N))
|
||||||
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;
|
if (ks.IsKeyDown(Keys.S))
|
||||||
}
|
{
|
||||||
}
|
foreach (var soldier in core.Squad)
|
||||||
}
|
{
|
||||||
}
|
if (soldier.Selected == true && soldier.Fired == false)
|
||||||
}
|
{
|
||||||
if (ks.IsKeyDown(Keys.C))
|
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>()));
|
||||||
{
|
soldier.Fired = true;
|
||||||
foreach (var soldier in core.Squad)
|
foreach (var shot in core.Volley)
|
||||||
{
|
{
|
||||||
if (soldier.Selected == true && soldier.Fired == false)
|
if (shot.select == false)
|
||||||
{
|
{
|
||||||
Point checker = Point.Zero;
|
shot.select = true;
|
||||||
double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation);
|
shot.X = soldier.X;
|
||||||
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation);
|
shot.Y = soldier.Y;
|
||||||
Vector2 direction = new Vector2((int)directionX, (int)directionY);
|
//shot.Transform.World.X += Grid.TileSize / 2;
|
||||||
int range = 120;
|
//shot.Transform.World.Y += Grid.TileSize / 2;
|
||||||
int current = 0;
|
}
|
||||||
bool hit = false;
|
if (shot.direction == Vector2.Zero)
|
||||||
checker = new Point((int)soldier.Transform.World.Origin.X, (int)soldier.Transform.World.Origin.Y);
|
{
|
||||||
do
|
double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation);
|
||||||
{
|
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation);
|
||||||
checker.X += (int)direction.X * checkerSpeed;
|
shot.direction = new Vector2((float)directionX, (float)directionY);
|
||||||
checker.Y += (int)direction.Y * checkerSpeed;
|
shot.Transform.World.Rotation = soldier.Transform.World.Rotation;
|
||||||
foreach (var creature in core.Swarm)
|
}
|
||||||
{
|
}
|
||||||
if (creature.GetComponent<Component.Collision>().Rectangle.Contains(checker))
|
}
|
||||||
{
|
}
|
||||||
hit = true;
|
}
|
||||||
}
|
if (ks.IsKeyDown(Keys.C))
|
||||||
}
|
{
|
||||||
if (core.TestMonster.GetComponent<Component.Collision>().Rectangle.Contains(checker))
|
foreach (var soldier in core.Squad)
|
||||||
{
|
{
|
||||||
|
if (soldier.Selected == true && soldier.Fired == false)
|
||||||
}
|
{
|
||||||
current++;
|
Point checker = Point.Zero;
|
||||||
} while (hit == false && current < range);
|
double directionX = Math.Cos(soldier.GetComponent<Component.Transform>().World.Rotation);
|
||||||
current = 0;
|
double directionY = Math.Sin(soldier.GetComponent<Component.Transform>().World.Rotation);
|
||||||
if (soldier.Selected == true && soldier.Fired == false && hit == true)
|
Vector2 direction = new Vector2((int)directionX, (int)directionY);
|
||||||
{
|
int range = 120;
|
||||||
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>()));
|
int current = 0;
|
||||||
soldier.Fired = true;
|
bool hit = false;
|
||||||
foreach (var shot in core.Volley)
|
checker = new Point((int)soldier.Transform.World.Origin.X, (int)soldier.Transform.World.Origin.Y);
|
||||||
{
|
do
|
||||||
if (shot.select == false)
|
{
|
||||||
{
|
checker.X += (int)direction.X * checkerSpeed;
|
||||||
shot.select = true;
|
checker.Y += (int)direction.Y * checkerSpeed;
|
||||||
shot.X = soldier.X;
|
foreach (var creature in core.Swarm)
|
||||||
shot.Y = soldier.Y;
|
{
|
||||||
//shot.Transform.World.X += Grid.TileSize / 2;
|
if (creature.GetComponent<Component.Collision>().Rectangle.Contains(checker))
|
||||||
//shot.Transform.World.Y += Grid.TileSize / 2;
|
{
|
||||||
}
|
hit = true;
|
||||||
if (shot.direction == Vector2.Zero)
|
}
|
||||||
{
|
}
|
||||||
shot.direction = new Vector2((float)directionX, (float)directionY);
|
if (core.TestMonster.GetComponent<Component.Collision>().Rectangle.Contains(checker))
|
||||||
shot.Transform.World.Rotation = soldier.Transform.World.Rotation;
|
{
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
current++;
|
||||||
hit = false;
|
} while (hit == false && current < range);
|
||||||
}
|
current = 0;
|
||||||
}
|
if (soldier.Selected == true && soldier.Fired == false && hit == true)
|
||||||
}
|
{
|
||||||
|
core.Volley.Add(new Shot(core.EntityManager, soldier.GetComponent<Component.Stat>()));
|
||||||
lastKeyboardState = ks;
|
soldier.Fired = true;
|
||||||
}
|
foreach (var shot in core.Volley)
|
||||||
}
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
shot.direction = new Vector2((float)directionX, (float)directionY);
|
||||||
|
shot.Transform.World.Rotation = soldier.Transform.World.Rotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hit = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastKeyboardState = ks;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,74 +1,85 @@
|
|||||||
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.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
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 Shot : Entity
|
public class Shot : Entity
|
||||||
{
|
{
|
||||||
public static Texture2D Texture;
|
public static Texture2D Texture;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
public static Point Origin;
|
public static Point Origin;
|
||||||
|
|
||||||
Stat soldierStat;
|
Stat soldierStat;
|
||||||
|
|
||||||
public Stat Stat
|
public Stat Stat
|
||||||
{
|
{
|
||||||
get { return soldierStat; }
|
get { return soldierStat; }
|
||||||
set { soldierStat = value; }
|
set { soldierStat = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _selected = false; //I guess as in "currently doing something"
|
private bool _selected = false; //I guess as in "currently doing something"
|
||||||
|
|
||||||
public bool select
|
public bool select
|
||||||
{
|
{
|
||||||
get { return _selected; }
|
get { return _selected; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_selected = value;
|
_selected = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Shot> Volley;
|
public List<Shot> Volley;
|
||||||
|
|
||||||
public Vector2 direction = Vector2.Zero;
|
public Vector2 direction = Vector2.Zero;
|
||||||
|
|
||||||
public Shot(EntityManager entityManager, Stat _soldierStat)
|
public Shot(EntityManager entityManager, Stat _soldierStat)
|
||||||
: base(entityManager)
|
: base(entityManager)
|
||||||
{
|
{
|
||||||
if (Texture == null)
|
if (Texture == null)
|
||||||
LoadContent();
|
LoadContent();
|
||||||
|
|
||||||
Transform.World.Origin = new Vector2(16, 16);
|
Transform.World.Origin = new Vector2(16, 16);
|
||||||
|
|
||||||
Stat = _soldierStat;
|
Stat = _soldierStat;
|
||||||
|
|
||||||
this.Color = Color.White;
|
this.Color = Color.White;
|
||||||
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White };
|
||||||
AddComponent(rc);
|
AddComponent(rc);
|
||||||
|
|
||||||
var cc = new Collision(this, 32, 32);
|
var cc = new Collision(this, 32, 32);
|
||||||
AddComponent(cc);
|
AddComponent(cc);
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void LoadContent()
|
public static void LoadContent()
|
||||||
{
|
{
|
||||||
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot");
|
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/Shot");
|
||||||
}
|
}
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
|
|
||||||
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
|
||||||
List<Point> soldierCollisions = new List<Point>();
|
List<Point> soldierCollisions = new List<Point>();
|
||||||
|
|
||||||
// HACK: Make this work properly with other speeds...
|
// HACK: Make this work properly with other speeds...
|
||||||
float speed = 4f;
|
float speed = 4f;
|
||||||
Transform.World.Position += speed * direction;
|
Transform.World.Position += speed * direction;
|
||||||
}
|
|
||||||
}
|
foreach (var entity in entityManager.Entities)
|
||||||
|
{
|
||||||
|
if (entity is SmallEnemy)
|
||||||
|
{
|
||||||
|
if (this.GetComponent<Component.Collision>().Rectangle.Intersects(entity.GetComponent<Component.Collision>().Rectangle))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+107
-107
@@ -1,107 +1,107 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using DepthsBelow.Component;
|
using DepthsBelow.Component;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace DepthsBelow
|
namespace DepthsBelow
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Various global utility functions.
|
/// Various global utility functions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static class Utility
|
static class Utility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculate the chance of an entity with a Stat component to hit another unit.
|
/// Calculate the chance of an entity with a Stat component to hit another unit.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="attacker">The attacking unit.</param>
|
/// <param name="attacker">The attacking unit.</param>
|
||||||
/// <param name="defender">The recieving unit.</param>
|
/// <param name="defender">The recieving unit.</param>
|
||||||
/// <returns>Returns a hit chance percentage.</returns>
|
/// <returns>Returns a hit chance percentage.</returns>
|
||||||
public static int CalculateHitChance(Entity attacker, Entity defender)
|
public static int CalculateHitChance(Entity attacker, Entity defender)
|
||||||
{
|
{
|
||||||
Stat shooting = attacker.GetComponent<Stat>();
|
Stat shooting = attacker.GetComponent<Stat>();
|
||||||
Stat dodging = defender.GetComponent<Stat>();
|
Stat dodging = defender.GetComponent<Stat>();
|
||||||
if (shooting == null || dodging == null)
|
if (shooting == null || dodging == null)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int baseHitChance = shooting.GetAim;
|
int baseHitChance = shooting.GetAim;
|
||||||
int baseDodgeChance = dodging.GetDodge;
|
int baseDodgeChance = dodging.GetDodge;
|
||||||
int distance = (int)Vector2.Distance(attacker.GetComponent<Transform>().World.Position, defender.GetComponent<Transform>().World.Position);
|
int distance = (int)Vector2.Distance(attacker.GetComponent<Transform>().World.Position, defender.GetComponent<Transform>().World.Position);
|
||||||
int basePenalty = shooting.Penalty(distance / (Grid.TileSize));
|
int basePenalty = shooting.Penalty(distance / (Grid.TileSize));
|
||||||
Console.WriteLine("Penalty = " + basePenalty);
|
Console.WriteLine("Penalty = " + basePenalty);
|
||||||
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
|
int chanceToHit = baseHitChance - baseDodgeChance - basePenalty;
|
||||||
//Console.WriteLine(chanceToHit);
|
//Console.WriteLine(chanceToHit);
|
||||||
return chanceToHit;
|
return chanceToHit;
|
||||||
}
|
}
|
||||||
/*public static bool HitTest(Entity attacker, Entity defender, int chanceToHit)
|
public static bool HitTest(Entity attacker, Entity defender, int chanceToHit)
|
||||||
{
|
{
|
||||||
Component.Stat shooting = attacker.GetComponent<Component.Stat>();
|
Component.Stat shooting = attacker.GetComponent<Component.Stat>();
|
||||||
Component.Stat dodging = defender.GetComponent<Component.Stat>();
|
Component.Stat dodging = defender.GetComponent<Component.Stat>();
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
if (rand.Next(0, 100) < chanceToHit)
|
if (rand.Next(0, 100) < chanceToHit)
|
||||||
{
|
{
|
||||||
dodging.Life -= shooting.Strength - dodging.Defence / 2;
|
dodging.Life -= shooting.Strength - dodging.Defence / 2;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}
|
||||||
private static Texture2D blank;
|
private static Texture2D blank;
|
||||||
|
|
||||||
public static void DrawLine(SpriteBatch batch, Color color, float width, Vector2 start, Vector2 end)
|
public static void DrawLine(SpriteBatch batch, Color color, float width, Vector2 start, Vector2 end)
|
||||||
{
|
{
|
||||||
if (blank == null)
|
if (blank == null)
|
||||||
{
|
{
|
||||||
blank = new Texture2D(Core.GraphicsDeviceManager.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
|
blank = new Texture2D(Core.GraphicsDeviceManager.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
|
||||||
blank.SetData(new[] { color });
|
blank.SetData(new[] { color });
|
||||||
}
|
}
|
||||||
|
|
||||||
float angle = (float)Math.Atan2(end.Y - start.Y, end.X - start.X);
|
float angle = (float)Math.Atan2(end.Y - start.Y, end.X - start.X);
|
||||||
float length = Vector2.Distance(start, end);
|
float length = Vector2.Distance(start, end);
|
||||||
|
|
||||||
batch.Draw(blank, start, null, color,
|
batch.Draw(blank, start, null, color,
|
||||||
angle, Vector2.Zero, new Vector2(length, width),
|
angle, Vector2.Zero, new Vector2(length, width),
|
||||||
SpriteEffects.None, 0);
|
SpriteEffects.None, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Texture2D solidTexture = null;
|
private static Texture2D solidTexture = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a 1x1 solid white XNA texture.
|
/// Creates a 1x1 solid white XNA texture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Returns a 1x1 solid white Texture2D object.</returns>
|
/// <returns>Returns a 1x1 solid white Texture2D object.</returns>
|
||||||
public static Texture2D GetSolidTexture()
|
public static Texture2D GetSolidTexture()
|
||||||
{
|
{
|
||||||
if (solidTexture == null)
|
if (solidTexture == null)
|
||||||
{
|
{
|
||||||
solidTexture = new Texture2D(GameServices.GetService<GraphicsDevice>(), 1, 1);
|
solidTexture = new Texture2D(GameServices.GetService<GraphicsDevice>(), 1, 1);
|
||||||
solidTexture.SetData(new Color[] { Color.White });
|
solidTexture.SetData(new Color[] { Color.White });
|
||||||
}
|
}
|
||||||
|
|
||||||
return solidTexture;
|
return solidTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts rectangles with negative sizes to positive sizes with its position offset.
|
/// Converts rectangles with negative sizes to positive sizes with its position offset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rect">The rectangle with potentially negative sizes.</param>
|
/// <param name="rect">The rectangle with potentially negative sizes.</param>
|
||||||
/// <returns>Returns a rectangle with positive sizes.</returns>
|
/// <returns>Returns a rectangle with positive sizes.</returns>
|
||||||
public static Rectangle MakeRectanglePositive(Rectangle rect)
|
public static Rectangle MakeRectanglePositive(Rectangle rect)
|
||||||
{
|
{
|
||||||
if (rect.Width < 0)
|
if (rect.Width < 0)
|
||||||
{
|
{
|
||||||
rect.X += rect.Width;
|
rect.X += rect.Width;
|
||||||
rect.Width = -rect.Width;
|
rect.Width = -rect.Width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rect.Height < 0)
|
if (rect.Height < 0)
|
||||||
{
|
{
|
||||||
rect.Y += rect.Height;
|
rect.Y += rect.Height;
|
||||||
rect.Height = -rect.Height;
|
rect.Height = -rect.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user