This commit is contained in:
Derek
2024-12-08 16:09:13 -06:00
parent f61807a572
commit c17ccea3e7
2 changed files with 68 additions and 31 deletions

View File

@@ -14,10 +14,10 @@ const CROUCHED_POS = Vector3(0,-.1,0)
const STAND_POS = Vector3(0,0.889,0)
const SLOWSPEED = .1
const MAX_STAMINA : float = 100
const STAMINA_DRAIN = 100 #multiplied times the delta when draining
const STAMINA_DRAIN = 20
const BOB_FREQ = 1.7
const BOB_AMP = 0.08
const ADS_POS = Vector3(0,-.05,-.45)
var speed
var double_jump = true
var air_dash = MAX_AIR_DASH
@@ -28,6 +28,7 @@ var default_gravity = gravity
var moving_fast = false
var moving_fast_top_speed = 0.0
var mouse_input : Vector2
var ads : bool
@export_group("Game Settings")
@export var AUDIO = true
@@ -40,7 +41,7 @@ var start_sensitivity
@export_subgroup("Head Bob & Gun Sway")
@export var t_bob = 1.0
@export var weapon_holder : Node3D
@export var weapon_sway_amount : float = .07
@export var weapon_sway_amount : float = .14
@export var weapon_rotation_amount : float = .07
@export_subgroup("FOV")
@export var BASE_FOV : float = 80
@@ -82,6 +83,10 @@ var hold_offset
var held_item_rotation = Vector3(0,0,0)
var gamespeed_controlled = false
var crouched = false
var flashlight_on : bool = false
##CACHED VARS
var weapon_start_pos
# Slow Down Variables
var remaining_stamina : float = MAX_STAMINA
@@ -124,10 +129,12 @@ var controlled_elsewhere = false
@onready var crouching_collision: CollisionShape3D = $CrouchingCollision
@onready var crouch_check: RayCast3D = $CrouchingCollision/CrouchCheck
@onready var hit_head: AudioStreamPlayer3D = $Audio/HitHead
@onready var crouch_audio: AudioStreamPlayer3D = $Audio/Crouch
@onready var hud: Control = $Head/Recoil/Camera3D/HUD
func _ready():
level_control.player = self
SignalBus.enemy_hit.connect(enemy_hit)
SignalBus.enemy_killed.connect(enemy_killed)
@@ -146,6 +153,9 @@ func _ready():
crt_filter.visible = false
#Cache vars
weapon_start_pos = weapon_spawner.position
#turn off audio if unchecked in player
if AUDIO == false:
AudioServer.set_bus_volume_db(0,-80)
@@ -192,13 +202,15 @@ func _physics_process(delta):
if crouched:
if !crouch_check.is_colliding():
crouched = !crouched
recoil.add_recoil(Vector3(-.2,.01,.01),5,10)
recoil.add_recoil(Vector3(-.2,.03,.03),5,10)
crouch_audio.play()
else:
recoil.add_recoil(Vector3(-.2,.01,.01),20,10)
recoil.add_recoil(Vector3(-.2,.03,.03),20,10)
hit_head.play()
else:
crouched = !crouched
recoil.add_recoil(Vector3(.2,0,0),5,10)
crouch_audio.play()
# Get the input direction and handle the movement/deceleration.
@@ -270,25 +282,27 @@ func _physics_process(delta):
# Game Speed
if !level_control.paused:
if Input.is_action_pressed("slow_down") and remaining_stamina > 0 :
ads = true
if !gamespeed_controlled:
Engine.time_scale = lerp(Engine.time_scale, SLOWSPEED, delta * 20)
gun.random_spread_amt = 0
#gun.random_spread_amt = 0
AudioServer.set_bus_effect_enabled(0,0,true)
camera.fov = lerp(camera.fov, camera.fov * gun.fov_zoom_amt, delta * 100)
if sensitivity_shift == true:
SENSITIVITY = lerp(SENSITIVITY, SENSITIVITY * .998, delta * 100)
if remaining_stamina > 0:
remaining_stamina = clamp(remaining_stamina - (delta * STAMINA_DRAIN),0,MAX_STAMINA)
remaining_stamina = clamp(remaining_stamina - ((delta * STAMINA_DRAIN)/Engine.time_scale),0,MAX_STAMINA)
else:
ads = false
if !gamespeed_controlled:
Engine.time_scale = lerp(Engine.time_scale, 1.0, delta * 50)
gun.random_spread_amt = gun.random_spread_start
#gun.random_spread_amt = gun.random_spread_start
AudioServer.set_bus_effect_enabled(0,0,false)
if sensitivity_shift == true:
camera.fov = lerp(camera.fov, BASE_FOV, delta * .5)
SENSITIVITY = start_sensitivity
if remaining_stamina < MAX_STAMINA and !Input.is_action_pressed("slow_down"):
remaining_stamina = clamp(remaining_stamina + (delta * STAMINA_DRAIN/10), 0, MAX_STAMINA)
remaining_stamina = clamp(remaining_stamina + (delta * STAMINA_DRAIN/Engine.time_scale), 0, MAX_STAMINA)
# Reloading
@@ -299,20 +313,22 @@ func _physics_process(delta):
gun.anim_player.play("inspect")
if Input.is_action_just_pressed("flashlight"):
flashlight_audio.play()
if flashlight.light_energy == 0:
while flashlight.light_energy != FLASHLIGHT_BRIGHTNESS:
flashlight.light_energy = FLASHLIGHT_BRIGHTNESS
elif flashlight.light_energy > 0:
flashlight.light_energy = 0
if flashlight_on:
flashlight_on = false
flashlight_audio.play()
else:
flashlight_on = true
flashlight_audio.play()
# Shooting & fire modes
if Input.is_action_pressed("shoot"):
gun.shoot(delta)
if gun:
gun.shoot(delta)
if Input.is_action_just_released("shoot"):
gun.cycle_count = gun.cycle_count_start
if gun:
gun.cycle_count = gun.cycle_count_start
# Gun folding out of the way
if gun_ray.is_colliding():
@@ -377,6 +393,8 @@ func _physics_process(delta):
if level_control.health <= 0:
level_control.die()
aim_down_sights(delta)
flashlight_toggle()
hold_item(delta)
move_and_slide()
crouch(delta)
@@ -384,6 +402,12 @@ func _physics_process(delta):
weapon_sway(delta)
weapon_bob(velocity.length(), delta)
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
@@ -398,6 +422,17 @@ func crouch(delta):
head.position = lerp(head.position, STAND_POS, delta * 8)
speed = WALK_SPEED
func aim_down_sights(delta):
if gun:
if gun.ads == true:
if ads:
crosshair.visible = false
camera.fov -= .1
gun.position = lerp(gun.position,ADS_POS,delta * 10 / Engine.time_scale)
else:
crosshair.visible = true
gun.position = lerp(gun.position, weapon_start_pos,delta * 2)
func _headbob(time) -> Vector3:
var pos = Vector3.ZERO
pos.y = sin(time * BOB_FREQ) * BOB_AMP
@@ -434,9 +469,10 @@ func weapon_tilt(input_x, delta):
camera.rotation.z = lerp(camera.rotation.z, -input_x * .075, 5 * delta)
func weapon_sway(delta):
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_sway_amount, 5 * delta)
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_sway_amount, 5 * delta)
if !ads:
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_sway_amount, 5 * delta)
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_sway_amount, 5 * delta)
func weapon_bob(vel : float, delta):
if weapon_holder:
@@ -451,9 +487,12 @@ func weapon_bob(vel : float, delta):
weapon_holder.position.x = lerp(weapon_holder.position.x, def_weapon_holder_pos.x, .1 * delta)
func weapon_select(gun_id):
if !gun.anim_player.is_playing():
if level_control.held_guns.size() >= (gun_id + 1) and level_control.current_gun_index != gun_id:
gun.anim_player.play("swap_out")
if gun != null:
if !gun.anim_player.is_playing():
if level_control.held_guns.size() >= (gun_id + 1) and level_control.current_gun_index != gun_id:
gun.anim_player.play("swap_out")
level_control.gun_spawn(gun_id)
else:
level_control.gun_spawn(gun_id)
func enemy_hit():
@@ -471,13 +510,10 @@ func enemy_killed():
enemy_killed_audio.play()
func toggle_hud(hud_on):
if dead:
crt_filter.visible = false#hud_on
crt_filter.visible = false
else:
crosshair.visible = hud_on
ammo_counter.visible = hud_on
stamina_counter.visible = hud_on
hud.visible = hud_on
func grab_moveable(body):
held_item = body
@@ -542,7 +578,7 @@ func save():
"rot_x" : rotation.x,
"rot_y" : rotation.y,
"rot_z" : rotation.z,
"health" : level_control.health
"crouched" : crouched,
"flashlight_on" : flashlight_on
}
return save_dict

View File

@@ -10,6 +10,7 @@ var cycle_count
@export var gun_name : String
@export_enum("Auto", "Single", "Burst") var fire_mode: int
@export var fov_zoom_amt = .98
@export var ads : bool = false
@export var recoil_amount : Vector3 = Vector3(1,.1,.1)
@export var recoil_speed_change : float = 4
@export var max_ammo = 15