diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Actor.cs | 19 | ||||
| -rw-r--r-- | scripts/Character.cs | 50 | ||||
| -rw-r--r-- | scripts/DungeonLevel.cs | 18 | ||||
| -rw-r--r-- | scripts/DungeonLevel.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/Enemy.cs | 6 | ||||
| -rw-r--r-- | scripts/TurnManager.cs | 61 | ||||
| -rw-r--r-- | scripts/TurnManager.cs.uid | 1 |
7 files changed, 139 insertions, 17 deletions
diff --git a/scripts/Actor.cs b/scripts/Actor.cs index fc69edf..b360545 100644 --- a/scripts/Actor.cs +++ b/scripts/Actor.cs @@ -1,8 +1,16 @@ using Godot; -public partial class Actor : Node2D { +public abstract partial class Actor : Node2D { + static int baseWalkCost = 10; [Export] public TileMapLayer Map { get; set; } + [Signal] + public delegate void actionPerformedEventHandler(); + + [Export] + public int Energy { get; set; } = 0; + [Export] + public int Speed { get; protected set; } = 10; protected void Walk(Vector2I offset) { Vector2I toMovePos = Map.LocalToMap(Position); @@ -14,5 +22,14 @@ public partial class Actor : Node2D { GD.Print(toMovePos); Position = Map.MapToLocal(toMovePos); } + + Energy -= baseWalkCost; + EndAction(); } + + protected virtual void EndAction() { + EmitSignal(SignalName.actionPerformed); + } + + public abstract void performAction(); }
\ No newline at end of file diff --git a/scripts/Character.cs b/scripts/Character.cs index e3707f5..172ffe4 100644 --- a/scripts/Character.cs +++ b/scripts/Character.cs @@ -2,6 +2,7 @@ using Godot; using System; public partial class Character : Actor { + private bool canAct = false; public override void _Input(InputEvent @event) { @@ -9,23 +10,42 @@ public partial class Character : Actor { if (!@event.IsPressed()) return; - Vector2I offset = Vector2I.Zero; + if (canAct) { + - if (@event.IsActionPressed("walk-up")) { - offset += Vector2I.Up; - } - if (@event.IsActionPressed("walk-down")) { - offset += Vector2I.Down; - } - if (@event.IsActionPressed("walk-left")) { - offset += Vector2I.Left; - } - if (@event.IsActionPressed("walk-right")) { - offset += Vector2I.Right; - } + if (@event.IsActionPressed("walk-up")) { + Walk(Vector2I.Up); + } + if (@event.IsActionPressed("walk-down")) { + Walk(Vector2I.Down); + } + if (@event.IsActionPressed("walk-left")) { + Walk(Vector2I.Left); + } + if (@event.IsActionPressed("walk-right")) { + GD.Print("Hello!"); + Walk(Vector2I.Right); + } - if (offset != Vector2I.Zero) { - Walk(offset); + if (@event.IsActionPressed("skip-turn")) { + SkipTurn(); + } } } + + private void SkipTurn() { + GD.Print("Skipped the turn."); + Energy = 0; + EndAction(); + } + + protected override void EndAction() { + canAct = false; + base.EndAction(); + } + + public override void performAction() { + GD.Print("I can act"); + canAct = true; + } } diff --git a/scripts/DungeonLevel.cs b/scripts/DungeonLevel.cs new file mode 100644 index 0000000..c3536ac --- /dev/null +++ b/scripts/DungeonLevel.cs @@ -0,0 +1,18 @@ +using Godot; +using System; + +public partial class DungeonLevel : Node2D { + TurnManager turnManager; + + public override void _Ready() { + base._Ready(); + + turnManager = GetNode<TurnManager>("TurnManager"); + + turnManager.Tick(); + } + + public void OnTurnEnd() { + turnManager.Tick(); + } +} diff --git a/scripts/DungeonLevel.cs.uid b/scripts/DungeonLevel.cs.uid new file mode 100644 index 0000000..5c3c2a2 --- /dev/null +++ b/scripts/DungeonLevel.cs.uid @@ -0,0 +1 @@ +uid://dwubb28wt4bhe diff --git a/scripts/Enemy.cs b/scripts/Enemy.cs index 6f48bd1..52eb27f 100644 --- a/scripts/Enemy.cs +++ b/scripts/Enemy.cs @@ -2,5 +2,9 @@ using Godot; using System; public partial class Enemy : Actor { - + public override void performAction() { + Walk(Vector2I.Right); + + GD.Print("Energy after walking: " + Energy); + } } diff --git a/scripts/TurnManager.cs b/scripts/TurnManager.cs new file mode 100644 index 0000000..ffb2659 --- /dev/null +++ b/scripts/TurnManager.cs @@ -0,0 +1,61 @@ +using Godot; +using System; +using System.Collections.Generic; +using System.Reflection.Metadata.Ecma335; + +public partial class TurnManager : Node { + [Signal] + public delegate void turnBeginEventHandler(); + [Signal] + public delegate void turnEndEventHandler(); + + private Godot.Collections.Array<Node> actors = []; + private int index = 0; + + public int TurnCount { get; private set; } = 1; + + public void Tick() { + EmitSignal(SignalName.turnBegin); + + GD.Print("Turn: " + TurnCount); + + actors.Clear(); + actors = GetTree().GetNodesInGroup("TimeSlave"); + + GD.Print("Actor count: " + actors.Count); + + index = -1; + NextActor(); + } + + private void NextActor() { + index++; + GD.Print("Index: " + index); + if (index >= actors.Count) { + EndTurn(); + return; + } + Actor currentActor = (Actor) actors[index]; + currentActor.Energy += currentActor.Speed; + ActorPerformAction(); + } + + private void ActorPerformAction() { + Actor currentActor = (Actor) actors[index]; + if (currentActor.Energy > 0) { + currentActor.performAction(); + } else { + NextActor(); + } + } + + public void OnActionEnd() { + ActorPerformAction(); + } + + private void EndTurn() { + GD.Print("Turn End"); + TurnCount++; + EmitSignal(SignalName.turnEnd); + } +} diff --git a/scripts/TurnManager.cs.uid b/scripts/TurnManager.cs.uid new file mode 100644 index 0000000..a306f3e --- /dev/null +++ b/scripts/TurnManager.cs.uid @@ -0,0 +1 @@ +uid://ynjn2pmluvf6 |
