Entities with collision components can now be solid to the pathfinder.
This commit is contained in:
@@ -19,6 +19,11 @@ namespace DepthsBelow.Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Rectangle Rectangle;
|
public Rectangle Rectangle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the entity is solid to other entities.
|
||||||
|
/// </summary>
|
||||||
|
public bool Solid = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Width of the collision rectangle.
|
/// Width of the collision rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -152,7 +152,19 @@ namespace DepthsBelow.Component
|
|||||||
{
|
{
|
||||||
byte[,] mapCollisionMap = Core.Map.GetCollisionMap();
|
byte[,] mapCollisionMap = Core.Map.GetCollisionMap();
|
||||||
|
|
||||||
// Add solid collision component entities
|
// Add solid collision component entities
|
||||||
|
foreach (var collision in EntityManager.GetComponents<Collision>())
|
||||||
|
{
|
||||||
|
if (collision.Solid && collision.Parent != this.Parent)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var pos = collision.Parent.Position;
|
||||||
|
mapCollisionMap[pos.X, pos.Y] = 0;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (appendCollisionMap != null)
|
if (appendCollisionMap != null)
|
||||||
foreach (var point in appendCollisionMap)
|
foreach (var point in appendCollisionMap)
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ namespace DepthsBelow
|
|||||||
// TODO: OnClick events
|
// TODO: OnClick events
|
||||||
|
|
||||||
// Tooltip stuff
|
// Tooltip stuff
|
||||||
var tooltip = core.Lua.GetObject<GUI.Frame>("ToolTip");
|
/*var tooltip = core.Lua.GetObject<GUI.Frame>("ToolTip");
|
||||||
if (tooltip != null)
|
if (tooltip != null)
|
||||||
{
|
{
|
||||||
tooltip.Visible = false;
|
tooltip.Visible = false;
|
||||||
@@ -189,7 +189,7 @@ namespace DepthsBelow
|
|||||||
tooltip.X = ms.X + 10;
|
tooltip.X = ms.X + 10;
|
||||||
tooltip.Y = ms.Y + 15;
|
tooltip.Y = ms.Y + 15;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
|
if (core.TurnManager.CurrentTurn == core.TurnManager["Player"])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ namespace DepthsBelow
|
|||||||
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);
|
||||||
|
cc.Solid = true;
|
||||||
AddComponent(cc);
|
AddComponent(cc);
|
||||||
|
|
||||||
var pfc = new PathFinder(this);
|
var pfc = new PathFinder(this);
|
||||||
|
|||||||
+200
-200
@@ -1,202 +1,202 @@
|
|||||||
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 Soldier : Entity
|
public class Soldier : Entity
|
||||||
{
|
{
|
||||||
public static Texture2D Texture;
|
public static Texture2D Texture;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
public string Name;
|
public string Name;
|
||||||
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;
|
||||||
|
|
||||||
private bool hasFiredAlready = false;
|
private bool hasFiredAlready = false;
|
||||||
|
|
||||||
int fireTimer = 0;
|
int fireTimer = 0;
|
||||||
int timeSpentFired = 1000;
|
int timeSpentFired = 1000;
|
||||||
|
|
||||||
public bool Fired
|
public bool Fired
|
||||||
{
|
{
|
||||||
get { return hasFiredAlready; }
|
get { return hasFiredAlready; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
hasFiredAlready = value;
|
hasFiredAlready = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int MaxActionPoints = 10;
|
public int MaxActionPoints = 10;
|
||||||
int actionPointsLeft = 0;
|
int actionPointsLeft = 10;
|
||||||
|
|
||||||
public int AP
|
public int AP
|
||||||
{
|
{
|
||||||
get { return actionPointsLeft; }
|
get { return actionPointsLeft; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
actionPointsLeft = value;
|
actionPointsLeft = value;
|
||||||
GetComponent<Component.Stat>().GetStep = actionPointsLeft;
|
GetComponent<Component.Stat>().GetStep = actionPointsLeft;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Soldier(ref List<Soldier> squad)
|
public Soldier(ref List<Soldier> squad)
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
if (Texture == null)
|
if (Texture == null)
|
||||||
LoadContent();
|
LoadContent();
|
||||||
|
|
||||||
this.Squad = squad;
|
this.Squad = squad;
|
||||||
|
|
||||||
Transform.World.Origin = new Vector2(16, 16);
|
Transform.World.Origin = new Vector2(16, 16);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
var pfc = new PathFinder(this);
|
var pfc = new PathFinder(this);
|
||||||
AddComponent(pfc);
|
AddComponent(pfc);
|
||||||
|
|
||||||
var flashlight = new Flashlight(this)
|
var flashlight = new Flashlight(this)
|
||||||
{
|
{
|
||||||
Intensity = 0.8f
|
Intensity = 0.8f
|
||||||
};
|
};
|
||||||
AddComponent(flashlight);
|
AddComponent(flashlight);
|
||||||
|
|
||||||
var stat = new Component.Stat(this)
|
var stat = new Component.Stat(this)
|
||||||
{
|
{
|
||||||
MaxHP = 100,
|
MaxHP = 100,
|
||||||
MaxPanic = 100,
|
MaxPanic = 100,
|
||||||
//Life = 10,
|
//Life = 10,
|
||||||
Defence = 10,
|
Defence = 10,
|
||||||
Strength = 50,
|
Strength = 50,
|
||||||
GetAim = 40,
|
GetAim = 40,
|
||||||
GetDodge = 20
|
GetDodge = 20
|
||||||
};
|
};
|
||||||
AddComponent(stat);
|
AddComponent(stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Remove()
|
public override void Remove()
|
||||||
{
|
{
|
||||||
Squad.Remove(this);
|
Squad.Remove(this);
|
||||||
|
|
||||||
base.Remove();
|
base.Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Selected
|
public bool Selected
|
||||||
{
|
{
|
||||||
get { return _selected; }
|
get { return _selected; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_selected = value;
|
_selected = value;
|
||||||
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
|
GetComponent<SpriteRenderer>().Color = (value) ? Color.Blue : this.Color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadContent()
|
public static void LoadContent()
|
||||||
{
|
{
|
||||||
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/soldier5");
|
Texture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/soldier5");
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
if (nextNode == null)
|
if (nextNode == null)
|
||||||
nextNode = GetComponent<PathFinder>().Next();
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
|
|
||||||
if (nextNode != null)
|
if (nextNode != null)
|
||||||
{
|
{
|
||||||
List<Point> soldierCollisions = new List<Point>();
|
List<Point> soldierCollisions = new List<Point>();
|
||||||
|
|
||||||
// Collision with units at a standstill
|
// Collision with units at a standstill
|
||||||
//foreach (var soldier in Squad)
|
//foreach (var soldier in Squad)
|
||||||
//{
|
//{
|
||||||
// if (soldier != this)
|
// if (soldier != this)
|
||||||
// {
|
// {
|
||||||
// if (!soldier.GetComponent<PathFinder>().IsMoving)
|
// if (!soldier.GetComponent<PathFinder>().IsMoving)
|
||||||
// {
|
// {
|
||||||
// soldierCollisions.Add(soldier.Transform.Grid);
|
// soldierCollisions.Add(soldier.Transform.Grid);
|
||||||
// }
|
// }
|
||||||
// if (soldier.Transform.Grid == nextNode.Position)
|
// if (soldier.Transform.Grid == nextNode.Position)
|
||||||
// {
|
// {
|
||||||
// GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
// GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
||||||
// nextNode = GetComponent<PathFinder>().Next();
|
// nextNode = GetComponent<PathFinder>().Next();
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Collision with moving units
|
// Collision with moving units
|
||||||
//foreach (var soldier in Squad)
|
//foreach (var soldier in Squad)
|
||||||
//{
|
//{
|
||||||
// if (soldier != this)
|
// if (soldier != this)
|
||||||
// {
|
// {
|
||||||
// var pathFinder = soldier.GetComponent<PathFinder>();
|
// var pathFinder = soldier.GetComponent<PathFinder>();
|
||||||
// var position = nextNode.Position;
|
// var position = nextNode.Position;
|
||||||
// if (soldier.Transform.Grid == position)
|
// if (soldier.Transform.Grid == position)
|
||||||
// {
|
// {
|
||||||
// soldierCollisions.Add(soldier.Transform.Grid);
|
// soldierCollisions.Add(soldier.Transform.Grid);
|
||||||
// GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
// GetComponent<PathFinder>().RecreatePath(soldierCollisions);
|
||||||
// nextNode = GetComponent<PathFinder>().Next();
|
// nextNode = GetComponent<PathFinder>().Next();
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if (nextNode != null)
|
if (nextNode != null)
|
||||||
{
|
{
|
||||||
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
|
var nodeWorldPos = Grid.GridToWorld(nextNode.Position);
|
||||||
// HACK: Make this work properly with other speeds...
|
// HACK: Make this work properly with other speeds...
|
||||||
float speed = 4f;
|
float speed = 4f;
|
||||||
if (Transform.World.X < nodeWorldPos.X)
|
if (Transform.World.X < nodeWorldPos.X)
|
||||||
Transform.World.X += speed;
|
Transform.World.X += speed;
|
||||||
if (Transform.World.X > nodeWorldPos.X)
|
if (Transform.World.X > nodeWorldPos.X)
|
||||||
Transform.World.X -= speed;
|
Transform.World.X -= speed;
|
||||||
if (Transform.World.Y < nodeWorldPos.Y)
|
if (Transform.World.Y < nodeWorldPos.Y)
|
||||||
Transform.World.Y += speed;
|
Transform.World.Y += speed;
|
||||||
if (Transform.World.Y > nodeWorldPos.Y)
|
if (Transform.World.Y > nodeWorldPos.Y)
|
||||||
Transform.World.Y -= speed;
|
Transform.World.Y -= speed;
|
||||||
|
|
||||||
if (Transform.World == nodeWorldPos)
|
if (Transform.World == nodeWorldPos)
|
||||||
{
|
{
|
||||||
//if (AP < NumberOfActionPoints)
|
//if (AP < NumberOfActionPoints)
|
||||||
//{
|
//{
|
||||||
//AP++;
|
//AP++;
|
||||||
lastLastNode = lastNode;
|
lastLastNode = lastNode;
|
||||||
lastNode = nextNode;
|
lastNode = nextNode;
|
||||||
nextNode = GetComponent<PathFinder>().Next();
|
nextNode = GetComponent<PathFinder>().Next();
|
||||||
//}
|
//}
|
||||||
/*else
|
/*else
|
||||||
{
|
{
|
||||||
GetComponent<PathFinder>().Stop();
|
GetComponent<PathFinder>().Stop();
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Fired == true)
|
if (Fired == true)
|
||||||
{
|
{
|
||||||
fireTimer += gameTime.ElapsedGameTime.Milliseconds;
|
fireTimer += gameTime.ElapsedGameTime.Milliseconds;
|
||||||
if (fireTimer > timeSpentFired)
|
if (fireTimer > timeSpentFired)
|
||||||
{
|
{
|
||||||
fireTimer = 0;
|
fireTimer = 0;
|
||||||
Fired = false;
|
Fired = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user