diff options
Diffstat (limited to 'scripts/WeaponHolder.cs')
| -rw-r--r-- | scripts/WeaponHolder.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/WeaponHolder.cs b/scripts/WeaponHolder.cs new file mode 100644 index 0000000..210be60 --- /dev/null +++ b/scripts/WeaponHolder.cs @@ -0,0 +1,43 @@ +using Godot; + +public partial class WeaponHolder : Node2D +{ + [Export] public PackedScene[] WeaponScenes { get; set; } + + private Weapon _currentWeapon; + + public override void _Ready() + { + // Equip the first weapon automatically + EquipWeapon(0); + } + + public void EquipWeapon(int index) + { + if (WeaponScenes == null || WeaponScenes.Length <= index || WeaponScenes[index] == null) + return; + + if (_currentWeapon != null) + { + _currentWeapon.QueueFree(); + } + + _currentWeapon = WeaponScenes[index].Instantiate<Weapon>(); + AddChild(_currentWeapon); + + GD.Print($"WeaponHolder equipped weapon index: {index}"); + } + + public override void _UnhandledInput(InputEvent @event) + { + // Handle shooting + if (@event.IsActionPressed("shoot") && _currentWeapon != null) + { + _currentWeapon.Fire(GetGlobalMousePosition()); + } + + // Handle swapping + if (@event.IsActionPressed("weapon_1")) EquipWeapon(0); + else if (@event.IsActionPressed("weapon_2")) EquipWeapon(1); + } +}
\ No newline at end of file |
