moved bucket to the playercontroller, changed tweenStages to a list of pegactions, so processtween takes in actions and builds off of that so that movement/actions priority will line up properly. change tweenstages key to be priority:loop. added category to actions to divide into movement vs action
This commit is contained in:
@@ -9,7 +9,6 @@ public partial class Map : TileMapLayer
|
||||
public int _minX, _maxX, _minY, _maxY, _mainSource = 0;
|
||||
public string _isSolidString = "is_solid";
|
||||
public Vector2 _cellSize, _sizeInPixels, _sizeInCells;
|
||||
public Vector2I _pathTakenAtlasCoordinates = new Vector2I(4, 0);
|
||||
public List<Vector2I> _cells = new(), _leftmostColumn = new(), _rightmostColumn = new(), _topRow = new(), _bottomRow = new();
|
||||
public AStarGrid2D _astar = new();
|
||||
public Dictionary<Vector2I, Peg> _addressOccupants = new();
|
||||
|
||||
@@ -8,11 +8,6 @@ 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 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;
|
||||
public List<Vector2I> _path = new();
|
||||
public PegController _pegController;
|
||||
@@ -30,7 +25,7 @@ public partial class Peg : HoverableNode
|
||||
base._Ready();
|
||||
_actions = [.. GetNode<Node2D>("Actions").GetChildren().Cast<PegAction>()];
|
||||
}
|
||||
public virtual bool Act(int SUB_STEP)
|
||||
public virtual PegAction SelectAction()
|
||||
{
|
||||
PegAction action = null;
|
||||
for (int i = 0; i < _actions.Count; i++)
|
||||
@@ -43,17 +38,11 @@ public partial class Peg : HoverableNode
|
||||
}
|
||||
if (action == null)
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
Tween subtween = action.CreateAnimation(this);
|
||||
string key = action._priority + ":" + SUB_STEP ;
|
||||
if (!_pegController._tweenStages.ContainsKey(key))
|
||||
{
|
||||
_pegController._tweenStages[key] = new();
|
||||
}
|
||||
_pegController._tweenStages[key].Add(subtween);
|
||||
|
||||
_staminaRemaining -= action._cost;
|
||||
return true;
|
||||
return action;
|
||||
}
|
||||
|
||||
public virtual void CounterAct(Commander COMMANDER)
|
||||
|
||||
+26
-17
@@ -14,7 +14,7 @@ public partial class PegController : TurnController
|
||||
public List<PackedScene> _hostilePegScenes;
|
||||
public List<Peg> _pegs = new();
|
||||
public PlayerController _playerController;
|
||||
public Dictionary<string, List<Tween>> _tweenStages = new();
|
||||
public Dictionary<string, List<Tuple<Peg, PegAction>>> _tweenStages = new();
|
||||
public Tween _tween;
|
||||
public XmlDocument _pegProbabilities = new();
|
||||
|
||||
@@ -69,17 +69,27 @@ public partial class PegController : TurnController
|
||||
_tweenStages.Clear();
|
||||
|
||||
int loop = 0;
|
||||
bool noPegsActed = false;
|
||||
while (!noPegsActed)
|
||||
bool anyPegsActed = true;
|
||||
while (anyPegsActed)
|
||||
{
|
||||
noPegsActed = true;
|
||||
anyPegsActed = false;
|
||||
for (int i = 0; i < _pegs.Count; i++)
|
||||
{
|
||||
Peg peg = _pegs[i];
|
||||
bool pegActed = peg.Act(loop);
|
||||
if (pegActed && noPegsActed)
|
||||
PegAction action = peg.SelectAction();
|
||||
|
||||
if (action != null)
|
||||
{
|
||||
noPegsActed = false;
|
||||
string key = action._priority + ":" + loop;
|
||||
if (!_tweenStages.ContainsKey(key))
|
||||
{
|
||||
_tweenStages[key] = new();
|
||||
}
|
||||
_tweenStages[key].Add(new(peg, action));
|
||||
if (!anyPegsActed)
|
||||
{
|
||||
anyPegsActed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
loop++;
|
||||
@@ -135,37 +145,36 @@ public partial class PegController : TurnController
|
||||
|
||||
public void ProcessTween()
|
||||
{
|
||||
_tweenStages = _tweenStages.OrderBy(s => s.Key.Split(":")[0]).ThenBy(s => s.Key.Split(":")[1]).ToDictionary();
|
||||
_tweenStages = _tweenStages.OrderBy(s => int.Parse(s.Key.Split(":")[0])).ThenBy(s => int.Parse(s.Key.Split(":")[1])).ToDictionary();
|
||||
if (_tweenStages.Count <= 0)
|
||||
{
|
||||
EndTurn();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_tween != null)
|
||||
{
|
||||
_tween.Kill();
|
||||
}
|
||||
_tween?.Kill();
|
||||
|
||||
_tween = CreateTween();
|
||||
|
||||
for (int i = 0; i < _tweenStages.Count; i++)
|
||||
{
|
||||
_tween.Chain().TweenInterval(0.5f);
|
||||
List<Tween> tweenSteps = _tweenStages.Values.ElementAt(i);
|
||||
List<Tuple<Peg, PegAction>> tweenSteps = _tweenStages.Values.ElementAt(i);
|
||||
for (int j = 0; j < tweenSteps.Count; j++)
|
||||
{
|
||||
Tween step = tweenSteps[j];
|
||||
_tween.Parallel().TweenSubtween(step);
|
||||
Tuple<Peg, PegAction> step = tweenSteps[j];
|
||||
Peg peg = step.Item1;
|
||||
PegAction action = step.Item2;
|
||||
Tween tween = action.CreateAnimation(peg);
|
||||
_tween.Parallel().TweenSubtween(tween);
|
||||
}
|
||||
}
|
||||
_tween.TweenCallback(Callable.From(EndTurn));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void StartTurn()
|
||||
{
|
||||
|
||||
AddHostilePegs(4);
|
||||
|
||||
for (int i = 0; i < _pegs.Count; i++)
|
||||
|
||||
@@ -7,6 +7,7 @@ public partial class BasicMovement : PegAction
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_category = "movement";
|
||||
_priority = 0;
|
||||
_healthChange = 0;
|
||||
_cost = 1;
|
||||
|
||||
@@ -7,6 +7,7 @@ public partial class Shortbow : PegAction
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_category = "attack";
|
||||
_priority = 1;
|
||||
_healthChange = -1;
|
||||
_cost = 2;
|
||||
|
||||
@@ -7,6 +7,7 @@ public partial class Shortsword : PegAction
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_category = "attack";
|
||||
_priority = 1;
|
||||
_healthChange = -2;
|
||||
_cost = 2;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
|
||||
public partial class PegAction : Node2D
|
||||
{
|
||||
public string _category;
|
||||
public int _priority, _healthChange, _cost, _range, _usesMax, _usesRemaining, _triggers = 0;
|
||||
public Sprite2D _image;
|
||||
|
||||
|
||||
@@ -8,12 +8,10 @@ public partial class PlayArea : Node2D
|
||||
public Node2D _leftEdge, _rightEdge;
|
||||
public Area2D _region;
|
||||
public Map _map;
|
||||
public Bucket _bucket;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_bucket = GetNode<Bucket>("Bucket");
|
||||
_region = GetNode<Area2D>("Region");
|
||||
|
||||
_leftEdge = GetNode<Node2D>("LeftEdge");
|
||||
@@ -29,7 +27,6 @@ public partial class PlayArea : Node2D
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
base._Process(delta);
|
||||
_bucket.Move();
|
||||
}
|
||||
|
||||
public void HighlightCells()
|
||||
|
||||
@@ -13,13 +13,22 @@ public partial class PlayerController : TurnController
|
||||
public PegController _pegController;
|
||||
public PackedScene _commanderScene = GD.Load<PackedScene>("res://Commander.tscn");
|
||||
public List<Tower> _towers = new();
|
||||
public Bucket _bucket;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_health = _healthMax;
|
||||
base._Ready();
|
||||
_bucket = GetNode<Bucket>("Bucket");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
base._Process(delta);
|
||||
_bucket.Move();
|
||||
}
|
||||
|
||||
|
||||
public void ChangeHealth(int DAMAGE, Node IMPETUS = null)
|
||||
{
|
||||
_health += DAMAGE;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://cg1m762ed04kv" path="res://Main.cs" id="1_ig7tw"]
|
||||
[ext_resource type="PackedScene" uid="uid://dumcridek4xy3" path="res://play_area.tscn" id="2_1bvp3"]
|
||||
[ext_resource type="PackedScene" path="res://peg_controller.tscn" id="3_lquwl"]
|
||||
[ext_resource type="PackedScene" uid="uid://bxlt2ap0dym1x" path="res://peg_controller.tscn" id="3_lquwl"]
|
||||
[ext_resource type="PackedScene" uid="uid://b7kvx7p0b2086" path="res://player_controller.tscn" id="4_lquwl"]
|
||||
[ext_resource type="PackedScene" path="res://mouse_handler.tscn" id="5_lquwl"]
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,8 +2,12 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://cfohujgs5dygx" path="res://PlayerController.cs" id="1_lvefo"]
|
||||
[ext_resource type="PackedScene" uid="uid://d06n7p75u130s" path="res://tower.tscn" id="2_f0yg5"]
|
||||
[ext_resource type="PackedScene" uid="uid://b2mb7mimdu5ad" path="res://bucket.tscn" id="3_va7e3"]
|
||||
|
||||
[node name="PlayerController" type="Node2D" unique_id=317732890]
|
||||
script = ExtResource("1_lvefo")
|
||||
|
||||
[node name="Tower1" parent="." unique_id=1315831332 instance=ExtResource("2_f0yg5")]
|
||||
|
||||
[node name="Bucket" parent="." unique_id=1168722558 instance=ExtResource("3_va7e3")]
|
||||
position = Vector2(960, 1040)
|
||||
|
||||
Reference in New Issue
Block a user