From 6842ccfd372601db6b5d3f678ab5ebf03ad2b206 Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 2 Sep 2025 12:50:09 -0300 Subject: Adicionado entidade Inspetor. --- scripts/actors/Actor.cs | 2 +- scripts/actors/Inspector.cs | 39 +++++++++++++++++++++ scripts/actors/Inspector.cs.uid | 1 + scripts/input/BaseInputHandler.cs | 17 ++++++--- scripts/input/InputHandler.cs | 8 +++-- scripts/input/InspectInputHandler.cs | 59 ++++++++++++++++++++++++++++++++ scripts/input/InspectInputHandler.cs.uid | 1 + scripts/input/MainGameInputHandler.cs | 4 +++ 8 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 scripts/actors/Inspector.cs create mode 100644 scripts/actors/Inspector.cs.uid create mode 100644 scripts/input/InspectInputHandler.cs create mode 100644 scripts/input/InspectInputHandler.cs.uid (limited to 'scripts') diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs index 2d22d44..80e8c1d 100644 --- a/scripts/actors/Actor.cs +++ b/scripts/actors/Actor.cs @@ -4,7 +4,7 @@ using Godot; /// A classe de ator define um personagem no jogo. /// [GlobalClass] -public abstract partial class Actor : Sprite2D +public partial class Actor : Sprite2D { /// /// Sinal emitido toda vez que o HP mudar. diff --git a/scripts/actors/Inspector.cs b/scripts/actors/Inspector.cs new file mode 100644 index 0000000..0bdab5b --- /dev/null +++ b/scripts/actors/Inspector.cs @@ -0,0 +1,39 @@ +using Godot; + +/// +/// Isto é uma abominação +/// +public partial class Inspector : Sprite2D +{ + private static readonly Texture2D texture = GD.Load("res://assets/sprites/inspector.png"); + + private Vector2I gridPosition = Vector2I.Zero; + /// + /// Posição do inspetor no espaço. Diferentemente de Position, GridPosition tem como formato + /// os tiles do mapa. + /// + public Vector2I GridPosition { + set { + gridPosition = value; + // O sistema de coordenadas do Godot é em pixels, mas faz mais sentido para o jogo utilizar coordenadas em tiles. + // Esta propriedade converte um sistema para o outro automaticamente. + Position = Grid.GridToWorld(value); + } + get => gridPosition; + } + + public Inspector(Vector2I initialPosition) + { + GridPosition = initialPosition; + Centered = false; + Texture = texture; + } + + /// + /// O Inspetor não faz parte do mapa. + /// + /// + public void Walk(Vector2I offset) { + GridPosition += offset; + } +} \ No newline at end of file diff --git a/scripts/actors/Inspector.cs.uid b/scripts/actors/Inspector.cs.uid new file mode 100644 index 0000000..ca411e4 --- /dev/null +++ b/scripts/actors/Inspector.cs.uid @@ -0,0 +1 @@ +uid://dxsrtu4b3pi08 diff --git a/scripts/input/BaseInputHandler.cs b/scripts/input/BaseInputHandler.cs index 4ba25d7..4e389ed 100644 --- a/scripts/input/BaseInputHandler.cs +++ b/scripts/input/BaseInputHandler.cs @@ -9,11 +9,18 @@ using Godot; /// Mas isto pode aumentar. /// public abstract partial class BaseInputHandler : Node { - - /// - /// Obtém uma ação do usuári conforme input. + /// + /// Método executado quando o input handler entra em cena; /// - /// Jogador - /// Ação que o jogador escolheu, nulo se nenhuma. + public virtual void Enter() { } + /// + /// Método executado quando o input handler sai de cena; + /// + public virtual void Exit() { } + /// + /// Obtém uma ação do usuári conforme input. + /// + /// Jogador + /// Ação que o jogador escolheu, nulo se nenhuma. public abstract Action GetAction(Player player); } diff --git a/scripts/input/InputHandler.cs b/scripts/input/InputHandler.cs index 873276f..4f5b4e1 100644 --- a/scripts/input/InputHandler.cs +++ b/scripts/input/InputHandler.cs @@ -3,7 +3,8 @@ using Godot; public enum InputHandlers { MainGame, - GameOver + GameOver, + Inspect } /// @@ -25,7 +26,8 @@ public partial class InputHandler : Node inputHandlers.Add(InputHandlers.MainGame, GetNode("MainGameInputHandler")); // Controles para quando o jogador está morto. inputHandlers.Add(InputHandlers.GameOver, GetNode("GameOverInputHandler")); - + inputHandlers.Add(InputHandlers.Inspect, GetNode("InspectInputHandler")); + SetInputHandler(startingInputHandler); } @@ -39,6 +41,8 @@ public partial class InputHandler : Node /// /// Estado do jogo. public void SetInputHandler(InputHandlers inputhandler) { + selectedInputHandler?.Exit(); selectedInputHandler = inputHandlers[inputhandler]; + selectedInputHandler.Enter(); } } diff --git a/scripts/input/InspectInputHandler.cs b/scripts/input/InspectInputHandler.cs new file mode 100644 index 0000000..60c10e4 --- /dev/null +++ b/scripts/input/InspectInputHandler.cs @@ -0,0 +1,59 @@ +using Godot; + +/// +/// TODO: Esta solução é nojenta e precisa ser retrabalhada. +/// +public partial class InspectInputHandler : BaseInputHandler +{ + private readonly Godot.Collections.Dictionary directions = new() + { + {"walk-up", Vector2I.Up}, + {"walk-down", Vector2I.Down}, + {"walk-left", Vector2I.Left}, + {"walk-right", Vector2I.Right}, + {"walk-up-right", Vector2I.Up + Vector2I.Right}, + {"walk-up-left", Vector2I.Up + Vector2I.Left}, + {"walk-down-right", Vector2I.Down + Vector2I.Right}, + {"walk-down-left", Vector2I.Down + Vector2I.Left}, + }; + /// + /// Preciso disso + /// + [Export] + private Map map; + + private Inspector inspector; + + public override void Enter() { + inspector = new(map.Map_Data.Player.GridPosition) + { + ZIndex = 4 + }; + // Copiamos a câmera do jogador com todas as suas configurações + Camera2D camera = (Camera2D) map.Map_Data.Player.GetNode("Camera2D").Duplicate(); + inspector.AddChild(camera); + + map.AddChild(inspector); + camera.Enabled = true; + camera.MakeCurrent(); + } + + public override void Exit() { + inspector.QueueFree(); + } + public override Action GetAction(Player player) + { + Action action = null; + foreach (var direction in directions) { + if (Input.IsActionJustPressed(direction.Key)) { + inspector.Walk(direction.Value); + } + } + + if (Input.IsActionJustPressed("quit")) { + GetParent().SetInputHandler(InputHandlers.MainGame); + } + + return action; + } +} \ No newline at end of file diff --git a/scripts/input/InspectInputHandler.cs.uid b/scripts/input/InspectInputHandler.cs.uid new file mode 100644 index 0000000..20141fa --- /dev/null +++ b/scripts/input/InspectInputHandler.cs.uid @@ -0,0 +1 @@ +uid://bamlnrj5bm1rd diff --git a/scripts/input/MainGameInputHandler.cs b/scripts/input/MainGameInputHandler.cs index 1c5ac6e..c7bf26a 100644 --- a/scripts/input/MainGameInputHandler.cs +++ b/scripts/input/MainGameInputHandler.cs @@ -24,6 +24,10 @@ public partial class MainGameInputHandler : BaseInputHandler { action = new BumpAction(player, direction.Value); } } + + if (Input.IsActionJustPressed("inspect")) { + GetParent().SetInputHandler(InputHandlers.Inspect); + } if (Input.IsActionJustPressed("skip-turn")) { action = new WaitAction(player); -- cgit v1.2.3