summaryrefslogtreecommitdiff
path: root/scripts/input/PickupInputHandler.cs
blob: 8f4f9b2db50704ddaf7496865de56330ef48e56c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Godot;

/// <summary>
/// Esquema de controles para pegar um item.
/// </summary>
public partial class PickupInputHandler : 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},
		{"skip-turn", Vector2I.Zero}
	};
	public override Action GetAction(Player player) {
		Action action = null;

		if (player.IsAlive) {
			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<InputHandler>().SetInputHandler(InputHandlers.MainGame);
	}
}