added crouch slide, disabled fov zoom on slow down for now

This commit is contained in:
derek
2024-12-09 12:56:04 -06:00
parent 6c16607956
commit a1518945d4
16 changed files with 152 additions and 43 deletions

View File

@@ -5,6 +5,8 @@ extends Control
var current_stam_bar
var stam_bar_visible : bool = false
var interact_visible : bool = false
var health_bar_start_pos
var money_count : int = 0
@onready var level_control = get_tree().current_scene
@onready var player = level_control.player
@@ -19,14 +21,18 @@ var interact_visible : bool = false
const FULL_WHITE = Color(1, 1, 1, 1)
const TRANSPARENT = Color(1, 1, 1, 0)
const RED_COLOR = Color(1, 0, 0)
const ORANGE_COLOR = Color(0.822, 0.318, 0.086)
const GREEN_COLOR = Color(0, 0.608, 0.172)
const STAM_BAR_MAX_OPACITY = .7
const STAM_BAR_MAX_OPACITY = 1.0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
SignalBus.player_hit.connect(player_hit)
health_bar.max_value = level_control.start_health
health_bar_start_pos = health_bar.position
if radial_stamina:
current_stam_bar = stamina_bar
stamina_bar_2.visible = false
@@ -42,24 +48,38 @@ func _process(delta: float) -> void:
health_bar.value = level_control.health
if level_control.health <= 2:
change_color(health_bar,RED_COLOR,10,delta)
health_bar.position += wiggle_element()
health_bar.position = health_bar_start_pos + shake_element(15)
elif level_control.health < ((level_control.start_health / 2) + 1):
change_color(health_bar,ORANGE_COLOR,10,delta)
else:
change_color(health_bar,FULL_WHITE,10,delta)
#MONEY
money.text = "$" + str(level_control.money)
if money_count < level_control.money:
money_count += 1
change_color(money,GREEN_COLOR,10,delta)
elif money_count > level_control.money:
change_color(money,RED_COLOR,10,delta)
money_count -= 1
else:
change_color(money,FULL_WHITE,10,delta)
money.text = "$" + str(money_count)
if player.remaining_stamina/player.MAX_STAMINA >= .99:
stam_bar_visible = false
else:
stam_bar_visible = true
current_stam_bar.value = player.remaining_stamina
ammo.text = str(level_control.ammo_current[level_control.current_gun_index]) +" - " + str(level_control.ammo_reserve[level_control.current_gun_index])
ammo.text = str(level_control.ammo_current[level_control.current_gun_index]) +" | " + str(level_control.ammo_reserve[level_control.current_gun_index])
if player.gun != null:
gun_name.text = player.gun.gun_name
else:
gun_name.visible = false
lerp_color(ammo,RED_COLOR,FULL_WHITE,level_control.ammo_current[level_control.current_gun_index],player.gun.max_ammo,.5)
if player.remaining_stamina < 25:
change_color(current_stam_bar,RED_COLOR,10,delta)
change_color(crosshair,RED_COLOR,10,delta)
@@ -81,20 +101,39 @@ func _process(delta: float) -> void:
else:
change_color(crosshair,FULL_WHITE,10,delta)
if player.ads:
if player.gun.ads:
fade_in_out(crosshair,1,false,5,delta)
else:
fade_in_out(crosshair,1,true,5,delta)
else:
fade_in_out(crosshair,1,true,5,delta)
## FADE ELEMENTS IN AND OUT
fade_in_out(current_stam_bar,STAM_BAR_MAX_OPACITY,stam_bar_visible,delta)
fade_in_out(current_stam_bar,STAM_BAR_MAX_OPACITY,stam_bar_visible,5,delta)
func wiggle_element():
var rand_x = randf_range(-5,5)
var rand_y = randf_range(-5,5)
func shake_element(amount):
var rand_x = randf_range(-amount,amount)
var rand_y = randf_range(-amount,amount)
return Vector2(rand_x,rand_y)
func lerp_color(element,colorA,colorB,cur_value,max_value,active_percent):
var value : float = float(cur_value)/float(max_value)
if value <= active_percent:
element.modulate = lerp(colorA,colorB,value)
else:
element.modulate = colorB
func change_color(element,color,speed,delta):
element.modulate = lerp(element.modulate, Color(color.r,color.g,color.b,element.modulate.a), (delta * speed)/Engine.time_scale)
func fade_in_out(element,MAX_OPACITY,visible,delta):
func fade_in_out(element,MAX_OPACITY,visible,speed,delta):
var element_color = element.modulate
if visible:
element.modulate = lerp(element_color, Color(element_color.r,element_color.g,element_color.b,MAX_OPACITY),(delta * 10)/Engine.time_scale)
element.modulate = lerp(element_color, Color(element_color.r,element_color.g,element_color.b,MAX_OPACITY),(delta * speed)/Engine.time_scale)
else:
element.modulate = lerp(element_color, Color(element_color.r,element_color.g,element_color.b,0),(delta * 10)/Engine.time_scale)
element.modulate = lerp(element_color, Color(element_color.r,element_color.g,element_color.b,0),(delta * speed)/Engine.time_scale)
func player_hit():
pass
#self.position += wiggle_element(25)

View File

@@ -47,7 +47,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 = .14
@export var weapon_sway_amount : float = .09
@export var weapon_rotation_amount : float = .07
@export_subgroup("FOV")
@export var BASE_FOV : float = 80
@@ -206,7 +206,16 @@ func _physics_process(delta):
velocity.y += JUMP_VELOCITY
double_jump = false
# Get the input direction and handle the movement/deceleration.
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
var direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
# Handle Sprint
if Input.is_action_just_pressed("sprint") and !is_on_floor():
if air_dash > 0:
velocity.x += direction.x * DASH_SPEED
velocity.z += direction.z * DASH_SPEED
air_dash -= 1
if Input.is_action_just_pressed("crouch"):
if crouched:
if !crouch_check.is_colliding():
@@ -220,19 +229,10 @@ func _physics_process(delta):
crouched = !crouched
recoil.add_recoil(Vector3(.2,0,0),5,10)
crouch_audio.play()
velocity.y -= 15
if is_on_floor():
velocity += direction * 20
# Get the input direction and handle the movement/deceleration.
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
var direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
# Handle Sprint
if Input.is_action_just_pressed("sprint") and !is_on_floor():
if air_dash > 0:
velocity.x += direction.x * DASH_SPEED
velocity.z += direction.z * DASH_SPEED
air_dash -= 1
print("AIR DASH " +str(air_dash))
#walking
if is_on_floor() and !is_climbing:
if direction:
@@ -293,22 +293,19 @@ func _physics_process(delta):
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)
Engine.time_scale = lerp(Engine.time_scale, SLOWSPEED, (delta * 50) / Engine.time_scale)
#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)
SENSITIVITY = lerp(SENSITIVITY, SENSITIVITY * .998, (delta * 100) / Engine.time_scale)
if remaining_stamina > 0:
remaining_stamina = clamp(remaining_stamina - ((delta * STAMINA_DRAIN)/Engine.time_scale),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)
Engine.time_scale = lerp(Engine.time_scale, 1.0, (delta * 50)/Engine.time_scale)
#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/Engine.time_scale), 0, MAX_STAMINA)
@@ -448,11 +445,9 @@ 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:
@@ -583,6 +578,7 @@ func release_moveable():
moveable_holder.rotation = Vector3(0,0,0)
func hit(damage, fired_by, target_type):
SignalBus.emit_signal("player_hit")
level_control.health -= damage
level_control.last_hit = fired_by
level_control.target_type = target_type

View File

@@ -7,3 +7,4 @@ signal enemy_killed()
signal king_killed()
signal enemy_count_changed()
signal game_loaded()
signal player_hit()