weapon swap working and array tracking bullet status
This commit is contained in:
@@ -18,4 +18,4 @@ func _ready():
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
text = "Ammo: " + str(level_control.ammo_current[gun_index]) +" " + str(level_control.ammo_reserve[gun_index])
|
||||
text = str(player.gun.gun_name) + "\n Ammo: " + str(level_control.ammo_current[level_control.current_gun_index]) +" " + str(level_control.ammo_reserve[level_control.current_gun_index])
|
||||
|
||||
@@ -16,22 +16,36 @@ func _ready():
|
||||
held_guns = [gun_1,gun_2]
|
||||
var instance_gun = held_guns[0].instantiate()
|
||||
var instance_gun_2 = held_guns[1].instantiate()
|
||||
|
||||
#set up ammo for starting guns
|
||||
ammo_current[1] = instance_gun_2.max_ammo
|
||||
ammo_reserve[1] = instance_gun_2.max_ammo * instance_gun_2.start_mags
|
||||
|
||||
ammo_current[0] = instance_gun.max_ammo
|
||||
ammo_reserve[0] = instance_gun.max_ammo * instance_gun.start_mags
|
||||
print(ammo_current)
|
||||
print(ammo_reserve)
|
||||
#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 = 0
|
||||
instance_gun.gun_index = index
|
||||
instance_gun.anim_player.play("swap_in")
|
||||
player.weapon_holder.add_child(instance_gun)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
@@ -7,6 +7,7 @@ var cycle_count_start
|
||||
var cycle_count
|
||||
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var recoil_amount = .2
|
||||
@export var max_ammo = 15
|
||||
@@ -134,3 +135,6 @@ func spawn_mag():
|
||||
instance_mag.position = mag_ejector.global_position
|
||||
instance_mag.transform.basis = mag_ejector.global_transform.basis
|
||||
get_tree().get_root().add_child(instance_mag)
|
||||
|
||||
func swapped_out():
|
||||
queue_free()
|
||||
|
||||
@@ -180,29 +180,13 @@ func _physics_process(delta):
|
||||
gun_folded = false
|
||||
|
||||
#Weapon Swap Up
|
||||
if Input.is_action_just_pressed("scroll_up"):
|
||||
gun.queue_free()
|
||||
var instance_gun = level_control.gun_2.instantiate()
|
||||
instance_gun.global_transform.origin = weapon_spawner.position
|
||||
gun = instance_gun
|
||||
def_weapon_holder_pos = weapon_holder.position
|
||||
ammo = gun.max_ammo
|
||||
ammo_reserve = gun.max_ammo * gun.start_mags
|
||||
bullet_damage = gun.bullet_damage
|
||||
gun_fire_pitch_starting = gun.audio_fire.pitch_scale
|
||||
weapon_holder.add_child(instance_gun)
|
||||
if Input.is_action_just_pressed("scroll_up") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index + 1)
|
||||
#Weapon Swap Down
|
||||
if Input.is_action_just_pressed("scroll_down"):
|
||||
gun.queue_free()
|
||||
var instance_gun = level_control.gun_1.instantiate()
|
||||
instance_gun.global_transform.origin = weapon_spawner.position
|
||||
gun = instance_gun
|
||||
def_weapon_holder_pos = weapon_holder.position
|
||||
ammo = gun.max_ammo
|
||||
ammo_reserve = gun.max_ammo * gun.start_mags
|
||||
bullet_damage = gun.bullet_damage
|
||||
gun_fire_pitch_starting = gun.audio_fire.pitch_scale
|
||||
weapon_holder.add_child(instance_gun)
|
||||
if Input.is_action_just_pressed("scroll_down") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index - 1)
|
||||
|
||||
move_and_slide()
|
||||
weapon_tilt(input_dir.x, delta)
|
||||
@@ -229,7 +213,7 @@ func _on_pick_up_detection_body_entered(body):
|
||||
pickupmsg = pickup_announce.instantiate()
|
||||
pickupmsg.pickuptext = "ammo"
|
||||
get_parent().add_child(pickupmsg)
|
||||
ammo_reserve += int((body.rand_amt/100) * gun.max_ammo)
|
||||
level_control.ammo_reserve[level_control.current_gun_index] += int((body.rand_amt/100) * gun.max_ammo)
|
||||
picked_up = true
|
||||
picked_up_text = "ammo"
|
||||
pickup_sound.pitch_scale = 1 + rng.randf_range(-.3,.3)
|
||||
|
||||
Reference in New Issue
Block a user