mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-04 12:11:15 +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")
|
BulletScene = ExtResource("1_yby7n")
|
||||||
RateOfFire = 0.1
|
RateOfFire = 0.1
|
||||||
BulletCapacity = 4
|
BulletCapacity = 4
|
||||||
ReloadTime = 0.8
|
ReloadTime = 0.2
|
||||||
AutoReload = true
|
AutoReload = true
|
||||||
InfiniteAmmo = true
|
InfiniteAmmo = true
|
||||||
BulletsPerShot = 1
|
BulletsPerShot = 1
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ script = ExtResource("1_8tmoj")
|
||||||
PlayerTemplate = ExtResource("2_8mh54")
|
PlayerTemplate = ExtResource("2_8mh54")
|
||||||
PlayerSpawnMarker = NodePath("PlayerStartPosition")
|
PlayerSpawnMarker = NodePath("PlayerStartPosition")
|
||||||
WeaponTemplate = ExtResource("3_2wlhc")
|
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="."]
|
[node name="Factory Tilemaps" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,14 @@ public partial class GameManager : Node2D
|
||||||
var weapon = _player.CreateChild<Weapon>(WeaponTemplate);
|
var weapon = _player.CreateChild<Weapon>(WeaponTemplate);
|
||||||
weapon.WeaponData = startingItem.WeaponData;
|
weapon.WeaponData = startingItem.WeaponData;
|
||||||
|
|
||||||
_player.EquippedWeapon ??= weapon;
|
_player.AddWeapon(weapon);
|
||||||
|
|
||||||
|
if (_player.EquippedWeapon == null)
|
||||||
|
{
|
||||||
|
_player.EquipWeapon(weapon);
|
||||||
|
}
|
||||||
|
|
||||||
|
//_player.EquippedWeapon ??= weapon;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,10 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
|
|
||||||
public Weapon EquippedWeapon { get; set; }
|
public Weapon EquippedWeapon { get; set; }
|
||||||
|
|
||||||
|
public Array<Weapon> EquippedWeapons { get; set; } = new Array<Weapon>();
|
||||||
|
|
||||||
|
public int CurrentWeaponIndex { get; set; } = 0;
|
||||||
|
|
||||||
private float _currentHealth = 0f;
|
private float _currentHealth = 0f;
|
||||||
|
|
||||||
private bool _isDestroyed = false;
|
private bool _isDestroyed = false;
|
||||||
|
|
@ -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)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
SetAnimation();
|
SetAnimation();
|
||||||
if (!_canMove) return;
|
if (!_canMove) return;
|
||||||
HandleShoot();
|
HandleShoot();
|
||||||
FindInteractable();
|
FindInteractable();
|
||||||
|
|
||||||
|
if (Input.IsActionJustPressed("next_weapon"))
|
||||||
|
{
|
||||||
|
NextWeapon();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.IsActionJustPressed("previous_weapon"))
|
||||||
|
{
|
||||||
|
PreviousWeapon();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FindInteractable()
|
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)
|
, 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]
|
[layer_names]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue