From 1bf37d7afa1f99526d977f22c4132066ea6f1f34 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Sat, 12 Aug 2023 23:18:12 -0700 Subject: [PATCH 1/2] controller support wip --- State/Character/PlayerState.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/State/Character/PlayerState.cs b/State/Character/PlayerState.cs index 0c49024..73adcc5 100644 --- a/State/Character/PlayerState.cs +++ b/State/Character/PlayerState.cs @@ -50,6 +50,8 @@ public abstract partial class PlayerState : CharacterState Vector2 mousePos = Character.GetGlobalMousePosition(); Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos); + Vector2 joystick = Godot.Input.GetVector("look_left", "look_right", + "look_up", "look_down"); if (Character.Inventory.SelectedItem is Items.Weapon weapon) { @@ -58,7 +60,14 @@ public abstract partial class PlayerState : CharacterState if (!weapon.ShouldHideIdle || isAttack1On) { - Character.Target = dirToMouse; + if (joystick.IsZeroApprox()) + { + Character.Target = Character.Direction; + } + else + { + Character.Target = joystick; + } } if (isAttack1On) From 7a0e8e29a3d42c1433b7794a5d28066752648e60 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Tue, 15 Aug 2023 00:44:44 -0700 Subject: [PATCH 2/2] switching items with controller --- Items/Inventory.cs | 24 ++++++++++++++++++++++++ State/Character/PlayerState.cs | 8 ++++++++ project.godot | 10 ++++++++++ 3 files changed, 42 insertions(+) diff --git a/Items/Inventory.cs b/Items/Inventory.cs index 56ef5aa..c8e9ef8 100644 --- a/Items/Inventory.cs +++ b/Items/Inventory.cs @@ -27,6 +27,20 @@ public partial class Inventory : Node2D set => EquipItem(value, ref _selectedItem); } + private int _quickSwitchIndex = -1; + + public const int QUICKSWITCH_SIZE = 3; + + public int CurrentQuickSwitchIndex + { + get => _quickSwitchIndex; + set + { + const int size = QUICKSWITCH_SIZE; + _quickSwitchIndex = (value % size + size) % size; + } + } + public bool IsUsingItem => SelectedItem?.IsUsing ?? false; public Inventory() @@ -57,6 +71,16 @@ public partial class Inventory : Node2D base._Ready(); } + public bool EquipIndex(int index) + { + if (index < Items.Count) + { + return EquipItem(Items[index], ref _selectedItem); + } + + return EquipItem(null, ref _selectedItem); + } + private bool EquipItem(Item item, ref Item slot) { if (item is not null) diff --git a/State/Character/PlayerState.cs b/State/Character/PlayerState.cs index 73adcc5..b780fa0 100644 --- a/State/Character/PlayerState.cs +++ b/State/Character/PlayerState.cs @@ -30,6 +30,14 @@ public abstract partial class PlayerState : CharacterState { inventory.SelectedItem = inventory.GetItemByMap("equip_3"); } + else if (@event.IsActionPressed("next_item")) + { + inventory.EquipIndex(++inventory.CurrentQuickSwitchIndex); + } + else if (@event.IsActionPressed("prev_item")) + { + inventory.EquipIndex(--inventory.CurrentQuickSwitchIndex); + } if (@event.IsActionPressed("interact")) { diff --git a/project.godot b/project.godot index 55cbffc..854203e 100644 --- a/project.godot +++ b/project.godot @@ -172,6 +172,16 @@ look_right={ "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) ] } +next_item={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":5,"pressure":0.0,"pressed":false,"script":null) +] +} +prev_item={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":4,"pressure":0.0,"pressed":false,"script":null) +] +} [internationalization]