diff --git a/DepthsBelow/DepthsBelow/Component/Collision.cs b/DepthsBelow/DepthsBelow/Component/Collision.cs index f9da86d..7b3e097 100755 --- a/DepthsBelow/DepthsBelow/Component/Collision.cs +++ b/DepthsBelow/DepthsBelow/Component/Collision.cs @@ -19,6 +19,11 @@ namespace DepthsBelow.Component /// public Rectangle Rectangle; + /// + /// Whether the entity is solid to other entities. + /// + public bool Solid = false; + /// /// Width of the collision rectangle. /// diff --git a/DepthsBelow/DepthsBelow/Component/PathFinder.cs b/DepthsBelow/DepthsBelow/Component/PathFinder.cs index def0eef..83e7f22 100755 --- a/DepthsBelow/DepthsBelow/Component/PathFinder.cs +++ b/DepthsBelow/DepthsBelow/Component/PathFinder.cs @@ -152,7 +152,19 @@ namespace DepthsBelow.Component { byte[,] mapCollisionMap = Core.Map.GetCollisionMap(); - // Add solid collision component entities + // Add solid collision component entities + foreach (var collision in EntityManager.GetComponents()) + { + if (collision.Solid && collision.Parent != this.Parent) + { + try + { + var pos = collision.Parent.Position; + mapCollisionMap[pos.X, pos.Y] = 0; + } + catch { } + } + } if (appendCollisionMap != null) foreach (var point in appendCollisionMap) diff --git a/DepthsBelow/DepthsBelow/MouseInput.cs b/DepthsBelow/DepthsBelow/MouseInput.cs index 7dfb5e8..054142d 100755 --- a/DepthsBelow/DepthsBelow/MouseInput.cs +++ b/DepthsBelow/DepthsBelow/MouseInput.cs @@ -171,7 +171,7 @@ namespace DepthsBelow // TODO: OnClick events // Tooltip stuff - var tooltip = core.Lua.GetObject("ToolTip"); + /*var tooltip = core.Lua.GetObject("ToolTip"); if (tooltip != null) { tooltip.Visible = false; @@ -189,7 +189,7 @@ namespace DepthsBelow tooltip.X = ms.X + 10; tooltip.Y = ms.Y + 15; } - } + }*/ if (core.TurnManager.CurrentTurn == core.TurnManager["Player"]) { diff --git a/DepthsBelow/DepthsBelow/SmallEnemy.cs b/DepthsBelow/DepthsBelow/SmallEnemy.cs index c22b4ad..0945985 100755 --- a/DepthsBelow/DepthsBelow/SmallEnemy.cs +++ b/DepthsBelow/DepthsBelow/SmallEnemy.cs @@ -45,7 +45,8 @@ namespace DepthsBelow var rc = new SpriteRenderer(this) { Texture = Texture, Color = Color.White }; AddComponent(rc); - var cc = new Collision(this, 32, 32); + var cc = new Collision(this, 32, 32); + cc.Solid = true; AddComponent(cc); var pfc = new PathFinder(this); diff --git a/DepthsBelow/DepthsBelow/Soldier.cs b/DepthsBelow/DepthsBelow/Soldier.cs index ab6ed91..5c9c1b1 100755 --- a/DepthsBelow/DepthsBelow/Soldier.cs +++ b/DepthsBelow/DepthsBelow/Soldier.cs @@ -1,202 +1,202 @@ -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 Soldier : Entity - { - public static Texture2D Texture; - public Color Color; - public string Name; - private bool _selected; - - public List Squad; - - private PathFinder.Node nextNode; - private PathFinder.Node lastNode; - private PathFinder.Node lastLastNode; - - private bool hasFiredAlready = false; - - int fireTimer = 0; - int timeSpentFired = 1000; - - public bool Fired - { - get { return hasFiredAlready; } - set - { - hasFiredAlready = value; - } - } - - public int MaxActionPoints = 10; - int actionPointsLeft = 0; - - public int AP - { - get { return actionPointsLeft; } - set - { - actionPointsLeft = value; - GetComponent().GetStep = actionPointsLeft; - } - } - +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 Soldier : Entity + { + public static Texture2D Texture; + public Color Color; + public string Name; + private bool _selected; + + public List Squad; + + private PathFinder.Node nextNode; + private PathFinder.Node lastNode; + private PathFinder.Node lastLastNode; + + private bool hasFiredAlready = false; + + int fireTimer = 0; + int timeSpentFired = 1000; + + public bool Fired + { + get { return hasFiredAlready; } + set + { + hasFiredAlready = value; + } + } + + public int MaxActionPoints = 10; + int actionPointsLeft = 10; + + public int AP + { + get { return actionPointsLeft; } + set + { + actionPointsLeft = value; + GetComponent().GetStep = actionPointsLeft; + } + } + public Soldier(ref List squad) - : base() - { - if (Texture == null) - LoadContent(); - - 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); - - var flashlight = new Flashlight(this) - { - Intensity = 0.8f - }; - AddComponent(flashlight); - - var stat = new Component.Stat(this) - { - MaxHP = 100, - MaxPanic = 100, - //Life = 10, - Defence = 10, - Strength = 50, - GetAim = 40, - GetDodge = 20 - }; - AddComponent(stat); - } - - public override void Remove() - { - Squad.Remove(this); - - base.Remove(); - } - - public bool Selected - { - get { return _selected; } - set - { - _selected = value; - GetComponent().Color = (value) ? Color.Blue : this.Color; - } - } - - public static void LoadContent() - { - Texture = GameServices.GetService().Load("images/soldier5"); - } - - public override void Update(GameTime gameTime) - { - base.Update(gameTime); - - float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; - - if (nextNode == null) - nextNode = GetComponent().Next(); - - if (nextNode != null) - { - List soldierCollisions = new List(); - - // Collision with units at a standstill - //foreach (var soldier in Squad) - //{ - // if (soldier != this) - // { - // if (!soldier.GetComponent().IsMoving) - // { - // soldierCollisions.Add(soldier.Transform.Grid); - // } - // if (soldier.Transform.Grid == nextNode.Position) - // { - // GetComponent().RecreatePath(soldierCollisions); - // nextNode = GetComponent().Next(); - // break; - // } - // } - - //} - - // Collision with moving units - //foreach (var soldier in Squad) - //{ - // if (soldier != this) - // { - // var pathFinder = soldier.GetComponent(); - // var position = nextNode.Position; - // if (soldier.Transform.Grid == position) - // { - // soldierCollisions.Add(soldier.Transform.Grid); - // GetComponent().RecreatePath(soldierCollisions); - // nextNode = GetComponent().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 (AP < NumberOfActionPoints) - //{ - //AP++; - lastLastNode = lastNode; - lastNode = nextNode; - nextNode = GetComponent().Next(); - //} - /*else - { - GetComponent().Stop(); - }*/ - } - } - } - if (Fired == true) - { - fireTimer += gameTime.ElapsedGameTime.Milliseconds; - if (fireTimer > timeSpentFired) - { - fireTimer = 0; - Fired = false; - } - } - } - } + : base() + { + if (Texture == null) + LoadContent(); + + 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); + + var flashlight = new Flashlight(this) + { + Intensity = 0.8f + }; + AddComponent(flashlight); + + var stat = new Component.Stat(this) + { + MaxHP = 100, + MaxPanic = 100, + //Life = 10, + Defence = 10, + Strength = 50, + GetAim = 40, + GetDodge = 20 + }; + AddComponent(stat); + } + + public override void Remove() + { + Squad.Remove(this); + + base.Remove(); + } + + public bool Selected + { + get { return _selected; } + set + { + _selected = value; + GetComponent().Color = (value) ? Color.Blue : this.Color; + } + } + + public static void LoadContent() + { + Texture = GameServices.GetService().Load("images/soldier5"); + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + + float elapsed = gameTime.ElapsedGameTime.Milliseconds / 1000.0f; + + if (nextNode == null) + nextNode = GetComponent().Next(); + + if (nextNode != null) + { + List soldierCollisions = new List(); + + // Collision with units at a standstill + //foreach (var soldier in Squad) + //{ + // if (soldier != this) + // { + // if (!soldier.GetComponent().IsMoving) + // { + // soldierCollisions.Add(soldier.Transform.Grid); + // } + // if (soldier.Transform.Grid == nextNode.Position) + // { + // GetComponent().RecreatePath(soldierCollisions); + // nextNode = GetComponent().Next(); + // break; + // } + // } + + //} + + // Collision with moving units + //foreach (var soldier in Squad) + //{ + // if (soldier != this) + // { + // var pathFinder = soldier.GetComponent(); + // var position = nextNode.Position; + // if (soldier.Transform.Grid == position) + // { + // soldierCollisions.Add(soldier.Transform.Grid); + // GetComponent().RecreatePath(soldierCollisions); + // nextNode = GetComponent().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 (AP < NumberOfActionPoints) + //{ + //AP++; + lastLastNode = lastNode; + lastNode = nextNode; + nextNode = GetComponent().Next(); + //} + /*else + { + GetComponent().Stop(); + }*/ + } + } + } + if (Fired == true) + { + fireTimer += gameTime.ElapsedGameTime.Milliseconds; + if (fireTimer > timeSpentFired) + { + fireTimer = 0; + Fired = false; + } + } + } + } } \ No newline at end of file