diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-28 12:52:20 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-28 12:52:20 -0300 |
| commit | afcd5055e98dcb7c9fefeabb072ecc56d0456bd7 (patch) | |
| tree | 7b5efa129573e184ce5c5f6e0dd8ae872b29e62a /scripts/InputHandler.cs | |
| parent | 2fb787a744d4f7a37d81233d2913a5ef39122f73 (diff) | |
Movimento diagonal
Diffstat (limited to 'scripts/InputHandler.cs')
| -rw-r--r-- | scripts/InputHandler.cs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/scripts/InputHandler.cs b/scripts/InputHandler.cs index b3c7018..39016ed 100644 --- a/scripts/InputHandler.cs +++ b/scripts/InputHandler.cs @@ -1,22 +1,32 @@ +using System.Numerics; using Godot; /// <summary> /// Obtém input do usuário. /// </summary> public partial class InputHandler : Node { + 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}, + }; public Action GetAction(Player player) { Action action = null; - if (Input.IsActionJustPressed("walk-up")) { - action = new BumpAction(player, Vector2I.Up); - } else if (Input.IsActionJustPressed("walk-down")) { - action = new BumpAction(player, Vector2I.Down); - } else if (Input.IsActionJustPressed("walk-left")) { - action = new BumpAction(player, Vector2I.Left); - } else if (Input.IsActionJustPressed("walk-right")) { - action = new BumpAction(player, Vector2I.Right); - } else if (Input.IsActionJustPressed("skip-turn")) { - action = new BumpAction(player, Vector2I.Zero); + foreach (var direction in directions) { + if (Input.IsActionJustPressed(direction.Key)) { + action = new BumpAction(player, direction.Value); + } + } + + if (Input.IsActionJustPressed("skip-turn")) { + action = new WaitAction(player); } return action; |
