summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project.godot5
-rw-r--r--scenes/character.tscn5
-rw-r--r--scenes/skeleton.tscn2
-rw-r--r--scenes/test_map.tscn21
-rw-r--r--scenes/turn_manager.tscn6
-rw-r--r--scripts/Actor.cs19
-rw-r--r--scripts/Character.cs50
-rw-r--r--scripts/DungeonLevel.cs18
-rw-r--r--scripts/DungeonLevel.cs.uid1
-rw-r--r--scripts/Enemy.cs6
-rw-r--r--scripts/TurnManager.cs61
-rw-r--r--scripts/TurnManager.cs.uid1
12 files changed, 168 insertions, 27 deletions
diff --git a/project.godot b/project.godot
index bace009..0e7d507 100644
--- a/project.godot
+++ b/project.godot
@@ -41,6 +41,11 @@ walk-right={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
+skip-turn={
+"deadzone": 0.2,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":46,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
+]
+}
[rendering]
diff --git a/scenes/character.tscn b/scenes/character.tscn
index 825f5bf..4b23758 100644
--- a/scenes/character.tscn
+++ b/scenes/character.tscn
@@ -3,7 +3,10 @@
[ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/character.png" id="1_agfs1"]
[ext_resource type="Script" uid="uid://c840l08453pu2" path="res://scripts/Character.cs" id="2_rkhd4"]
-[node name="Character" type="Sprite2D"]
+[node name="Character" type="Sprite2D" groups=["TimeSlave"]]
texture_filter = 1
texture = ExtResource("1_agfs1")
script = ExtResource("2_rkhd4")
+
+[node name="Camera2D" type="Camera2D" parent="."]
+zoom = Vector2(4, 4)
diff --git a/scenes/skeleton.tscn b/scenes/skeleton.tscn
index 8471909..1dc7727 100644
--- a/scenes/skeleton.tscn
+++ b/scenes/skeleton.tscn
@@ -3,6 +3,6 @@
[ext_resource type="Texture2D" uid="uid://dh5sgjdwkps88" path="res://assets/sprites/skeleton.png" id="1_pbvs3"]
[ext_resource type="Script" uid="uid://bef1fo3vgvxej" path="res://scripts/Enemy.cs" id="2_txkty"]
-[node name="Skeleton" type="Sprite2D"]
+[node name="Skeleton" type="Sprite2D" groups=["TimeSlave"]]
texture = ExtResource("1_pbvs3")
script = ExtResource("2_txkty")
diff --git a/scenes/test_map.tscn b/scenes/test_map.tscn
index 446e6d7..a5c4039 100644
--- a/scenes/test_map.tscn
+++ b/scenes/test_map.tscn
@@ -1,24 +1,29 @@
-[gd_scene load_steps=4 format=4 uid="uid://u5h6iqyi8wd0"]
+[gd_scene load_steps=6 format=4 uid="uid://u5h6iqyi8wd0"]
[ext_resource type="TileSet" uid="uid://biilh0ufacguh" path="res://assets/test_tileset.tres" id="1_57l66"]
+[ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/DungeonLevel.cs" id="1_p21b5"]
[ext_resource type="PackedScene" uid="uid://bl01llfbscv6r" path="res://scenes/character.tscn" id="2_fn2sa"]
[ext_resource type="PackedScene" uid="uid://bsn4a4tfensy8" path="res://scenes/skeleton.tscn" id="3_57l66"]
+[ext_resource type="PackedScene" uid="uid://ie3vpgatjvkw" path="res://scenes/turn_manager.tscn" id="4_p21b5"]
-[node name="Node2D" type="Node2D"]
+[node name="DungeonLevel" type="Node2D"]
+script = ExtResource("1_p21b5")
[node name="Map" type="TileMapLayer" parent="."]
texture_filter = 1
tile_map_data = PackedByteArray("AAAHAAcAAAAAAAAAAAAIAAcAAAAAAAAAAAAJAAcAAAAAAAAAAAAKAAcAAAAAAAAAAAALAAcAAAAAAAAAAAAMAAcAAAAAAAAAAAANAAcAAAAAAAAAAAAOAAcAAAAAAAAAAAAOAA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AAABAAAAAAAUAAMAAAABAAAAAAATAAMAAAABAAAAAAASAAMAAAABAAAAAAARAAMAAAABAAAAAAAQAAMAAAABAAAAAAAPAAMAAAABAAAAAAAPAAQAAAABAAAAAAAPAAUAAAABAAAAAAAQAAkAAAAAAAAAAAARAAkAAAAAAAAAAAARAAgAAAAAAAAAAAASAAgAAAAAAAAAAAATAAgAAAAAAAAAAAAUAAkAAAAAAAAAAAATAAkAAAAAAAAAAAARAAcAAAAAAAAAAAAQAAcAAAAAAAAAAAAQAAYAAAAAAAAAAAAQAAUAAAAAAAAAAAARAAUAAAAAAAAAAAARAAQAAAAAAAAAAAASAAQAAAAAAAAAAAATAAQAAAAAAAAAAAAUAAQAAAAAAAAAAAAUAAUAAAAAAAAAAAAVAAUAAAAAAAAAAAAVAAYAAAAAAAAAAAAVAAcAAAAAAAAAAAAVAAgAAAAAAAAAAAAVAAkAAAAAAAAAAAASAAcAAAAAAAAAAAASAAYAAAAAAAAAAAASAAUAAAAAAAAAAAATAAUAAAAAAAAAAAAUAAYAAAAAAAAAAAAUAAcAAAAAAAAAAAAUAAgAAAAAAAAAAAATAAcAAAAAAAAAAAATAAYAAAAAAAAAAAAQAAQAAAAAAAAAAAAQAAgAAAAAAAAAAAARAAYAAAAAAAAAAAASAAkAAAAAAAAAAAAWAAkAAAAAAAAAAAAWAAgAAAAAAAAAAAAWAAcAAAAAAAAAAAAWAAYAAAAAAAAAAAAWAAUAAAAAAAAAAAAWAAQAAAAAAAAAAAAVAAQAAAAAAAAAAAA=")
tile_set = ExtResource("1_57l66")
-[node name="Camera2D" type="Camera2D" parent="."]
-anchor_mode = 0
-zoom = Vector2(2, 2)
+[node name="Skeleton" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("3_57l66")]
+position = Vector2(120, 121)
+Map = NodePath("../Map")
[node name="Character" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("2_fn2sa")]
position = Vector2(135, 135)
Map = NodePath("../Map")
-[node name="Skeleon" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("3_57l66")]
-position = Vector2(184, 136)
-Map = NodePath("../Map")
+[node name="TurnManager" parent="." instance=ExtResource("4_p21b5")]
+
+[connection signal="actionPerformed" from="Skeleton" to="TurnManager" method="OnActionEnd"]
+[connection signal="actionPerformed" from="Character" to="TurnManager" method="OnActionEnd"]
+[connection signal="turnEnd" from="TurnManager" to="." method="OnTurnEnd"]
diff --git a/scenes/turn_manager.tscn b/scenes/turn_manager.tscn
new file mode 100644
index 0000000..4a1cf5c
--- /dev/null
+++ b/scenes/turn_manager.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=3 uid="uid://ie3vpgatjvkw"]
+
+[ext_resource type="Script" uid="uid://ynjn2pmluvf6" path="res://scripts/TurnManager.cs" id="1_3c2a3"]
+
+[node name="TurnManager" type="Node"]
+script = ExtResource("1_3c2a3")
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