mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 18:35:54 +00:00
Fix for weapon switching
This commit is contained in:
parent
898c15183b
commit
9e04056800
5 changed files with 83 additions and 3 deletions
|
|
@ -138,7 +138,14 @@ public partial class GameManager : Node2D
|
|||
var weapon = _player.CreateChild<Weapon>(WeaponTemplate);
|
||||
weapon.WeaponData = startingItem.WeaponData;
|
||||
|
||||
_player.EquippedWeapon ??= weapon;
|
||||
_player.AddWeapon(weapon);
|
||||
|
||||
if (_player.EquippedWeapon == null)
|
||||
{
|
||||
_player.EquipWeapon(weapon);
|
||||
}
|
||||
|
||||
//_player.EquippedWeapon ??= weapon;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
[Export] public float MaxHealth = 32f;
|
||||
|
||||
public Weapon EquippedWeapon { get; set; }
|
||||
|
||||
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
|
||||
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue