From c6bbb834f7758027c0df338f1520f34fad3befea Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 9 Sep 2025 19:09:34 -0300 Subject: Organização MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/InputHandling/PickupInputHandler.cs | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 scripts/InputHandling/PickupInputHandler.cs (limited to 'scripts/InputHandling/PickupInputHandler.cs') diff --git a/scripts/InputHandling/PickupInputHandler.cs b/scripts/InputHandling/PickupInputHandler.cs new file mode 100644 index 0000000..1396b2b --- /dev/null +++ b/scripts/InputHandling/PickupInputHandler.cs @@ -0,0 +1,50 @@ +using Godot; +using TheLegendOfGustav.Entities.Actions; +using TheLegendOfGustav.Entities.Actors; + +namespace TheLegendOfGustav.InputHandling; + +/// +/// Esquema de controles para pegar um item. +/// +public partial class PickupInputHandler : 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}, + {"skip-turn", Vector2I.Zero} + }; + + public override Action GetAction(Player player) + { + Action action = null; + + foreach (var direction in directions) + { + if (Input.IsActionJustPressed(direction.Key)) + { + action = new PickupAction(player, direction.Value); + Quit(); + } + } + + if (Input.IsActionJustPressed("quit")) + { + Quit(); + } + + return action; + } + + private void Quit() + { + GetParent().SetInputHandler(InputHandlers.MainGame); + } +} -- cgit v1.2.3