1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-24 08:44:18 +00:00
pineapple-surf/player/OnHand.gd

58 lines
1.3 KiB
GDScript3
Raw Normal View History

extends Node3D
enum GUN_STATE {
ACTIVE,
SWITCHING,
INACTIVE
}
var active_weapon: BaseWeapon
signal weapon_switched(weapon: BaseWeapon)
var player: Player:
get:
return player
set(p):
player = p
2023-01-09 00:53:52 +00:00
for weapon in weapons:
weapon.player = player
var weapons: Array = [
2023-01-08 01:25:48 +00:00
load("res://player/onhand/PeaShooter.tscn").instantiate()
# load("res://Player/Weapons/Arm.tscn").instantiate(),
# load("res://Player/Weapons/ak47.tscn").instantiate(),
]
func _ready() -> void:
2023-01-08 01:25:48 +00:00
self._switch_weapon(BaseWeapon.WeaponSlot.ONE)
2023-01-08 12:13:09 +00:00
func _input(_event: InputEvent) -> void:
if Input.is_action_just_pressed("slot1"):
_switch_weapon(BaseWeapon.WeaponSlot.ONE)
2023-01-08 01:25:48 +00:00
# elif Input.is_action_just_pressed("slot2"):
# _switch_weapon(BaseWeapon.WeaponSlot.TWO)
# elif Input.is_action_just_pressed("slot3"):
# _switch_weapon(BaseWeapon.WeaponSlot.THREE)
func _switch_weapon(slot: BaseWeapon.WeaponSlot):
# TODO: play anim ecc ecc
# Try to get the correct weapon per the given `slot`
for weapon in weapons:
if weapon.weaponSlot == slot:
# Remove active weapon
if active_weapon:
2023-01-08 12:13:09 +00:00
active_weapon.on_switch_out()
2023-01-09 00:53:52 +00:00
remove_child(active_weapon)
# Add new weapon
add_child(weapon)
active_weapon = weapon
2023-01-08 12:13:09 +00:00
active_weapon.on_switch_in()
emit_signal("weapon_switched", weapon)
break