diff --git a/Resources/Weapons/IcicleGun.tres b/Resources/Weapons/IcicleGun.tres index 60a71c14..10c9c5e5 100644 --- a/Resources/Weapons/IcicleGun.tres +++ b/Resources/Weapons/IcicleGun.tres @@ -9,7 +9,7 @@ Name = "Icicle Gun" BulletScene = ExtResource("1_yby7n") RateOfFire = 0.1 BulletCapacity = 4 -ReloadTime = 0.8 +ReloadTime = 0.2 AutoReload = true InfiniteAmmo = true BulletsPerShot = 1 diff --git a/Scenes/test.tscn b/Scenes/test.tscn index ee8560a6..d6f24469 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -52,7 +52,7 @@ script = ExtResource("1_8tmoj") PlayerTemplate = ExtResource("2_8mh54") PlayerSpawnMarker = NodePath("PlayerStartPosition") WeaponTemplate = ExtResource("3_2wlhc") -StartingEquipment = Array[Object]([ExtResource("4_swym2"), ExtResource("5_frf65"), ExtResource("5_nqier")]) +StartingEquipment = Array[Object]([ExtResource("4_swym2"), ExtResource("5_nqier"), ExtResource("5_frf65")]) [node name="Factory Tilemaps" type="Node2D" parent="."] diff --git a/Scripts/GameManager.cs b/Scripts/GameManager.cs index 41e85487..d8df67f0 100644 --- a/Scripts/GameManager.cs +++ b/Scripts/GameManager.cs @@ -138,7 +138,14 @@ public partial class GameManager : Node2D var weapon = _player.CreateChild(WeaponTemplate); weapon.WeaponData = startingItem.WeaponData; - _player.EquippedWeapon ??= weapon; + _player.AddWeapon(weapon); + + if (_player.EquippedWeapon == null) + { + _player.EquipWeapon(weapon); + } + + //_player.EquippedWeapon ??= weapon; break; } diff --git a/Scripts/PlayerMovement.cs b/Scripts/PlayerMovement.cs index 11aaeb97..783164ce 100644 --- a/Scripts/PlayerMovement.cs +++ b/Scripts/PlayerMovement.cs @@ -45,6 +45,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible [Export] public float MaxHealth = 32f; public Weapon EquippedWeapon { get; set; } + + public Array EquippedWeapons { get; set; } = new Array(); + + public int CurrentWeaponIndex { get; set; } = 0; private float _currentHealth = 0f; @@ -157,12 +161,56 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible } }*/ + public void AddWeapon(Weapon weapon) + { + EquippedWeapons.Add(weapon); + } + + public void EquipWeapon(Weapon weapon) + { + EquippedWeapon = weapon; + CurrentWeaponIndex = EquippedWeapons.IndexOf(weapon); + } + + public void NextWeapon() + { + CurrentWeaponIndex += 1; + if (CurrentWeaponIndex > EquippedWeapons.Count - 1) + { + CurrentWeaponIndex = EquippedWeapons.Count - 1; + } + + EquipWeapon(EquippedWeapons[CurrentWeaponIndex]); + } + + public void PreviousWeapon() + { + CurrentWeaponIndex -= 1; + if (CurrentWeaponIndex < 0) + { + CurrentWeaponIndex = 0; + } + + EquipWeapon(EquippedWeapons[CurrentWeaponIndex]); + } + public override void _Process(double delta) { SetAnimation(); if (!_canMove) return; HandleShoot(); FindInteractable(); + + if (Input.IsActionJustPressed("next_weapon")) + { + NextWeapon(); + } + + if (Input.IsActionJustPressed("previous_weapon")) + { + PreviousWeapon(); + } + } private void FindInteractable() diff --git a/project.godot b/project.godot index a013f5d6..11bf5aeb 100644 --- a/project.godot +++ b/project.godot @@ -197,6 +197,31 @@ pause={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194332,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +next_weapon={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null) +] +} +previous_weapon={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null) +] +} +next_item={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":52,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null) +] +} +previous_item={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null) +] +} +use_item={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":85,"key_label":0,"unicode":117,"location":0,"echo":false,"script":null) +] +} [layer_names]