ammo working through weapon manager

This commit is contained in:
derek
2024-07-15 13:21:13 -05:00
parent 06b8229db1
commit f2ff68b7fa
5 changed files with 659 additions and 19 deletions

634
scenes/tesE29C.tmp Normal file

File diff suppressed because one or more lines are too long

View File

@@ -2,20 +2,20 @@ extends Label
const ASPECT_RATIO_STD = .5625 #9/16 for standard ratio const ASPECT_RATIO_STD = .5625 #9/16 for standard ratio
@export var padding_amount = .05 #multiplied by screen size @export var padding_amount = .05 #multiplied by screen size
@onready var level_control = $"../../../.."
@onready var player = $"../../.." @onready var player = $"../../.."
@onready var gun_anim = $"../gun/GunAnims" @onready var gun_anim = $"../gun/GunAnims"
var gun_index
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
var viewportWidth = get_viewport().size.x var viewportWidth = get_viewport().size.x
var viewportHeight = get_viewport().size.y var viewportHeight = get_viewport().size.y
var viewportHeightAdjusted = viewportWidth * ASPECT_RATIO_STD var viewportHeightAdjusted = viewportWidth * ASPECT_RATIO_STD
gun_index = 0
size = Vector2(viewportWidth - (padding_amount * viewportWidth), viewportHeight - (padding_amount * viewportHeightAdjusted)) size = Vector2(viewportWidth - (padding_amount * viewportWidth), viewportHeight - (padding_amount * viewportHeightAdjusted))
position = Vector2(0 - (padding_amount * viewportWidth) ,0 - (padding_amount * viewportHeightAdjusted)) position = Vector2(0 - (padding_amount * viewportWidth) ,0 - (padding_amount * viewportHeightAdjusted))
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
text = "Ammo: " + str(player.ammo) +" " + str(player.ammo_reserve) text = "Ammo: " + str(level_control.ammo_current[gun_index]) +" " + str(level_control.ammo_reserve[gun_index])

View File

@@ -29,7 +29,7 @@ func _ready():
player.ammo = player.gun.max_ammo player.ammo = player.gun.max_ammo
player.ammo_reserve = player.gun.max_ammo * player.gun.start_mags player.ammo_reserve = player.gun.max_ammo * player.gun.start_mags
player.gun_fire_pitch_starting = player.gun.audio_fire.pitch_scale player.gun_fire_pitch_starting = player.gun.audio_fire.pitch_scale
current_gun_index = 0 instance_gun.gun_index = 0
player.weapon_holder.add_child(instance_gun) player.weapon_holder.add_child(instance_gun)
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.

View File

@@ -35,8 +35,12 @@ var cycle_count
@export var audio_reload : Node @export var audio_reload : Node
@onready var player = $"../../../../" @onready var player = $"../../../../"
@onready var level_control = $"../../../../../"
@onready var ammo_current
var rng = RandomNumberGenerator.new() var rng = RandomNumberGenerator.new()
var level_control var gun_index
#var ammo_current
var ammo_reserve
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@@ -44,7 +48,9 @@ func _ready():
start_rotation = self.rotation start_rotation = self.rotation
random_spread_start = random_spread_amt random_spread_start = random_spread_amt
level_control = get_tree().get_root() ammo_current = level_control.ammo_current[gun_index]
ammo_reserve = level_control.ammo_reserve[gun_index]
if fire_mode == 0: if fire_mode == 0:
cycle_count = 1 cycle_count = 1
@@ -64,27 +70,26 @@ func _process(delta):
func reload_finished(): func reload_finished():
if player.ammo_reserve >= max_ammo: if level_control.ammo_reserve[gun_index] >= max_ammo:
player.ammo += max_ammo level_control.ammo_current[gun_index] += max_ammo
player.ammo_reserve -= max_ammo level_control.ammo_reserve[gun_index] -= max_ammo
player.reloading = false player.reloading = false
else: else:
player.ammo += player.ammo_reserve level_control.ammo_current[gun_index] += level_control.ammo_reserve[gun_index]
player.ammo_reserve -= player.ammo_reserve level_control.ammo_reserve[gun_index] -= level_control.ammo_reserve[gun_index]
player.reloading = false player.reloading = false
func shoot(player,delta): func shoot(player,delta):
if player.ammo > 0 and cycle_count > 0: if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
if !anim_player.is_playing(): if !anim_player.is_playing():
player.ammo -= 1 level_control.ammo_current[gun_index] -= 1
#RECOIL --- fix later to happen over a period of time #RECOIL --- fix later to happen over a period of time
player.camera.rotation.x = clamp(lerp(player.camera.rotation.x, player.camera.rotation.x + recoil_amount, delta * 10), deg_to_rad(-90), deg_to_rad(60)) player.camera.rotation.x = clamp(lerp(player.camera.rotation.x, player.camera.rotation.x + recoil_amount, delta * 10), deg_to_rad(-90), deg_to_rad(60))
#(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION) #(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION)
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt) audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
audio_fire.play() audio_fire.play()
anim_player.play("shoot") anim_player.play("shoot")
# instance bullet # instance bullet
var instance_bullet = bullet.instantiate() var instance_bullet = bullet.instantiate()
instance_bullet.position = player.bullet_ray.global_position instance_bullet.position = player.bullet_ray.global_position
@@ -114,15 +119,15 @@ func shoot(player,delta):
audio_empty.play() audio_empty.play()
func reload(player,delta): func reload(player,delta):
if player.ammo < max_ammo and player.reloading == false and player.ammo_reserve > 0: if level_control.ammo_current[gun_index] < max_ammo and player.reloading == false and level_control.ammo_reserve[gun_index] > 0:
player.reloading = true player.reloading = true
anim_player.play("reload") anim_player.play("reload")
audio_reload.play() audio_reload.play()
if anim_player.is_playing() and anim_player.current_animation == "reload": if anim_player.is_playing() and anim_player.current_animation == "reload":
if player.ammo == 0: if level_control.ammo_current[gun_index] == 0:
player.ammo = 0 level_control.ammo_current[gun_index] = 0
else: else:
player.ammo = 1 level_control.ammo_current[gun_index] = 1
func spawn_mag(): func spawn_mag():
var instance_mag = mag.instantiate() var instance_mag = mag.instantiate()

View File

@@ -47,6 +47,7 @@ var gun_folded = false
var recoiling_fade = 0 var recoiling_fade = 0
var bullet_destination var bullet_destination
var gun_fire_pitch_starting var gun_fire_pitch_starting
var current_weapon_index
# Slow Down Variables # Slow Down Variables
const SLOWSPEED = .2 const SLOWSPEED = .2