ammo rework seems to mostly be in order
This commit is contained in:
@@ -103,14 +103,12 @@ func refresh_scene():
|
||||
if gun_1 != null:
|
||||
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
|
||||
player.add_ammo(true,instance_gun.gun_name,instance_gun.ammo_type,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)
|
||||
player.add_ammo(true,instance_gun_2.gun_name,instance_gun_2.ammo_type,instance_gun_2.max_ammo,instance_gun_2.start_mags)
|
||||
|
||||
# Spawn first gun
|
||||
if gun_1 != null:
|
||||
@@ -123,7 +121,6 @@ func _process(_delta):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
func gun_spawn(index):
|
||||
|
||||
#loop around if scrolling past available guns
|
||||
@@ -139,9 +136,7 @@ func gun_spawn(index):
|
||||
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)
|
||||
@@ -198,20 +193,6 @@ func pickup_spawn():
|
||||
item_spawn.rand_amt = randi_range(25,100)
|
||||
return item_spawn
|
||||
|
||||
#func pause_menu():
|
||||
#if paused:
|
||||
#get_tree().paused = false
|
||||
#Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
#player.toggle_hud(true)
|
||||
#player.pause_menu.hide()
|
||||
#else:
|
||||
#get_tree().paused = true
|
||||
#Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
#player.toggle_hud(false)
|
||||
#player.pause_menu.show()
|
||||
#
|
||||
#paused = !paused
|
||||
|
||||
func save_quit():
|
||||
SaveLoad.save_game_data(level_name)
|
||||
get_tree().quit()
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
extends Resource
|
||||
class_name ammo_stats
|
||||
|
||||
@export_enum("Light", "Medium", "Heavy", "Shotgun", "Rocket") var ammo_type: int
|
||||
@@ -9,6 +9,7 @@ var cycle_count
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
@export var gun_icon : Texture2D
|
||||
@export_enum("Light", "Medium", "Heavy", "Shotgun", "Rocket") var ammo_type: int
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var fov_zoom_amt = .98
|
||||
@export var ads : bool = false
|
||||
@@ -55,10 +56,6 @@ func _ready():
|
||||
start_rotation = self.rotation
|
||||
random_spread_start = random_spread_amt
|
||||
|
||||
#ammo_current = level_control.ammo_current[gun_index]
|
||||
#ammo_reserve = level_control.ammo_reserve[gun_index]
|
||||
|
||||
|
||||
if fire_mode == 0:
|
||||
cycle_count = 1
|
||||
cycle_count_start = 1
|
||||
@@ -77,17 +74,17 @@ func _process(_delta):
|
||||
|
||||
|
||||
func reload_finished():
|
||||
if level_control.ammo_reserve[gun_index] >= max_ammo:
|
||||
level_control.ammo_current[gun_index] += max_ammo
|
||||
level_control.ammo_reserve[gun_index] -= max_ammo
|
||||
if player.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
player.gun_ammo[gun_name] += max_ammo
|
||||
player.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
|
||||
else:
|
||||
level_control.ammo_current[gun_index] += level_control.ammo_reserve[gun_index]
|
||||
level_control.ammo_reserve[gun_index] -= level_control.ammo_reserve[gun_index]
|
||||
player.gun_ammo[gun_name] += player.ammo_reserve[str(ammo_type)]
|
||||
player.ammo_reserve[str(ammo_type)] -= player.ammo_reserve[str(ammo_type)]
|
||||
|
||||
|
||||
func shoot(delta):
|
||||
if level_control.ammo_current[gun_index] > 0:
|
||||
if player.gun_ammo[gun_name] > 0:
|
||||
if !anim_player.is_playing():
|
||||
anim_player.play("shoot")
|
||||
elif !anim_player.is_playing() and cycle_count != 0:
|
||||
@@ -95,7 +92,7 @@ func shoot(delta):
|
||||
audio_empty.play()
|
||||
|
||||
func fire():
|
||||
level_control.ammo_current[gun_index] -= 1
|
||||
player.gun_ammo[gun_name] -= 1
|
||||
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
|
||||
audio_fire.play()
|
||||
pellet_spawn()
|
||||
@@ -109,15 +106,15 @@ func fire():
|
||||
SignalBus.emit_signal("shot_fired")
|
||||
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
if player.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and player.ammo_reserve[str(ammo_type)] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
if level_control.ammo_current[gun_index] == 0:
|
||||
level_control.ammo_current[gun_index] = 0
|
||||
if player.gun_ammo[gun_name] == 0:
|
||||
player.gun_ammo[gun_name] = 0
|
||||
else:
|
||||
level_control.ammo_current[gun_index] = 1
|
||||
player.gun_ammo[gun_name] = 1
|
||||
|
||||
func pellet_spawn():
|
||||
var pellets_remaining = pellets_per_shot
|
||||
|
||||
@@ -4,7 +4,9 @@ extends Node3D
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
@export var gun_icon : Texture2D
|
||||
@export_enum("Light", "Medium", "Heavy", "Shotgun", "Rocket") var ammo_type: int
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var gun_info : gun_stats
|
||||
@export var hitscan_enabled : bool = false
|
||||
@export var fov_zoom_amt = .98
|
||||
@export var ads : bool = false
|
||||
@@ -42,7 +44,6 @@ extends Node3D
|
||||
@onready var player = get_tree().current_scene.player
|
||||
@onready var level_control = get_tree().current_scene
|
||||
@onready var muzzle_smoke = preload("res://assets/muzzle_smoke.tscn")
|
||||
@onready var ammo_current
|
||||
|
||||
var start_position
|
||||
var start_rotation
|
||||
@@ -74,18 +75,19 @@ func _process(_delta):
|
||||
|
||||
|
||||
func reload_finished():
|
||||
if level_control.ammo_reserve[gun_index] >= max_ammo:
|
||||
level_control.ammo_current[gun_index] += max_ammo
|
||||
level_control.ammo_reserve[gun_index] -= max_ammo
|
||||
if player.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
player.gun_ammo[gun_name] += max_ammo
|
||||
player.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
else:
|
||||
level_control.ammo_current[gun_index] += level_control.ammo_reserve[gun_index]
|
||||
level_control.ammo_reserve[gun_index] -= level_control.ammo_reserve[gun_index]
|
||||
player.gun_ammo[gun_name] += player.ammo_reserve[str(ammo_type)]
|
||||
player.ammo_reserve[str(ammo_type)] -= player.ammo_reserve[str(ammo_type)]
|
||||
|
||||
func shoot(delta):
|
||||
|
||||
if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
|
||||
print("GUN AMMO: ",player.gun_ammo)
|
||||
print("RESERVE AMMO: ",player.ammo_reserve)
|
||||
if player.gun_ammo[gun_name] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
level_control.ammo_current[gun_index] -= 1
|
||||
player.gun_ammo[gun_name] -= 1
|
||||
#audio and anims
|
||||
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
|
||||
audio_fire.play()
|
||||
@@ -108,15 +110,15 @@ func shoot(delta):
|
||||
audio_empty.play()
|
||||
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
if player.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and player.ammo_reserve[str(ammo_type)] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
if level_control.ammo_current[gun_index] == 0:
|
||||
level_control.ammo_current[gun_index] = 0
|
||||
if player.gun_ammo[gun_name] == 0:
|
||||
player.gun_ammo[gun_name] = 0
|
||||
else:
|
||||
level_control.ammo_current[gun_index] = 1
|
||||
player.gun_ammo[gun_name] = 1
|
||||
|
||||
func spawn_mag():
|
||||
var instance_mag = mag.instantiate()
|
||||
|
||||
19
scripts/gun_stats_resource.gd
Normal file
19
scripts/gun_stats_resource.gd
Normal file
@@ -0,0 +1,19 @@
|
||||
extends Resource
|
||||
class_name gun_stats
|
||||
|
||||
@export var gun_name : String
|
||||
@export var gun_icon : Texture2D
|
||||
@export_enum("Light", "Medium", "Heavy", "Shotgun", "Rocket") var ammo_type: int
|
||||
@export var fov_zoom_amt = .98
|
||||
@export var use_ads : bool = false
|
||||
@export var recoil_amount : Vector3 = Vector3(.2,.05,.05)
|
||||
@export var kick_amount : float = .1
|
||||
@export var max_ammo = 15
|
||||
@export var start_mags = 3
|
||||
@export var bullet_damage = 1
|
||||
@export var smoke_enabled : bool = false
|
||||
@export var bullet_force_mod = 5.0
|
||||
@export var bullet_speed = 150
|
||||
@export var bullet_drop = .3
|
||||
@export var random_spread_amt = 1.0
|
||||
@export var fire_pitch_scale_amt = .2
|
||||
@@ -106,17 +106,19 @@ func _process(delta: float) -> void:
|
||||
current_stam_bar.value = player.remaining_stamina
|
||||
|
||||
if player.gun != null:
|
||||
ammo_current.text = str(level_control.ammo_current[level_control.current_gun_index]).pad_zeros(2)
|
||||
ammo_reserve.text = str(level_control.ammo_reserve[level_control.current_gun_index]).pad_zeros(3)
|
||||
lerp_color(ammo_current,RED_COLOR,FULL_WHITE,level_control.ammo_current[level_control.current_gun_index],player.gun.max_ammo,.5)
|
||||
lerp_color(ammo_reserve,RED_COLOR,FULL_WHITE,level_control.ammo_reserve[level_control.current_gun_index],player.gun.max_ammo*2,.5)
|
||||
if player.gun_ammo.has(player.gun.gun_name):
|
||||
ammo_current.text = str(player.gun_ammo[player.gun.gun_name]).pad_zeros(2)
|
||||
lerp_color(ammo_current,RED_COLOR,FULL_WHITE,player.gun_ammo[player.gun.gun_name],player.gun.max_ammo,.5)
|
||||
if player.ammo_reserve.has(str(player.gun.ammo_type)):
|
||||
ammo_reserve.text = str(player.ammo_reserve[str(player.gun.ammo_type)]).pad_zeros(3)
|
||||
lerp_color(ammo_reserve,RED_COLOR,FULL_WHITE,player.ammo_reserve[str(player.gun.ammo_type)],player.gun.max_ammo*2,.5)
|
||||
else:
|
||||
fade_in_out(ammo_current,1,false,10,delta)
|
||||
fade_in_out(ammo_reserve,1,false,10,delta)
|
||||
fade_in_out(crosshair,1,false,10,delta)
|
||||
|
||||
if player.gun != null:
|
||||
gun_name.text = player.gun.gun_name
|
||||
gun_name.visible = true
|
||||
else:
|
||||
gun_name.visible = false
|
||||
|
||||
@@ -143,7 +145,7 @@ func _process(delta: float) -> void:
|
||||
change_color(crosshair,FULL_WHITE,10,delta)
|
||||
|
||||
if player.ads:
|
||||
if player.gun:
|
||||
if player.gun != null:
|
||||
if player.gun.ads:
|
||||
fade_in_out(crosshair,1,false,5,delta)
|
||||
fade_in_out(current_stam_bar,.001,true,5,delta)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -9,6 +9,7 @@ var cycle_count
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
@export var gun_icon : Texture2D
|
||||
@export_enum("Light", "Medium", "Heavy", "Shotgun", "Rocket") var ammo_type: int
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var fov_zoom_amt = 10
|
||||
@export var ads : bool = false
|
||||
@@ -101,9 +102,9 @@ func _process(delta):
|
||||
|
||||
func reload_finished():
|
||||
#if max ammo in reserve fill all the way
|
||||
if level_control.ammo_reserve[gun_index] >= max_ammo:
|
||||
level_control.ammo_current[gun_index] += max_ammo
|
||||
level_control.ammo_reserve[gun_index] -= max_ammo
|
||||
if player.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
player.gun_ammo[gun_name] += max_ammo
|
||||
player.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
casings_chamber_last = max_ammo
|
||||
for i in casing_array:
|
||||
i.visible = true
|
||||
@@ -112,10 +113,10 @@ func reload_finished():
|
||||
player.reloading = false
|
||||
#if not max ammo in reserve add remaining ammo
|
||||
else:
|
||||
level_control.ammo_current[gun_index] += level_control.ammo_reserve[gun_index]
|
||||
var casings_in_chamber = level_control.ammo_reserve[gun_index]
|
||||
casings_chamber_last = level_control.ammo_reserve[gun_index]
|
||||
level_control.ammo_reserve[gun_index] -= level_control.ammo_reserve[gun_index]
|
||||
player.gun_ammo[gun_name] += player.ammo_reserve[str(ammo_type)]
|
||||
var casings_in_chamber = player.ammo_reserve[str(ammo_type)]
|
||||
casings_chamber_last = player.ammo_reserve[str(ammo_type)]
|
||||
player.ammo_reserve[str(ammo_type)] -= player.ammo_reserve[str(ammo_type)]
|
||||
|
||||
while casings_in_chamber > 0:
|
||||
casing_array[casings_in_chamber].visible = true
|
||||
@@ -125,9 +126,9 @@ func reload_finished():
|
||||
player.reloading = false
|
||||
|
||||
func shoot(delta):
|
||||
if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
|
||||
if player.gun_ammo[gun_name] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
level_control.ammo_current[gun_index] -= 1
|
||||
player.gun_ammo[gun_name] -= 1
|
||||
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
|
||||
audio_fire.play()
|
||||
anim_player.play("shoot") #actual bullet spawn triggered by animation
|
||||
@@ -162,13 +163,13 @@ func fire(delta):
|
||||
Input.start_joy_vibration(0,.5,.9,.2)
|
||||
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
if player.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and player.ammo_reserve[str(ammo_type)] > 0:
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
for i in bullet_array:
|
||||
i.visible = false
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
level_control.ammo_current[gun_index] = 0
|
||||
player.gun_ammo[gun_name] = 0
|
||||
|
||||
func spawn_casings():
|
||||
for i in casing_array:
|
||||
|
||||
@@ -10,6 +10,7 @@ var ads = false
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
@export var gun_icon : Texture2D
|
||||
@export_enum("Light", "Medium", "Heavy", "Shotgun", "Rocket") var ammo_type: int
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var fov_zoom_amt = .98
|
||||
@export var recoil_amount : Vector3 = Vector3(.2,0,0)
|
||||
@@ -67,20 +68,20 @@ func _process(_delta):
|
||||
|
||||
|
||||
func reload_finished():
|
||||
if level_control.ammo_reserve[gun_index] >= max_ammo:
|
||||
level_control.ammo_current[gun_index] += max_ammo
|
||||
level_control.ammo_reserve[gun_index] -= max_ammo
|
||||
if player.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
player.gun_ammo[gun_name] += max_ammo
|
||||
player.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
|
||||
else:
|
||||
level_control.ammo_current[gun_index] += level_control.ammo_reserve[gun_index]
|
||||
level_control.ammo_reserve[gun_index] -= level_control.ammo_reserve[gun_index]
|
||||
player.gun_ammo[gun_name] += player.ammo_reserve[str(ammo_type)]
|
||||
player.ammo_reserve[str(ammo_type)] -= player.ammo_reserve[str(ammo_type)]
|
||||
|
||||
|
||||
func shoot(delta):
|
||||
|
||||
if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
|
||||
if player.gun_ammo[gun_name] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
level_control.ammo_current[gun_index] -= 1
|
||||
player.gun_ammo[gun_name] -= 1
|
||||
#RECOIL --- fix later to happen over a period of time
|
||||
#(ADD PLAYER KICK HERE. RELATIVE TO GUN POSITION)
|
||||
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
|
||||
@@ -106,15 +107,15 @@ func shoot(delta):
|
||||
audio_empty.play()
|
||||
|
||||
func reload():
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
if player.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and player.ammo_reserve[str(ammo_type)] > 0:
|
||||
#player.reloading = true
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
if level_control.ammo_current[gun_index] == 0:
|
||||
level_control.ammo_current[gun_index] = 0
|
||||
if player.gun_ammo[gun_name] == 0:
|
||||
player.gun_ammo[gun_name] = 0
|
||||
else:
|
||||
level_control.ammo_current[gun_index] = 1
|
||||
player.gun_ammo[gun_name] = 1
|
||||
|
||||
func spawn_mag():
|
||||
var instance_mag = mag.instantiate()
|
||||
|
||||
@@ -74,16 +74,14 @@ func save_game_data(level_name):
|
||||
player_money = level_control.money
|
||||
held_guns = save_resource_path(level_control.held_guns)
|
||||
current_gun = level_control.current_gun_index
|
||||
current_ammo = level_control.ammo_current
|
||||
reserve_ammo = level_control.ammo_reserve
|
||||
current_ammo = player.gun_ammo
|
||||
reserve_ammo = player.ammo_reserve
|
||||
|
||||
#SAVE DATA
|
||||
file.store_var(player_health)
|
||||
file.store_var(player_money)
|
||||
file.store_var(held_guns)
|
||||
file.store_var(current_gun)
|
||||
file.store_var(current_ammo)
|
||||
file.store_var(reserve_ammo)
|
||||
|
||||
#save enemies
|
||||
var objects = get_tree().get_nodes_in_group("persist")
|
||||
@@ -138,8 +136,6 @@ func load_save_game_data(level_name):
|
||||
var held_guns_encoded = file.get_var()
|
||||
held_guns = load_resource_path(held_guns_encoded)
|
||||
current_gun = file.get_var()
|
||||
current_ammo = file.get_var()
|
||||
reserve_ammo = file.get_var()
|
||||
var current_nodes = get_tree().get_nodes_in_group("persist")
|
||||
for i in current_nodes:
|
||||
if i.is_in_group("enemy"):
|
||||
@@ -181,8 +177,6 @@ func load_save_game_data(level_name):
|
||||
player.gun.queue_free()
|
||||
if current_gun != null:
|
||||
level_control.gun_spawn(current_gun)
|
||||
level_control.ammo_current = current_ammo
|
||||
level_control.ammo_reserve = reserve_ammo
|
||||
|
||||
file.close()
|
||||
await get_tree().create_timer(1).timeout #need to fix this
|
||||
|
||||
@@ -4,6 +4,7 @@ extends Node3D
|
||||
@export_group("Gun Feel")
|
||||
@export var gun_name : String
|
||||
@export var gun_icon : Texture2D
|
||||
@export_enum("Light", "Medium", "Heavy", "Shotgun", "Rocket") var ammo_type: int
|
||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||
@export var hitscan_enabled : bool = false
|
||||
@export var ads : bool = false
|
||||
@@ -92,12 +93,12 @@ func _process(_delta):
|
||||
|
||||
|
||||
func reload_finished():
|
||||
if level_control.ammo_reserve[gun_index] >= max_ammo:
|
||||
level_control.ammo_current[gun_index] += max_ammo
|
||||
level_control.ammo_reserve[gun_index] -= max_ammo
|
||||
if player.ammo_reserve[str(ammo_type)] >= max_ammo:
|
||||
player.gun_ammo[gun_name] += max_ammo
|
||||
player.ammo_reserve[str(ammo_type)] -= max_ammo
|
||||
else:
|
||||
level_control.ammo_current[gun_index] += level_control.ammo_reserve[gun_index]
|
||||
level_control.ammo_reserve[gun_index] -= level_control.ammo_reserve[gun_index]
|
||||
player.gun_ammo[gun_name] += player.ammo_reserve[str(ammo_type)]
|
||||
player.ammo_reserve[str(ammo_type)] -= player.ammo_reserve[str(ammo_type)]
|
||||
|
||||
func shoot(delta):
|
||||
if !anim_player.is_playing():
|
||||
@@ -110,9 +111,9 @@ func shoot(delta):
|
||||
|
||||
|
||||
func fire():
|
||||
if level_control.ammo_current[gun_index] > 0 and cycle_count > 0:
|
||||
if player.gun_ammo[gun_name] > 0 and cycle_count > 0:
|
||||
if !anim_player.is_playing():
|
||||
level_control.ammo_current[gun_index] -= 1
|
||||
player.gun_ammo[gun_name] -= 1
|
||||
#audio and anims
|
||||
audio_fire.pitch_scale = 1 + rng.randf_range(-fire_pitch_scale_amt,fire_pitch_scale_amt)
|
||||
audio_fire.play()
|
||||
@@ -160,7 +161,7 @@ func remove_tracker():
|
||||
tracker = null
|
||||
|
||||
func check_ammo():
|
||||
if level_control.ammo_current[gun_index] == 0 and level_control.ammo_reserve[gun_index] > 0:
|
||||
if player.gun_ammo[gun_name] == 0 and player.ammo_reserve[str(ammo_type)] > 0:
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
|
||||
@@ -168,15 +169,15 @@ func reload():
|
||||
if tracker != null:
|
||||
anim_player.play("remove_tracker")
|
||||
else:
|
||||
if level_control.ammo_current[gun_index] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and level_control.ammo_reserve[gun_index] > 0:
|
||||
if player.gun_ammo[gun_name] < max_ammo and player.gun.anim_player.get_current_animation() != "reload" and player.ammo_reserve[str(ammo_type)] > 0:
|
||||
anim_player.play("reload")
|
||||
audio_reload.play()
|
||||
remove_tracker()
|
||||
if anim_player.is_playing() and anim_player.current_animation == "reload":
|
||||
if level_control.ammo_current[gun_index] == 0:
|
||||
level_control.ammo_current[gun_index] = 0
|
||||
if player.gun_ammo[gun_name] == 0:
|
||||
player.gun_ammo[gun_name] = 0
|
||||
else:
|
||||
level_control.ammo_current[gun_index] = 1
|
||||
player.gun_ammo[gun_name] = 1
|
||||
|
||||
func spawn_mag():
|
||||
var instance_mag = mag.instantiate()
|
||||
|
||||
@@ -24,6 +24,8 @@ func picked_up():
|
||||
gun_already_held = true
|
||||
|
||||
if !gun_already_held:
|
||||
var gun_info = gun_resource.instantiate()
|
||||
level_control.player.add_ammo(true,gun_info.gun_name,gun_info.ammo_type,gun_info.max_ammo,gun_info.start_mags)
|
||||
level_control.held_guns.append(gun_resource)
|
||||
var instance_gun = gun_resource.instantiate()
|
||||
level_control.ammo_current.append(instance_gun.max_ammo)
|
||||
|
||||
Reference in New Issue
Block a user