diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Actor.cs | 35 | ||||
| -rw-r--r-- | scripts/Actor.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/Character.cs | 51 | ||||
| -rw-r--r-- | scripts/Character.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/DungeonLevel.cs | 18 | ||||
| -rw-r--r-- | scripts/DungeonLevel.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/Enemy.cs | 10 | ||||
| -rw-r--r-- | scripts/Enemy.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/TurnManager.cs | 61 | ||||
| -rw-r--r-- | scripts/TurnManager.cs.uid | 1 |
10 files changed, 180 insertions, 0 deletions
diff --git a/scripts/Actor.cs b/scripts/Actor.cs new file mode 100644 index 0000000..b360545 --- /dev/null +++ b/scripts/Actor.cs @@ -0,0 +1,35 @@ +using Godot; + +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); + toMovePos += offset; + + TileData tile = Map.GetCellTileData(toMovePos); + + if (tile.HasCustomData("isWalkable") && (bool) tile.GetCustomData("isWalkable")) { + 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/Actor.cs.uid b/scripts/Actor.cs.uid new file mode 100644 index 0000000..cf29b40 --- /dev/null +++ b/scripts/Actor.cs.uid @@ -0,0 +1 @@ +uid://c0cm4woy8lawl diff --git a/scripts/Character.cs b/scripts/Character.cs new file mode 100644 index 0000000..172ffe4 --- /dev/null +++ b/scripts/Character.cs @@ -0,0 +1,51 @@ +using Godot; +using System; + +public partial class Character : Actor { + private bool canAct = false; + + public override void _Input(InputEvent @event) + { + base._Input(@event); + + if (!@event.IsPressed()) return; + + if (canAct) { + + + 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 (@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/Character.cs.uid b/scripts/Character.cs.uid new file mode 100644 index 0000000..8229b7f --- /dev/null +++ b/scripts/Character.cs.uid @@ -0,0 +1 @@ +uid://c840l08453pu2 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 new file mode 100644 index 0000000..52eb27f --- /dev/null +++ b/scripts/Enemy.cs @@ -0,0 +1,10 @@ +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/Enemy.cs.uid b/scripts/Enemy.cs.uid new file mode 100644 index 0000000..93255b7 --- /dev/null +++ b/scripts/Enemy.cs.uid @@ -0,0 +1 @@ +uid://bef1fo3vgvxej 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 |
