summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-08-17 19:32:36 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-08-17 19:32:36 -0300
commitca782d7310f2df854a8727535ac92337c85ed445 (patch)
tree7df571c01d48cac56fb8362d4d091bdd2a55c09a
parentadb86dd1725276457c13e9a4d37372fda628dea3 (diff)
Gigantesco refactor
-rw-r--r--scenes/DungeonLevel.tscn18
-rw-r--r--scenes/Game.tscn13
-rw-r--r--scenes/Player.tscn13
-rw-r--r--scenes/character.tscn12
-rw-r--r--scenes/skeleton.tscn8
-rw-r--r--scenes/test_map.tscn29
-rw-r--r--scenes/turn_manager.tscn60
-rw-r--r--scripts/Actor.cs36
-rw-r--r--scripts/Character.cs48
-rw-r--r--scripts/DungeonLevel.cs21
-rw-r--r--scripts/DungeonLevel.cs.uid2
-rw-r--r--scripts/Enemy.cs7
-rw-r--r--scripts/Game.cs28
-rw-r--r--scripts/Game.cs.uid1
-rw-r--r--scripts/InputHandler.cs22
-rw-r--r--scripts/InputHandler.cs.uid1
-rw-r--r--scripts/TurnManager.cs55
-rw-r--r--scripts/TurnManager.cs.uid1
-rw-r--r--scripts/Utils/Grid.cs14
-rw-r--r--scripts/Utils/Grid.cs.uid1
-rw-r--r--scripts/actors/Actor.cs23
-rw-r--r--scripts/actors/Actor.cs.uid (renamed from scripts/Actor.cs.uid)0
-rw-r--r--scripts/actors/Player.cs8
-rw-r--r--scripts/actors/Player.cs.uid (renamed from scripts/Character.cs.uid)0
-rw-r--r--scripts/actors/actions/Action.cs6
-rw-r--r--scripts/actors/actions/Action.cs.uid1
-rw-r--r--scripts/actors/actions/MovementAction.cs22
-rw-r--r--scripts/actors/actions/MovementAction.cs.uid1
28 files changed, 245 insertions, 206 deletions
diff --git a/scenes/DungeonLevel.tscn b/scenes/DungeonLevel.tscn
new file mode 100644
index 0000000..f9d98fd
--- /dev/null
+++ b/scenes/DungeonLevel.tscn
@@ -0,0 +1,18 @@
+[gd_scene load_steps=4 format=4 uid="uid://dnh8xgk1w76i2"]
+
+[ext_resource type="TileSet" uid="uid://biilh0ufacguh" path="res://assets/test_tileset.tres" id="1_bxfih"]
+[ext_resource type="Script" uid="uid://cy7qumrpks2kx" path="res://scripts/DungeonLevel.cs" id="1_u6mlv"]
+[ext_resource type="PackedScene" uid="uid://7sfxgul40ths" path="res://scenes/Player.tscn" id="2_u6mlv"]
+
+[node name="Map" type="Node2D"]
+script = ExtResource("1_u6mlv")
+
+[node name="Dungeon" type="TileMapLayer" parent="."]
+texture_filter = 1
+tile_map_data = PackedByteArray("AAAHAAcAAAAAAAAAAAAIAAcAAAAAAAAAAAAJAAcAAAAAAAAAAAAKAAcAAAAAAAAAAAALAAcAAAAAAAAAAAAMAAcAAAAAAAAAAAANAAcAAAAAAAAAAAAOAAcAAAAAAAAAAAAOAAgAAAAAAAAAAAANAAgAAAAAAAAAAAAMAAgAAAAAAAAAAAALAAgAAAAAAAAAAAAKAAgAAAAAAAAAAAAJAAgAAAAAAAAAAAAIAAgAAAAAAAAAAAAHAAgAAAAAAAAAAAAHAAkAAAAAAAAAAAAIAAkAAAAAAAAAAAAKAAkAAAAAAAAAAAALAAkAAAAAAAAAAAAMAAkAAAAAAAAAAAANAAkAAAAAAAAAAAAOAAkAAAAAAAAAAAAJAAkAAAAAAAAAAAAGAAYAAAABAAAAAAAGAAcAAAABAAAAAAAGAAgAAAAAAAAAAAAGAAkAAAABAAAAAAAGAAoAAAABAAAAAAAHAAoAAAABAAAAAAAIAAoAAAABAAAAAAAJAAoAAAABAAAAAAANAAoAAAABAAAAAAAOAAoAAAABAAAAAAAPAAoAAAABAAAAAAAPAAkAAAABAAAAAAAPAAgAAAABAAAAAAAPAAcAAAABAAAAAAAPAAYAAAABAAAAAAAOAAYAAAABAAAAAAANAAYAAAABAAAAAAAMAAYAAAABAAAAAAALAAYAAAABAAAAAAAKAAYAAAABAAAAAAAJAAYAAAABAAAAAAAIAAYAAAABAA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AAAAAAAAAAAQAAQAAAAAAAAAAAAQAAgAAAAAAAAAAAARAAYAAAABAAAAAAASAAkAAAAAAAAAAAAWAAkAAAAAAAAAAAAWAAgAAAAAAAAAAAAWAAcAAAAAAAAAAAAWAAYAAAAAAAAAAAAWAAUAAAAAAAAAAAAWAAQAAAAAAAAAAAAVAAQAAAAAAAAAAAAKAAoAAAAAAAAAAAAJAAsAAAABAAAAAAA=")
+tile_set = ExtResource("1_bxfih")
+
+[node name="Actors" type="Node2D" parent="."]
+
+[node name="Player" parent="Actors" instance=ExtResource("2_u6mlv")]
+position = Vector2(144, 144)
diff --git a/scenes/Game.tscn b/scenes/Game.tscn
new file mode 100644
index 0000000..6d1a2be
--- /dev/null
+++ b/scenes/Game.tscn
@@ -0,0 +1,13 @@
+[gd_scene load_steps=4 format=3 uid="uid://u5h6iqyi8wd0"]
+
+[ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/Game.cs" id="1_cpr0p"]
+[ext_resource type="PackedScene" uid="uid://dnh8xgk1w76i2" path="res://scenes/DungeonLevel.tscn" id="2_cpr0p"]
+[ext_resource type="Script" uid="uid://ejqmdbc0524i" path="res://scripts/InputHandler.cs" id="3_s0nni"]
+
+[node name="Game" type="Node"]
+script = ExtResource("1_cpr0p")
+
+[node name="Map" parent="." instance=ExtResource("2_cpr0p")]
+
+[node name="InputHandler" type="Node" parent="."]
+script = ExtResource("3_s0nni")
diff --git a/scenes/Player.tscn b/scenes/Player.tscn
new file mode 100644
index 0000000..bd40178
--- /dev/null
+++ b/scenes/Player.tscn
@@ -0,0 +1,13 @@
+[gd_scene load_steps=3 format=3 uid="uid://7sfxgul40ths"]
+
+[ext_resource type="Script" uid="uid://c840l08453pu2" path="res://scripts/actors/Player.cs" id="1_p0vlq"]
+[ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/character.png" id="1_v6fml"]
+
+[node name="Player" type="Sprite2D"]
+texture = ExtResource("1_v6fml")
+centered = false
+script = ExtResource("1_p0vlq")
+
+[node name="Camera2D" type="Camera2D" parent="."]
+offset = Vector2(8, 8)
+zoom = Vector2(2, 2)
diff --git a/scenes/character.tscn b/scenes/character.tscn
deleted file mode 100644
index 4b23758..0000000
--- a/scenes/character.tscn
+++ /dev/null
@@ -1,12 +0,0 @@
-[gd_scene load_steps=3 format=3 uid="uid://bl01llfbscv6r"]
-
-[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" 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
deleted file mode 100644
index 1dc7727..0000000
--- a/scenes/skeleton.tscn
+++ /dev/null
@@ -1,8 +0,0 @@
-[gd_scene load_steps=3 format=3 uid="uid://bsn4a4tfensy8"]
-
-[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" groups=["TimeSlave"]]
-texture = ExtResource("1_pbvs3")
-script = ExtResource("2_txkty")
diff --git a/scenes/test_map.tscn b/scenes/test_map.tscn
deleted file mode 100644
index c7be4df..0000000
--- a/scenes/test_map.tscn
+++ /dev/null
@@ -1,29 +0,0 @@
-[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="DungeonLevel" type="Node2D"]
-script = ExtResource("1_p21b5")
-
-[node name="Map" type="TileMapLayer" parent="."]
-texture_filter = 1
-tile_map_data = PackedByteArray("AAAHAAcAAAAAAAAAAAAIAAcAAAAAAAAAAAAJAAcAAAAAAAAAAAAKAAcAAAAAAAAAAAALAAcAAAAAAAAAAAAMAAcAAAAAAAAAAAANAAcAAAAAAAAAAAAOAAcAAAAAAAAAAAAOAAgAAAAAAAAAAAANAAgAAAAAAAAAAAAMAAgAAAAAAAAAAAALAAgAAAAAAAAAAAAKAAgAAAAAAAAAAAAJAAgAAAAAAAAAAAAIAAgAAAAAAAAAAAAHAAgAAAAAAAAAAAAHAAkAAAAAAAAAAAAIAAkAAAAAAAAAAAAKAAkAAAAAAAAAAAALAAkAAAAAAAAAAAAMAAkAAAAAAAAAAAANAAkAAAAAAAAAAAAOAAkAAAAAAAAAAAAJAAkAAAAAAAAAAAAGAAYAAAABAAAAAAAGAAcAAAABAAAAAAAGAAgAAAAAAAAAAAAGAAkAAAABAAAAAAAGAAoAAAABAAAAAAAHAAoAAAABAAAAAAAIAAoAAAABAAAAAAAJAAoAAAABAAAAAAANAAoAAAABAAAAAAAOAAoAAAABAAAAAAAPAAoAAAABAAAAAAAPAAkAAAABAAAAAAAPAAgAAAABAAAAAAAPAAcAAAABAAAAAAAPAAYAAAABAAAAAAAOAAYAAAABAAAAAAANAAYAAAABAAAAAAAMAAYAAAABAAAAAAALAAYAAAABAAAAAAAKAAYAAAABAAAAAAAJAAYAAAABAAAAAAAIAAYAAAABAAAAAAAHAAYAAAABAAAAAAAMAAoAAAABAAAAAAALAAoAAAAAAAAAAAAKAAoAAAABAAAAAAAFA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AAYAAAAAAAAAAAASAAkAAAAAAAAAAAAWAAkAAAAAAAAAAAAWAAgAAAAAAAAAAAAWAAcAAAAAAAAAAAAWAAYAAAAAAAAAAAAWAAUAAAAAAAAAAAAWAAQAAAAAAAAAAAAVAAQAAAAAAAAAAAA=")
-tile_set = ExtResource("1_57l66")
-
-[node name="Character" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("2_fn2sa")]
-position = Vector2(135, 135)
-Map = NodePath("../Map")
-
-[node name="Skeleton" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("3_57l66")]
-position = Vector2(120, 121)
-Map = NodePath("../Map")
-
-[node name="TurnManager" parent="." instance=ExtResource("4_p21b5")]
-
-[connection signal="actionPerformed" from="Character" to="TurnManager" method="OnActionEnd"]
-[connection signal="actionPerformed" from="Skeleton" to="TurnManager" method="OnActionEnd"]
-[connection signal="turnEnd" from="TurnManager" to="." method="OnTurnEnd"]
diff --git a/scenes/turn_manager.tscn b/scenes/turn_manager.tscn
index 4a1cf5c..9e9a4f7 100644
--- a/scenes/turn_manager.tscn
+++ b/scenes/turn_manager.tscn
@@ -1,6 +1,62 @@
[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"]
+[sub_resource type="CSharpScript" id="CSharpScript_4jeo4"]
+script/source = "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);
+
+ actors.Clear();
+ actors = GetTree().GetNodesInGroup(\"TimeSlave\");
+
+ index = -1;
+ NextActor();
+ }
+
+ private void NextActor() {
+ 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() {
+ TurnCount++;
+ EmitSignal(SignalName.turnEnd);
+ }
+}
+"
[node name="TurnManager" type="Node"]
-script = ExtResource("1_3c2a3")
+script = SubResource("CSharpScript_4jeo4")
diff --git a/scripts/Actor.cs b/scripts/Actor.cs
deleted file mode 100644
index d196940..0000000
--- a/scripts/Actor.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-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 != null) {
- if ((bool) tile.GetCustomData("isWalkable")) {
- 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
deleted file mode 100644
index 1db6ee1..0000000
--- a/scripts/Character.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-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")) {
- Walk(Vector2I.Right);
- }
-
- if (@event.IsActionPressed("skip-turn")) {
- SkipTurn();
- }
- }
- }
-
- private void SkipTurn() {
- Energy = 0;
- EndAction();
- }
-
- protected override void EndAction() {
- canAct = false;
- base.EndAction();
- }
-
- public override void PerformAction() {
- canAct = true;
- }
-}
diff --git a/scripts/DungeonLevel.cs b/scripts/DungeonLevel.cs
index c3536ac..a303254 100644
--- a/scripts/DungeonLevel.cs
+++ b/scripts/DungeonLevel.cs
@@ -1,18 +1,19 @@
using Godot;
using System;
-public partial class DungeonLevel : Node2D {
- TurnManager turnManager;
+public partial class DungeonLevel : Node2D
+{
+ public Player player;
+ public TileMapLayer buildingLayer;
- public override void _Ready() {
- base._Ready();
-
- turnManager = GetNode<TurnManager>("TurnManager");
+ private Node2D actors;
- turnManager.Tick();
- }
+ public override void _Ready()
+ {
+ base._Ready();
- public void OnTurnEnd() {
- turnManager.Tick();
+ buildingLayer = GetNode<TileMapLayer>("Dungeon");
+ actors = GetNode<Node2D>("Actors");
+ player = actors.GetNode<Player>("Player");
}
}
diff --git a/scripts/DungeonLevel.cs.uid b/scripts/DungeonLevel.cs.uid
index 5c3c2a2..a63fd2e 100644
--- a/scripts/DungeonLevel.cs.uid
+++ b/scripts/DungeonLevel.cs.uid
@@ -1 +1 @@
-uid://dwubb28wt4bhe
+uid://cy7qumrpks2kx
diff --git a/scripts/Enemy.cs b/scripts/Enemy.cs
index 473ba0f..29a85b7 100644
--- a/scripts/Enemy.cs
+++ b/scripts/Enemy.cs
@@ -1,8 +1,7 @@
using Godot;
using System;
-public partial class Enemy : Actor {
- public override void PerformAction() {
- Walk(Vector2I.Right);
- }
+public partial class Enemy : Actor
+{
+
}
diff --git a/scripts/Game.cs b/scripts/Game.cs
new file mode 100644
index 0000000..8de7af6
--- /dev/null
+++ b/scripts/Game.cs
@@ -0,0 +1,28 @@
+using Godot;
+using System;
+
+public partial class Game : Node {
+ private Player player;
+ public TileMapLayer Dungeon { get; private set; }
+ private DungeonLevel map;
+ private InputHandler inputHandler;
+
+ public override void _Ready() {
+ base._Ready();
+
+ map = GetNode<DungeonLevel>("Map");
+
+ inputHandler = GetNode<InputHandler>("InputHandler");
+ Dungeon = map.buildingLayer;
+
+ player = map.player;
+ }
+
+ public override void _PhysicsProcess(double delta) {
+ base._PhysicsProcess(delta);
+
+ Action action = inputHandler.GetAction();
+
+ action?.Perform(this, player);
+ }
+}
diff --git a/scripts/Game.cs.uid b/scripts/Game.cs.uid
new file mode 100644
index 0000000..5c3c2a2
--- /dev/null
+++ b/scripts/Game.cs.uid
@@ -0,0 +1 @@
+uid://dwubb28wt4bhe
diff --git a/scripts/InputHandler.cs b/scripts/InputHandler.cs
new file mode 100644
index 0000000..dae990a
--- /dev/null
+++ b/scripts/InputHandler.cs
@@ -0,0 +1,22 @@
+using Godot;
+using System;
+
+public partial class InputHandler : Node {
+ public Action GetAction() {
+ Action action = null;
+
+ if (Input.IsActionJustPressed("walk-up")) {
+ action = new MovementAction(Vector2I.Up);
+ } else if (Input.IsActionJustPressed("walk-down")) {
+ action = new MovementAction(Vector2I.Down);
+ } else if (Input.IsActionJustPressed("walk-left")) {
+ action = new MovementAction(Vector2I.Left);
+ } else if (Input.IsActionJustPressed("walk-right")) {
+ action = new MovementAction(Vector2I.Right);
+ } else if (Input.IsActionJustPressed("skip-turn")) {
+ action = new MovementAction(Vector2I.Zero);
+ }
+
+ return action;
+ }
+}
diff --git a/scripts/InputHandler.cs.uid b/scripts/InputHandler.cs.uid
new file mode 100644
index 0000000..302a3b5
--- /dev/null
+++ b/scripts/InputHandler.cs.uid
@@ -0,0 +1 @@
+uid://ejqmdbc0524i
diff --git a/scripts/TurnManager.cs b/scripts/TurnManager.cs
deleted file mode 100644
index ea9050e..0000000
--- a/scripts/TurnManager.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-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);
-
- actors.Clear();
- actors = GetTree().GetNodesInGroup("TimeSlave");
-
- index = -1;
- NextActor();
- }
-
- private void NextActor() {
- 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() {
- TurnCount++;
- EmitSignal(SignalName.turnEnd);
- }
-}
diff --git a/scripts/TurnManager.cs.uid b/scripts/TurnManager.cs.uid
deleted file mode 100644
index a306f3e..0000000
--- a/scripts/TurnManager.cs.uid
+++ /dev/null
@@ -1 +0,0 @@
-uid://ynjn2pmluvf6
diff --git a/scripts/Utils/Grid.cs b/scripts/Utils/Grid.cs
new file mode 100644
index 0000000..bf5d98f
--- /dev/null
+++ b/scripts/Utils/Grid.cs
@@ -0,0 +1,14 @@
+using Godot;
+using System;
+
+public partial class Grid : GodotObject {
+ public static readonly Vector2I tileSize = new(16, 16);
+
+ public static Vector2I WorldToGrid(Vector2 coord) {
+ return (Vector2I)(coord / tileSize);
+ }
+
+ public static Vector2 GridToWorld(Vector2I coord) {
+ return coord * tileSize;
+ }
+}
diff --git a/scripts/Utils/Grid.cs.uid b/scripts/Utils/Grid.cs.uid
new file mode 100644
index 0000000..c18e354
--- /dev/null
+++ b/scripts/Utils/Grid.cs.uid
@@ -0,0 +1 @@
+uid://75s33rka6l60
diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs
new file mode 100644
index 0000000..8e33b02
--- /dev/null
+++ b/scripts/actors/Actor.cs
@@ -0,0 +1,23 @@
+using Godot;
+
+[GlobalClass]
+public abstract partial class Actor : Sprite2D {
+ private Vector2I gridPosition = Vector2I.Zero;
+ public Vector2I GridPosition {
+ set {
+ gridPosition = value;
+ Position = Grid.GridToWorld(value);
+ }
+ get => gridPosition;
+ }
+
+ public override void _Ready()
+ {
+ base._Ready();
+ GridPosition = Grid.WorldToGrid(Position);
+ }
+
+ public void Walk(Vector2I offset) {
+ GridPosition += offset;
+ }
+} \ No newline at end of file
diff --git a/scripts/Actor.cs.uid b/scripts/actors/Actor.cs.uid
index cf29b40..cf29b40 100644
--- a/scripts/Actor.cs.uid
+++ b/scripts/actors/Actor.cs.uid
diff --git a/scripts/actors/Player.cs b/scripts/actors/Player.cs
new file mode 100644
index 0000000..c8abe12
--- /dev/null
+++ b/scripts/actors/Player.cs
@@ -0,0 +1,8 @@
+using Godot;
+using System;
+
+[GlobalClass]
+public partial class Player : Actor
+{
+
+}
diff --git a/scripts/Character.cs.uid b/scripts/actors/Player.cs.uid
index 8229b7f..8229b7f 100644
--- a/scripts/Character.cs.uid
+++ b/scripts/actors/Player.cs.uid
diff --git a/scripts/actors/actions/Action.cs b/scripts/actors/actions/Action.cs
new file mode 100644
index 0000000..21efa1a
--- /dev/null
+++ b/scripts/actors/actions/Action.cs
@@ -0,0 +1,6 @@
+using Godot;
+using System;
+
+public abstract partial class Action : RefCounted {
+ public abstract void Perform(Game game, Actor actor);
+}
diff --git a/scripts/actors/actions/Action.cs.uid b/scripts/actors/actions/Action.cs.uid
new file mode 100644
index 0000000..9523b0a
--- /dev/null
+++ b/scripts/actors/actions/Action.cs.uid
@@ -0,0 +1 @@
+uid://dlejckfyro2ch
diff --git a/scripts/actors/actions/MovementAction.cs b/scripts/actors/actions/MovementAction.cs
new file mode 100644
index 0000000..f29e2e8
--- /dev/null
+++ b/scripts/actors/actions/MovementAction.cs
@@ -0,0 +1,22 @@
+using Godot;
+using System;
+
+public partial class MovementAction : Action
+{
+ public Vector2I Offset { get; private set; }
+ public MovementAction(Vector2I offset)
+ {
+ Offset = offset;
+ }
+
+ public override void Perform(Game game, Actor actor)
+ {
+ Vector2I finalDestination = actor.GridPosition + Offset;
+
+ TileData tile = game.Dungeon.GetCellTileData(finalDestination);
+
+ if (tile == null || !(bool) tile.GetCustomData("isWalkable")) return;
+
+ actor.Walk(Offset);
+ }
+}
diff --git a/scripts/actors/actions/MovementAction.cs.uid b/scripts/actors/actions/MovementAction.cs.uid
new file mode 100644
index 0000000..07569ef
--- /dev/null
+++ b/scripts/actors/actions/MovementAction.cs.uid
@@ -0,0 +1 @@
+uid://cdtpdaeg7hh6p