ammo rework seems to mostly be in order

This commit is contained in:
derek
2025-01-15 15:33:57 -06:00
parent 0a4e4eefb3
commit 93366827fc
22 changed files with 1740 additions and 320 deletions

View File

@@ -73,8 +73,8 @@ var instance_bullet
var instance_casing
var instance_mag
var reloading = false
var ammo
var ammo_reserve
var gun_ammo = {}
var ammo_reserve = {}
var bullet_damage
var def_weapon_holder_pos : Vector3
var weapon_holder_start_rot
@@ -358,11 +358,11 @@ func _physics_process(delta):
# Shooting & fire modes
if Input.is_action_pressed("shoot"):
if gun:
if gun != null:
gun.shoot(delta)
if Input.is_action_just_released("shoot"):
if gun:
if gun != null:
gun.cycle_count = gun.cycle_count_start
# Gun folding out of the way
@@ -469,6 +469,7 @@ func _physics_process(delta):
weapon_sway(delta)
weapon_bob(velocity.length(), delta)
## MOVEMENT
func joypad_walk():
# Joypad right stick look control
var dir_out = Vector2(0,0)
@@ -495,23 +496,6 @@ func joypad_look(delta):
head.rotate_x(-yAxis * JOYSTICK_SENSITIVITY * 1)
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-90), deg_to_rad(85))
func holster_gun(holster):
if holster:
gun_is_holstered = true
if gun != null:
holstered_gun_id = level_control.current_gun_index
gun.anim_player.play("swap_out")
else:
gun_is_holstered = false
if holstered_gun_id != null:
weapon_select(holstered_gun_id)
func flashlight_toggle():
if flashlight_on:
flashlight.light_energy = FLASHLIGHT_BRIGHTNESS
else:
flashlight.light_energy = 0
func crouch(delta):
if crouched:
crouching_collision.disabled = false
@@ -526,17 +510,6 @@ func crouch(delta):
head.position = lerp(head.position, STAND_POS, delta * 8)
speed = WALK_SPEED
func aim_down_sights(delta):
if gun:
if ads:
if gun.ads == true:
camera.fov = lerp(camera.fov,BASE_FOV - float(gun.fov_zoom_amt),(delta * 5)/Engine.time_scale)
gun.position = lerp(gun.position,ADS_POS,delta * 10 / Engine.time_scale)
else:
gun.position = lerp(gun.position, weapon_start_pos,delta * 2)
camera.fov = lerp(camera.fov,BASE_FOV - float(gun.fov_zoom_amt),(delta * 5)/Engine.time_scale)
func _headbob(time) -> Vector3:
var pos = Vector3.ZERO
pos.y = sin(time * BOB_FREQ) * BOB_AMP
@@ -546,86 +519,31 @@ func _headbob(time) -> Vector3:
footstep_sound.play()
return pos
func _on_pick_up_detection_body_entered(body):
if body.is_in_group("pickup"):
if body.pickupable:
body.picked_up()
if body.is_in_group("weapon_pickup"):
weapon_pickup_audio.play()
Input.start_joy_vibration(0,.1,.1,.1)
func ladder_collide():
if is_climbing == true:
gravity = 0.0
else:
gravity = default_gravity
func _on_pick_up_magnet_body_entered(body):
if body.is_in_group("pickup") and body.is_in_group("magnet"):
body.player_follow = self
body.collision_shape.disabled = true
func weapon_tilt(input_x, delta):
if !ads:
if weapon_holder:
weapon_holder.rotation.z = lerp(weapon_holder.rotation.z, -input_x * weapon_rotation_amount * 10, 4 * delta)
if camera:
camera.rotation.z = lerp(camera.rotation.z, -input_x * HEAD_TILT_AMT, 5 * delta)
func weapon_sway(delta):
if !ads:
var joy_input = Vector2(Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)*5,Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)*5)
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
joy_input = lerp(joy_input,Vector2.ZERO,10 * delta)
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, (mouse_input.y + joy_input.y) * weapon_sway_amount, 5 * delta)
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, (mouse_input.x + joy_input.x) * weapon_sway_amount, 5 * delta)
## VARIOUS ACTIONS
func flashlight_toggle():
if flashlight_on:
flashlight.light_energy = FLASHLIGHT_BRIGHTNESS
else:
if gun:
if gun.ads == true:
weapon_holder.rotation = Vector3.ZERO
flashlight.light_energy = 0
func weapon_bob(vel : float, delta):
if weapon_holder:
if vel > 2 and is_on_floor():
var speed_adjust = speed/WALK_SPEED
var bob_amount : float = 0.05
var bob_freq : float = 0.01 * speed_adjust
weapon_holder.position.y = lerp(weapon_holder.position.y, def_weapon_holder_pos.y + sin(Time.get_ticks_msec() * bob_freq) * bob_amount, speed * delta)
weapon_holder.position.x = lerp(weapon_holder.position.x, def_weapon_holder_pos.x + sin(Time.get_ticks_msec() * bob_freq) * bob_amount, speed * delta)
else:
weapon_holder.position.y = lerp(weapon_holder.position.y, def_weapon_holder_pos.y, .1 * delta)
weapon_holder.position.x = lerp(weapon_holder.position.x, def_weapon_holder_pos.x, .1 * delta)
func weapon_select(gun_id):
func aim_down_sights(delta):
if gun != null:
gun.anim_player.play("swap_out")
if gun_id != null:
level_control.gun_spawn(gun_id)
if ads:
if gun.ads == true:
camera.fov = lerp(camera.fov,BASE_FOV - float(gun.fov_zoom_amt),(delta * 5)/Engine.time_scale)
gun.position = lerp(gun.position,ADS_POS,delta * 10 / Engine.time_scale)
else:
gun.position = lerp(gun.position, weapon_start_pos,delta * 2)
camera.fov = lerp(camera.fov,BASE_FOV - float(gun.fov_zoom_amt),(delta * 5)/Engine.time_scale)
func enemy_hit():
var hitmarker_spawn = hitmarker.instantiate()
camera.add_child(hitmarker_spawn)
hit_indicator.play()
func enemy_killed():
if SaveLoad.enemies_killed:
SaveLoad.enemies_killed += 1
else:
SaveLoad.enemies_killed = 1
SaveLoad.save_persistent_data()
enemy_killed_audio.play()
func toggle_hud(hud_on):
if dead:
pass
else:
hud.visible = hud_on
func grab_moveable(body):
holster_gun(true)
held_item = body
@@ -670,7 +588,102 @@ func release_moveable():
held_item = null
hold_offset = null
moveable_holder.rotation = Vector3(0,0,0)
## GUNS AND AMMO
func holster_gun(holster):
if holster:
gun_is_holstered = true
if gun != null:
holstered_gun_id = level_control.current_gun_index
gun.anim_player.play("swap_out")
else:
gun_is_holstered = false
if holstered_gun_id != null:
weapon_select(holstered_gun_id)
func add_ammo(new_gun,gun_name,ammo_type,max_ammo,start_mags):
if new_gun:
gun_ammo[gun_name] = max_ammo
if ammo_reserve.has(str(ammo_type)):
ammo_reserve[str(ammo_type)] += start_mags * max_ammo
else:
ammo_reserve[str(ammo_type)] = start_mags * max_ammo
print("GUN AMMO ",gun_ammo)
print("RESERVE AMMO ", ammo_reserve)
## MISC
func _on_pick_up_detection_body_entered(body):
if body.is_in_group("pickup"):
if body.pickupable:
body.picked_up()
if body.is_in_group("weapon_pickup"):
weapon_pickup_audio.play()
Input.start_joy_vibration(0,.1,.1,.1)
func _on_pick_up_magnet_body_entered(body):
if body.is_in_group("pickup") and body.is_in_group("magnet"):
body.player_follow = self
body.collision_shape.disabled = true
func weapon_tilt(input_x, delta):
if !ads:
if weapon_holder:
weapon_holder.rotation.z = lerp(weapon_holder.rotation.z, -input_x * weapon_rotation_amount * 10, 4 * delta)
if camera:
camera.rotation.z = lerp(camera.rotation.z, -input_x * HEAD_TILT_AMT, 5 * delta)
func weapon_sway(delta):
if !ads:
var joy_input = Vector2(Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)*5,Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)*5)
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
joy_input = lerp(joy_input,Vector2.ZERO,10 * delta)
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, (mouse_input.y + joy_input.y) * weapon_sway_amount, 5 * delta)
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, (mouse_input.x + joy_input.x) * weapon_sway_amount, 5 * delta)
else:
if gun != null:
if gun.ads == true:
weapon_holder.rotation = Vector3.ZERO
func weapon_bob(vel : float, delta):
if weapon_holder:
if vel > 2 and is_on_floor():
var speed_adjust = speed/WALK_SPEED
var bob_amount : float = 0.05
var bob_freq : float = 0.01 * speed_adjust
weapon_holder.position.y = lerp(weapon_holder.position.y, def_weapon_holder_pos.y + sin(Time.get_ticks_msec() * bob_freq) * bob_amount, speed * delta)
weapon_holder.position.x = lerp(weapon_holder.position.x, def_weapon_holder_pos.x + sin(Time.get_ticks_msec() * bob_freq) * bob_amount, speed * delta)
else:
weapon_holder.position.y = lerp(weapon_holder.position.y, def_weapon_holder_pos.y, .1 * delta)
weapon_holder.position.x = lerp(weapon_holder.position.x, def_weapon_holder_pos.x, .1 * delta)
func weapon_select(gun_id):
if gun != null:
gun.anim_player.play("swap_out")
if gun_id != null:
level_control.gun_spawn(gun_id)
func enemy_hit():
var hitmarker_spawn = hitmarker.instantiate()
camera.add_child(hitmarker_spawn)
hit_indicator.play()
func enemy_killed():
if SaveLoad.enemies_killed:
SaveLoad.enemies_killed += 1
else:
SaveLoad.enemies_killed = 1
SaveLoad.save_persistent_data()
enemy_killed_audio.play()
func toggle_hud(hud_on):
hud.visible = hud_on
func hit(damage, fired_by, target_type):
SignalBus.emit_signal("player_hit")
level_control.health -= damage
@@ -693,6 +706,8 @@ func save():
"rot_y" : rotation.y,
"rot_z" : rotation.z,
"crouched" : crouched,
"flashlight_on" : flashlight_on
"flashlight_on" : flashlight_on,
"gun_ammo" : gun_ammo,
"ammo_reserve" : ammo_reserve
}
return save_dict