diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-17 19:32:36 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-17 19:32:36 -0300 |
| commit | ca782d7310f2df854a8727535ac92337c85ed445 (patch) | |
| tree | 7df571c01d48cac56fb8362d4d091bdd2a55c09a /scripts/actors | |
| parent | adb86dd1725276457c13e9a4d37372fda628dea3 (diff) | |
Gigantesco refactor
Diffstat (limited to 'scripts/actors')
| -rw-r--r-- | scripts/actors/Actor.cs | 23 | ||||
| -rw-r--r-- | scripts/actors/Actor.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/actors/Player.cs | 8 | ||||
| -rw-r--r-- | scripts/actors/Player.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/actors/actions/Action.cs | 6 | ||||
| -rw-r--r-- | scripts/actors/actions/Action.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/actors/actions/MovementAction.cs | 22 | ||||
| -rw-r--r-- | scripts/actors/actions/MovementAction.cs.uid | 1 |
8 files changed, 63 insertions, 0 deletions
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/actors/Actor.cs.uid b/scripts/actors/Actor.cs.uid new file mode 100644 index 0000000..cf29b40 --- /dev/null +++ b/scripts/actors/Actor.cs.uid @@ -0,0 +1 @@ +uid://c0cm4woy8lawl 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/actors/Player.cs.uid b/scripts/actors/Player.cs.uid new file mode 100644 index 0000000..8229b7f --- /dev/null +++ b/scripts/actors/Player.cs.uid @@ -0,0 +1 @@ +uid://c840l08453pu2 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 |
