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