61 lines
1.7 KiB
GDScript
61 lines
1.7 KiB
GDScript
extends Node3D
|
|
|
|
|
|
@export var player : Node
|
|
@export var money = 250
|
|
@export var health = 3
|
|
@export var MAX_PARTICLES = 100
|
|
@export var gun_1 : Resource
|
|
@export var gun_2 : Resource
|
|
var held_guns = []
|
|
var ammo_current = [0]
|
|
var ammo_reserve = [0]
|
|
var guns_dict = {}
|
|
var current_gun_index
|
|
var particle_number = 0
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
#global randomize function
|
|
randomize()
|
|
|
|
#Set up starting guns and ammo
|
|
held_guns = [gun_1]
|
|
var instance_gun = held_guns[0].instantiate()
|
|
ammo_current[0] = instance_gun.max_ammo
|
|
ammo_reserve[0] = instance_gun.max_ammo * instance_gun.start_mags
|
|
|
|
if gun_2 != null:
|
|
held_guns.append(gun_2)
|
|
var instance_gun_2 = held_guns[1].instantiate()
|
|
ammo_current.append(instance_gun_2.max_ammo)
|
|
ammo_reserve.append(instance_gun_2.max_ammo * instance_gun_2.start_mags)
|
|
|
|
# Spawn first gun
|
|
current_gun_index = 0
|
|
gun_spawn(0)
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(_delta):
|
|
pass
|
|
|
|
func gun_spawn(index):
|
|
#loop around if scrolling past available guns
|
|
if index > held_guns.size() - 1:
|
|
index = 0
|
|
elif index < 0:
|
|
index = held_guns.size() - 1
|
|
|
|
current_gun_index = index
|
|
|
|
var instance_gun = held_guns[index].instantiate()
|
|
instance_gun.global_transform.origin = player.weapon_spawner.position
|
|
player.gun = instance_gun
|
|
player.def_weapon_holder_pos = player.weapon_holder.position
|
|
player.ammo = player.gun.max_ammo
|
|
player.ammo_reserve = player.gun.max_ammo * player.gun.start_mags
|
|
player.gun_fire_pitch_starting = player.gun.audio_fire.pitch_scale
|
|
instance_gun.gun_index = index
|
|
instance_gun.anim_player.play("swap_in")
|
|
player.weapon_holder.add_child(instance_gun)
|