added friendly and neutral peg, added disposition

This commit is contained in:
2026-06-29 18:11:28 -04:00
parent ebdff1b200
commit 982c3e6786
16 changed files with 171 additions and 25 deletions
+50 -1
View File
@@ -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<Vector2I> rowCells = [.. _cells.Where(c => c.X == COLUMN_TO_CHECK)];
return rowCells.All(c => _astar.IsPointSolid(c));
}
public bool IsRowFull(int ROW_TO_CHECK)
{
List<Vector2I> rowCells = [.. _cells.Where(c => c.Y == ROW_TO_CHECK)];
+5 -11
View File
@@ -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<string, int> _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<Vector2I> _path = new();
public PegController _pegController;
public List<PegAction> _actions;
@@ -28,7 +28,7 @@ public partial class Peg : HoverableNode
public override void _Ready()
{
base._Ready();
ReprioritizeActions();
_actions = [.. GetNode<Node2D>("Actions").GetChildren().Cast<PegAction>()];
}
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<Vector2I> 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<Node>("Actions").GetChildren().Cast<PegAction>()];
}
public virtual void StartTurn()
{
_staminaRemaining = _stamina;
+3 -6
View File
@@ -14,7 +14,7 @@ public partial class PegController : TurnController
public List<PackedScene> _hostilePegScenes;
public List<Peg> _pegs = new();
public PlayerController _playerController;
public Dictionary<int, List<Tween>> _tweenStages = new();
public Dictionary<string, List<Tween>> _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();
+3 -1
View File
@@ -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;
}
+1
View File
@@ -7,6 +7,7 @@ public partial class Shortbow : PegAction
public override void _Ready()
{
base._Ready();
_priority = 1;
_healthChange = -1;
_cost = 2;
_range = 1;
+3 -1
View File
@@ -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);
+13
View File
@@ -0,0 +1,13 @@
using Godot;
using System;
public partial class FriendlyPeg : Peg
{
public override void _Ready()
{
base._Ready();
_disposition = 1;
}
}
+1
View File
@@ -0,0 +1 @@
uid://fxx1mrrxxqip
+1
View File
@@ -10,6 +10,7 @@ public partial class HostilePeg : Peg
public override void _Ready()
{
base._Ready();
_disposition = -1;
}
}
+3 -3
View File
@@ -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]
+1 -1
View File
@@ -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")]
+13
View File
@@ -0,0 +1,13 @@
using Godot;
using System;
public partial class NeutralPeg : Peg
{
public override void _Ready()
{
base._Ready();
_disposition = 0;
}
}
+1
View File
@@ -0,0 +1 @@
uid://hcna8x41gtkq
+36
View File
@@ -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"]
+1 -1
View File
@@ -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]
+36
View File
@@ -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"]