From 982c3e6786964fed3e39e5fd25c683a7371daafa Mon Sep 17 00:00:00 2001 From: Conor Edmonds Date: Mon, 29 Jun 2026 18:11:28 -0400 Subject: [PATCH] added friendly and neutral peg, added disposition --- Map.cs | 51 +++++++++++++++++++++++++++++++++- Peg.cs | 16 ++++------- PegController.cs | 9 ++---- Pegs/Actions/BasicMovement.cs | 4 ++- Pegs/Actions/Shortbow.cs | 1 + Pegs/Actions/Shortsword.cs | 4 ++- Pegs/FriendlyPeg.cs | 13 +++++++++ Pegs/FriendlyPeg.cs.uid | 1 + Pegs/HostilePeg.cs | 1 + Pegs/HostilePegs/archer.tscn | 6 ++-- Pegs/HostilePegs/infantry.tscn | 2 +- Pegs/NeutralPeg.cs | 13 +++++++++ Pegs/NeutralPeg.cs.uid | 1 + Pegs/friendly_peg.tscn | 36 ++++++++++++++++++++++++ Pegs/hostile_peg.tscn | 2 +- Pegs/neutral_peg.tscn | 36 ++++++++++++++++++++++++ 16 files changed, 171 insertions(+), 25 deletions(-) create mode 100644 Pegs/FriendlyPeg.cs create mode 100644 Pegs/FriendlyPeg.cs.uid create mode 100644 Pegs/NeutralPeg.cs create mode 100644 Pegs/NeutralPeg.cs.uid create mode 100644 Pegs/friendly_peg.tscn create mode 100644 Pegs/neutral_peg.tscn diff --git a/Map.cs b/Map.cs index aae215f..0338ae6 100644 --- a/Map.cs +++ b/Map.cs @@ -24,7 +24,49 @@ public partial class Map : TileMapLayer return i; } } - return 1; + return -1; + } + } + public int _lastOpenRow + { + get + { + for (int i = _maxY; i > _minY; i--) + { + if (!IsRowFull(i)) + { + return i; + } + } + return -1; + } + } + public int _firstOpenColumn + { + get + { + for (int i = 0; i < _maxX; i++) + { + if (!IsColumnnFull(i)) + { + return i; + } + } + return -1; + } + } + public int _lastOpenColumn + { + get + { + for (int i = _maxX; i > _minX; i--) + { + if (!IsColumnnFull(i)) + { + return i; + } + } + return -1; } } public override void _Ready() @@ -83,6 +125,13 @@ public partial class Map : TileMapLayer return hasOccupant || isSolid; } + public bool IsColumnnFull(int COLUMN_TO_CHECK) + { + List rowCells = [.. _cells.Where(c => c.X == COLUMN_TO_CHECK)]; + + return rowCells.All(c => _astar.IsPointSolid(c)); + } + public bool IsRowFull(int ROW_TO_CHECK) { List rowCells = [.. _cells.Where(c => c.Y == ROW_TO_CHECK)]; diff --git a/Peg.cs b/Peg.cs index e48f935..2eecc03 100644 --- a/Peg.cs +++ b/Peg.cs @@ -7,13 +7,13 @@ 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; + public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _visibility = 4, _movement = 0, _disposition; public Dictionary _priorities = new() { {"act", 1000000}, // 1000000 to 1999999 reserved for action priorities {"movement", 0} // 0 to 999999 reserved for movement priorities }; - public Vector2I _address = -Vector2I.One, _range = Vector2I.Up; + public Vector2I _address; public List _path = new(); public PegController _pegController; public List _actions; @@ -28,7 +28,7 @@ public partial class Peg : HoverableNode public override void _Ready() { base._Ready(); - ReprioritizeActions(); + _actions = [.. GetNode("Actions").GetChildren().Cast()]; } public virtual bool Act(int SUB_STEP) { @@ -43,11 +43,10 @@ public partial class Peg : HoverableNode } if (action == null) { - GD.Print("NO ACTION"); return false; } Tween subtween = action.CreateAnimation(this); - int key = action._priority + SUB_STEP; + string key = action._priority + ":" + SUB_STEP ; if (!_pegController._tweenStages.ContainsKey(key)) { _pegController._tweenStages[key] = new(); @@ -83,7 +82,7 @@ public partial class Peg : HoverableNode public virtual List GetGoals() { Map map = _pegController._playArea._map; - return [.. map._cells.Where(c => c.Y == map._firstOpenRow).Where(c => !map._astar.IsPointSolid(c))]; + return [.. map._cells.Where(c => c.Y == (_disposition == 1 ? map._lastOpenRow : map._firstOpenRow)).Where(c => !map._astar.IsPointSolid(c))]; } public Vector2 GetPositionFromAddress() @@ -91,11 +90,6 @@ public partial class Peg : HoverableNode return _pegController._playArea._map.GetCellPositionFromAddress(_address); } - public void ReprioritizeActions() - { - _actions = [.. GetNode("Actions").GetChildren().Cast()]; - } - public virtual void StartTurn() { _staminaRemaining = _stamina; diff --git a/PegController.cs b/PegController.cs index 5bbfd2d..7502a26 100644 --- a/PegController.cs +++ b/PegController.cs @@ -14,7 +14,7 @@ public partial class PegController : TurnController public List _hostilePegScenes; public List _pegs = new(); public PlayerController _playerController; - public Dictionary> _tweenStages = new(); + public Dictionary> _tweenStages = new(); public Tween _tween; public XmlDocument _pegProbabilities = new(); @@ -62,7 +62,6 @@ public partial class PegController : TurnController AddChild(newHostilePeg); _pegsCreated++; } - } public void HandlePegTurn() @@ -78,14 +77,13 @@ public partial class PegController : TurnController { Peg peg = _pegs[i]; bool pegActed = peg.Act(loop); - if (pegActed) + if (pegActed && noPegsActed) { noPegsActed = false; } } loop++; } - } public void HandlePegClick(Node CLICKED_NODE, int CLICK_TYPE) @@ -137,8 +135,7 @@ public partial class PegController : TurnController public void ProcessTween() { - _tweenStages = _tweenStages.OrderBy(s => s.Key).ToDictionary(); - // GD.Print(string.Join(", ", _tweenStages.Keys)); + _tweenStages = _tweenStages.OrderBy(s => s.Key.Split(":")[0]).ThenBy(s => s.Key.Split(":")[1]).ToDictionary(); if (_tweenStages.Count <= 0) { EndTurn(); diff --git a/Pegs/Actions/BasicMovement.cs b/Pegs/Actions/BasicMovement.cs index cdd5f1f..3b79eca 100644 --- a/Pegs/Actions/BasicMovement.cs +++ b/Pegs/Actions/BasicMovement.cs @@ -7,6 +7,7 @@ public partial class BasicMovement : PegAction public override void _Ready() { base._Ready(); + _priority = 0; _healthChange = 0; _cost = 1; _range = 2^32; @@ -24,11 +25,12 @@ public partial class BasicMovement : PegAction return null; } Vector2I cell = path[0]; + map.SetCellPeg(cell, PEG); PEG._path.Add(cell); Tween subtween = CreateTween(); - subtween.TweenProperty(this, "global_position", map.GetCellPositionFromAddress(cell), 0.25f); + subtween.TweenProperty(PEG, "global_position", map.GetCellPositionFromAddress(cell), 0.25f); return subtween; } diff --git a/Pegs/Actions/Shortbow.cs b/Pegs/Actions/Shortbow.cs index 9e18677..f143b63 100644 --- a/Pegs/Actions/Shortbow.cs +++ b/Pegs/Actions/Shortbow.cs @@ -7,6 +7,7 @@ public partial class Shortbow : PegAction public override void _Ready() { base._Ready(); + _priority = 1; _healthChange = -1; _cost = 2; _range = 1; diff --git a/Pegs/Actions/Shortsword.cs b/Pegs/Actions/Shortsword.cs index 77bdefc..1229c37 100644 --- a/Pegs/Actions/Shortsword.cs +++ b/Pegs/Actions/Shortsword.cs @@ -7,6 +7,7 @@ public partial class Shortsword : PegAction public override void _Ready() { base._Ready(); + _priority = 1; _healthChange = -2; _cost = 2; _range = 0; @@ -16,7 +17,8 @@ public partial class Shortsword : PegAction public override Tween CreateAnimation(Peg PEG) { - Vector2 target = Vector2.Up * PEG._pegController._playArea._map._cellSize; + Vector2 target = PEG._disposition * Vector2.Up * 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); diff --git a/Pegs/FriendlyPeg.cs b/Pegs/FriendlyPeg.cs new file mode 100644 index 0000000..ca01707 --- /dev/null +++ b/Pegs/FriendlyPeg.cs @@ -0,0 +1,13 @@ +using Godot; +using System; + +public partial class FriendlyPeg : Peg +{ + + public override void _Ready() + { + base._Ready(); + _disposition = 1; + } + +} diff --git a/Pegs/FriendlyPeg.cs.uid b/Pegs/FriendlyPeg.cs.uid new file mode 100644 index 0000000..019dc03 --- /dev/null +++ b/Pegs/FriendlyPeg.cs.uid @@ -0,0 +1 @@ +uid://fxx1mrrxxqip diff --git a/Pegs/HostilePeg.cs b/Pegs/HostilePeg.cs index aadae0a..562bc58 100644 --- a/Pegs/HostilePeg.cs +++ b/Pegs/HostilePeg.cs @@ -10,6 +10,7 @@ public partial class HostilePeg : Peg public override void _Ready() { base._Ready(); + _disposition = -1; } } diff --git a/Pegs/HostilePegs/archer.tscn b/Pegs/HostilePegs/archer.tscn index 0c363b2..b2a7315 100644 --- a/Pegs/HostilePegs/archer.tscn +++ b/Pegs/HostilePegs/archer.tscn @@ -28,12 +28,12 @@ texture_filter = 1 scale = Vector2(0.5, 0.5) texture = ExtResource("2_j7but") -[node name="Actions" type="Node" parent="." unique_id=614093526] - -[node name="BasicMovement" parent="Actions" unique_id=460007250 instance=ExtResource("3_j7but")] +[node name="Actions" type="Node2D" parent="." unique_id=96111050] [node name="Shortbow" parent="Actions" unique_id=518048625 instance=ExtResource("3_c81uf")] +[node name="BasicMovement" parent="Actions" unique_id=460007250 instance=ExtResource("3_j7but")] + [node name="HoverBounds" type="Area2D" parent="." unique_id=937525982] [node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=2142666816] diff --git a/Pegs/HostilePegs/infantry.tscn b/Pegs/HostilePegs/infantry.tscn index ae877d8..c83fd2d 100644 --- a/Pegs/HostilePegs/infantry.tscn +++ b/Pegs/HostilePegs/infantry.tscn @@ -28,7 +28,7 @@ texture_filter = 1 scale = Vector2(0.5, 0.5) texture = ExtResource("2_b77ka") -[node name="Actions" type="Node" parent="." unique_id=2081138574] +[node name="Actions" type="Node2D" parent="." unique_id=1442443799] [node name="Shortsword" parent="Actions" unique_id=518048625 instance=ExtResource("3_lwlv5")] diff --git a/Pegs/NeutralPeg.cs b/Pegs/NeutralPeg.cs new file mode 100644 index 0000000..4f73acc --- /dev/null +++ b/Pegs/NeutralPeg.cs @@ -0,0 +1,13 @@ +using Godot; +using System; + +public partial class NeutralPeg : Peg +{ + + public override void _Ready() + { + base._Ready(); + _disposition = 0; + } + +} diff --git a/Pegs/NeutralPeg.cs.uid b/Pegs/NeutralPeg.cs.uid new file mode 100644 index 0000000..c696601 --- /dev/null +++ b/Pegs/NeutralPeg.cs.uid @@ -0,0 +1 @@ +uid://hcna8x41gtkq diff --git a/Pegs/friendly_peg.tscn b/Pegs/friendly_peg.tscn new file mode 100644 index 0000000..b4e6090 --- /dev/null +++ b/Pegs/friendly_peg.tscn @@ -0,0 +1,36 @@ +[gd_scene format=3 uid="uid://tym3gfecxnhf"] + +[ext_resource type="Script" uid="uid://fxx1mrrxxqip" path="res://Pegs/FriendlyPeg.cs" id="1_d26yj"] +[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="1_q81kk"] + +[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"] +bounce = 0.5 + +[sub_resource type="CircleShape2D" id="CircleShape2D_4gyqm"] +radius = 12.5 + +[sub_resource type="CircleShape2D" id="CircleShape2D_6w6fg"] +radius = 12.5 + +[node name="FriendlyPeg" type="StaticBody2D" unique_id=1417697759] +input_pickable = true +physics_material_override = SubResource("PhysicsMaterial_7k104") +script = ExtResource("1_d26yj") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1762191899] +shape = SubResource("CircleShape2D_4gyqm") + +[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605] +texture_filter = 1 +scale = Vector2(0.5, 0.5) +texture = ExtResource("1_q81kk") + +[node name="Actions" type="Node2D" parent="." unique_id=2023031702] + +[node name="HoverBounds" type="Area2D" parent="." unique_id=937525982] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=2142666816] +shape = SubResource("CircleShape2D_6w6fg") + +[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"] +[connection signal="mouse_exited" from="." to="." method="OnMouseExited"] diff --git a/Pegs/hostile_peg.tscn b/Pegs/hostile_peg.tscn index a97f4fb..098bf5a 100644 --- a/Pegs/hostile_peg.tscn +++ b/Pegs/hostile_peg.tscn @@ -25,7 +25,7 @@ texture_filter = 1 scale = Vector2(0.5, 0.5) texture = ExtResource("2_0icqg") -[node name="Actions" type="Node" parent="." unique_id=218609326] +[node name="Actions" type="Node2D" parent="." unique_id=2023031702] [node name="HoverBounds" type="Area2D" parent="." unique_id=937525982] diff --git a/Pegs/neutral_peg.tscn b/Pegs/neutral_peg.tscn new file mode 100644 index 0000000..54263ae --- /dev/null +++ b/Pegs/neutral_peg.tscn @@ -0,0 +1,36 @@ +[gd_scene format=3 uid="uid://d3jw2bvkr8ahq"] + +[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="1_bdrbe"] +[ext_resource type="Script" uid="uid://hcna8x41gtkq" path="res://Pegs/NeutralPeg.cs" id="1_vrgbl"] + +[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"] +bounce = 0.5 + +[sub_resource type="CircleShape2D" id="CircleShape2D_4gyqm"] +radius = 12.5 + +[sub_resource type="CircleShape2D" id="CircleShape2D_6w6fg"] +radius = 12.5 + +[node name="NeutralPeg" type="StaticBody2D" unique_id=1417697759] +input_pickable = true +physics_material_override = SubResource("PhysicsMaterial_7k104") +script = ExtResource("1_vrgbl") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1762191899] +shape = SubResource("CircleShape2D_4gyqm") + +[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605] +texture_filter = 1 +scale = Vector2(0.5, 0.5) +texture = ExtResource("1_bdrbe") + +[node name="Actions" type="Node2D" parent="." unique_id=2023031702] + +[node name="HoverBounds" type="Area2D" parent="." unique_id=937525982] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=2142666816] +shape = SubResource("CircleShape2D_6w6fg") + +[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"] +[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]