From b1625b15a028c2469df29f815280d1e79b7376e8 Mon Sep 17 00:00:00 2001 From: Conor Edmonds Date: Tue, 30 Jun 2026 18:24:11 -0400 Subject: [PATCH] implemented visibility, so pegs can only scope out as far as they can see. --- Peg.cs | 28 ++++++++++++++++++++-------- PegController.cs | 18 +++++++++--------- Pegs/Actions/BasicMovement.cs | 20 ++++++++++++-------- Pegs/Actions/Shortbow.cs | 3 +-- Pegs/Actions/Shortsword.cs | 7 +++---- Pegs/HostilePegs/Archer.cs | 1 + Pegs/HostilePegs/Infantry.cs | 1 + Pegs/PegAction.cs | 7 ++++++- 8 files changed, 53 insertions(+), 32 deletions(-) diff --git a/Peg.cs b/Peg.cs index ca81729..a2985b9 100644 --- a/Peg.cs +++ b/Peg.cs @@ -7,7 +7,7 @@ public partial class Peg : HoverableNode { [Signal] public delegate void DeathEventHandler(Peg THIS); - public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _visibility = 4, _movement = 0, _disposition; + public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _movement = 0, _disposition, _visibility; public Vector2I _address; public List _path = new(); public PegController _pegController; @@ -36,12 +36,6 @@ public partial class Peg : HoverableNode break; } } - if (action == null) - { - return null; - } - - _staminaRemaining -= action._cost; return action; } @@ -68,10 +62,28 @@ public partial class Peg : HoverableNode return pathsOverZeroCount.OrderBy(p => p.Count).ToList()[0]; } + public virtual List GetVisibleCells() + { + Map map = _pegController._playArea._map; + return [.. map._cells.Where(c => (c - _address).Length() <= _visibility)]; + } + public virtual List GetGoals() { Map map = _pegController._playArea._map; - return [.. map._cells.Where(c => c.Y == (_disposition == 1 ? map._lastOpenRow : map._firstOpenRow)).Where(c => !map._astar.IsPointSolid(c))]; + TileMapLayer pathLayer = _pegController._playArea.GetNode("PathLayer"); + List pl = [.. pathLayer.GetUsedCells()]; + List visible = GetVisibleCells(); + if (_id == 4) + for (int i = 0; i < pl.Count; i++) + { + Vector2I cell = pl[i]; + pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(cell,0,Vector2I.Down + Vector2I.Right*(visible.IndexOf(cell) > -1 ? 1 : 4))); + + } + List unoccupied = [.. visible.Where(c => !map._astar.IsPointSolid(c))]; + List closest = [.. unoccupied.Where(c => c.Y == (_disposition == -1 ? unoccupied.Min(c => c.Y) : unoccupied.Max(c => c.Y))).OrderByDescending(c => Math.Abs(c.X - _address.X))]; + return closest; } public Vector2 GetPositionFromAddress() diff --git a/PegController.cs b/PegController.cs index 70a2f2c..fafff24 100644 --- a/PegController.cs +++ b/PegController.cs @@ -5,6 +5,8 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection.Metadata; +using System.Reflection.Metadata.Ecma335; +using System.Threading; using System.Threading.Tasks; using System.Xml; @@ -52,6 +54,7 @@ public partial class PegController : TurnController { HostilePeg newHostilePeg = Globals.GetRandomFromList(_hostilePegScenes).Instantiate(); newHostilePeg._id = _pegsCreated; + newHostilePeg.Scale *= _pegsCreated == 4 ? 1.5f : 1f; newHostilePeg.Death += HandlePegRemoval; newHostilePeg.Click += HandlePegClick; @@ -80,6 +83,7 @@ public partial class PegController : TurnController if (action != null) { + action.DoImmediately(peg); string key = action._priority + ":" + loop; if (!_tweenStages.ContainsKey(key)) { @@ -90,24 +94,23 @@ public partial class PegController : TurnController { anyPegsActed = true; } + peg._staminaRemaining -= action._cost; } } loop++; } + ProcessTween(); } public void HandlePegClick(Node CLICKED_NODE, int CLICK_TYPE) { + TileMapLayer pathLayer = _playArea.GetNode("PathLayer"); if (CLICKED_NODE is not Peg peg) { return; } if (CLICK_TYPE == 0) { - if (peg._staminaRemaining <= 0){ - return; - } - TileMapLayer pathLayer = _playArea.GetNode("PathLayer"); List newPath = peg.GetBestPath(); pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down*4)); @@ -138,7 +141,7 @@ public partial class PegController : TurnController public void Initiate() { - List positions = [.. _playArea.GetNode("InitialPositions").GetUsedCells()]; + List positions = [.. _playArea.GetNode("InitialPositions").GetUsedCells().OrderBy(c => c.Y).ThenBy(c => c.X)]; AddHostilePegs(positions); } @@ -181,12 +184,9 @@ public partial class PegController : TurnController { _pegs[i].StartTurn(); } - HandlePegSort(); - + HandlePegTurn(); - - ProcessTween(); } public void SetPeg(Peg PEG, Vector2I CELL) diff --git a/Pegs/Actions/BasicMovement.cs b/Pegs/Actions/BasicMovement.cs index 771d104..601f2cf 100644 --- a/Pegs/Actions/BasicMovement.cs +++ b/Pegs/Actions/BasicMovement.cs @@ -9,7 +9,6 @@ public partial class BasicMovement : PegAction base._Ready(); _category = "movement"; _priority = 0; - _healthChange = 0; _cost = 1; _range = 2^32; _usesMax = 2^32; @@ -17,23 +16,28 @@ public partial class BasicMovement : PegAction } public override Tween CreateAnimation(Peg PEG) + { + PegController pegController = PEG._pegController; + Map map = pegController._playArea._map; + Vector2I cell = PEG._path[0]; + Tween subtween = CreateTween(); + subtween.TweenProperty(PEG, "global_position", map.GetCellPositionFromAddress(cell), 0.25f); + PEG._path.RemoveAt(0); + return subtween; + } + + public override void DoImmediately(Peg PEG) { List path = PEG.GetBestPath(); PegController pegController = PEG._pegController; Map map = pegController._playArea._map; if (path?.Count == 0) { - return null; + return; } Vector2I cell = path[0]; - map.SetCellPeg(cell, PEG); PEG._path.Add(cell); - - Tween subtween = CreateTween(); - subtween.TweenProperty(PEG, "global_position", map.GetCellPositionFromAddress(cell), 0.25f); - - return subtween; } public override bool MeetsCriteria(Peg PEG) diff --git a/Pegs/Actions/Shortbow.cs b/Pegs/Actions/Shortbow.cs index 3147a3a..8d957ac 100644 --- a/Pegs/Actions/Shortbow.cs +++ b/Pegs/Actions/Shortbow.cs @@ -9,7 +9,6 @@ public partial class Shortbow : PegAction base._Ready(); _category = "attack"; _priority = 1; - _healthChange = -1; _cost = 2; _range = 1; _usesMax = 1; @@ -24,7 +23,7 @@ public partial class Shortbow : PegAction subtween.TweenProperty(_image, "global_position", target, 0.5f); subtween.TweenCallback(Callable.From(() => { - PEG._pegController._playerController.ChangeHealth(_healthChange, this); + PEG._pegController._playerController.ChangeHealth(-1, this); Position = Vector2.Zero; Visible = false; })); diff --git a/Pegs/Actions/Shortsword.cs b/Pegs/Actions/Shortsword.cs index 051b4b0..6cdab80 100644 --- a/Pegs/Actions/Shortsword.cs +++ b/Pegs/Actions/Shortsword.cs @@ -9,7 +9,6 @@ public partial class Shortsword : PegAction base._Ready(); _category = "attack"; _priority = 1; - _healthChange = -2; _cost = 2; _range = 0; _usesMax = 1; @@ -18,14 +17,14 @@ public partial class Shortsword : PegAction public override Tween CreateAnimation(Peg PEG) { - Vector2 target = PEG._disposition * Vector2.Up * PEG._pegController._playArea._map._cellSize; - GD.Print(target); + Vector2 target = PEG._disposition * Vector2.Down * PEG._pegController._playArea._map._cellSize; + // GD.Print(target); Tween subtween = CreateTween(); subtween.TweenProperty(_image, "visible", true, 0.0f); subtween.TweenProperty(_image, "position", target, 0.5f); subtween.TweenCallback(Callable.From(() => { - PEG._pegController._playerController.ChangeHealth(_healthChange, this); + PEG._pegController._playerController.ChangeHealth(-2, this); _image.Position = Vector2.Zero; _image.Visible = false; })); diff --git a/Pegs/HostilePegs/Archer.cs b/Pegs/HostilePegs/Archer.cs index 45edcb8..b051376 100644 --- a/Pegs/HostilePegs/Archer.cs +++ b/Pegs/HostilePegs/Archer.cs @@ -7,5 +7,6 @@ public partial class Archer : HostilePeg { base._Ready(); _stamina = 2; + _visibility = 4; } } diff --git a/Pegs/HostilePegs/Infantry.cs b/Pegs/HostilePegs/Infantry.cs index b137958..0d17c1f 100644 --- a/Pegs/HostilePegs/Infantry.cs +++ b/Pegs/HostilePegs/Infantry.cs @@ -7,5 +7,6 @@ public partial class Infantry : HostilePeg { base._Ready(); _stamina = 3; + _visibility = 3; } } diff --git a/Pegs/PegAction.cs b/Pegs/PegAction.cs index 93ffc08..676f4d1 100644 --- a/Pegs/PegAction.cs +++ b/Pegs/PegAction.cs @@ -4,7 +4,7 @@ using System; public partial class PegAction : Node2D { public string _category; - public int _priority, _healthChange, _cost, _range, _usesMax, _usesRemaining, _triggers = 0; + public int _priority, _cost, _range, _usesMax, _usesRemaining, _triggers = 0; public Sprite2D _image; public override void _Ready() @@ -18,6 +18,11 @@ public partial class PegAction : Node2D return null; } + public virtual void DoImmediately(Peg PEG) + { + + } + public virtual bool MeetsCriteria(Peg PEG) { return PEG._staminaRemaining >= _cost