mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Fix for weapon switching
This commit is contained in:
parent
898c15183b
commit
9e04056800
5 changed files with 83 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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="."]
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue