summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-02 12:50:09 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-02 12:50:09 -0300
commit6842ccfd372601db6b5d3f678ab5ebf03ad2b206 (patch)
tree572c89e5d266087f18c763bec3085dca3f29bdb6 /scripts
parent4be033a60846cbdd290da27be44f270eba5a964d (diff)
Adicionado entidade Inspetor.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/actors/Actor.cs2
-rw-r--r--scripts/actors/Inspector.cs39
-rw-r--r--scripts/actors/Inspector.cs.uid1
-rw-r--r--scripts/input/BaseInputHandler.cs17
-rw-r--r--scripts/input/InputHandler.cs8
-rw-r--r--scripts/input/InspectInputHandler.cs59
-rw-r--r--scripts/input/InspectInputHandler.cs.uid1
-rw-r--r--scripts/input/MainGameInputHandler.cs4
8 files changed, 123 insertions, 8 deletions
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.
/// </summary>
[GlobalClass]
-public abstract partial class Actor : Sprite2D
+public partial class Actor : Sprite2D
{
/// <summary>
/// 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;
+
+/// <summary>
+/// Isto é uma abominação
+/// </summary>
+public partial class Inspector : Sprite2D
+{
+ private static readonly Texture2D texture = GD.Load<Texture2D>("res://assets/sprites/inspector.png");
+
+ private Vector2I gridPosition = Vector2I.Zero;
+ /// <summary>
+ /// Posição do inspetor no espaço. Diferentemente de Position, GridPosition tem como formato
+ /// os tiles do mapa.
+ /// </summary>
+ 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;
+ }
+
+ /// <summary>
+ /// O Inspetor não faz parte do mapa.
+ /// </summary>
+ /// <param name="offset"></param>
+ 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.
/// </summary>
public abstract partial class BaseInputHandler : Node {
-
- /// <summary>
- /// Obtém uma ação do usuári conforme input.
+ /// <summary>
+ /// Método executado quando o input handler entra em cena;
/// </summary>
- /// <param name="player">Jogador</param>
- /// <returns>Ação que o jogador escolheu, nulo se nenhuma.</returns>
+ public virtual void Enter() { }
+ /// <summary>
+ /// Método executado quando o input handler sai de cena;
+ /// </summary>
+ public virtual void Exit() { }
+ /// <summary>
+ /// Obtém uma ação do usuári conforme input.
+ /// </summary>
+ /// <param name="player">Jogador</param>
+ /// <returns>Ação que o jogador escolheu, nulo se nenhuma.</returns>
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
}
/// <summary>
@@ -25,7 +26,8 @@ public partial class InputHandler : Node
inputHandlers.Add(InputHandlers.MainGame, GetNode<MainGameInputHandler>("MainGameInputHandler"));
// Controles para quando o jogador está morto.
inputHandlers.Add(InputHandlers.GameOver, GetNode<GameOverInputHandler>("GameOverInputHandler"));
-
+ inputHandlers.Add(InputHandlers.Inspect, GetNode<InspectInputHandler>("InspectInputHandler"));
+
SetInputHandler(startingInputHandler);
}
@@ -39,6 +41,8 @@ public partial class InputHandler : Node
/// </summary>
/// <param name="inputhandler">Estado do jogo.</param>
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;
+
+/// <summary>
+/// TODO: Esta solução é nojenta e precisa ser retrabalhada.
+/// </summary>
+public partial class InspectInputHandler : BaseInputHandler
+{
+ private readonly Godot.Collections.Dictionary<string, Vector2I> 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},
+ };
+ /// <summary>
+ /// Preciso disso
+ /// </summary>
+ [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>("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<InputHandler>().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<InputHandler>().SetInputHandler(InputHandlers.Inspect);
+ }
if (Input.IsActionJustPressed("skip-turn")) {
action = new WaitAction(player);