added functionality for various game modes

This commit is contained in:
Derek
2025-02-21 23:19:25 -06:00
parent 9cb57824b1
commit 777063ddeb
19 changed files with 809 additions and 183 deletions

View File

@@ -1,23 +1,16 @@
extends CharacterBody3D
const JUMP_VELOCITY = 5
const JUMP_WEAPON_DIP = Vector3(0,-5,0)
const AIR_TRANSITION_SPEED = 7
const GROUND_TRANSITION_SPEED = 4
const MAX_AIR_DASH = 1
const GROUND_TRANSITION_SPEED = 7
const FLASHLIGHT_BRIGHTNESS = 30
const KICK_AMOUNT = 20
const LAND_CAMERA_TILT : Vector3 = Vector3(-1,0,0)
const WALK_SPEED = 12.0
const CROUCH_SPEED = 3.0
const SPRINT_SPEED = 15.0
const DASH_SPEED = 40
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 = 20
const HEAD_TILT_AMT = .06
const BOB_FREQ = 1.7
const BOB_AMP = 0.1
@@ -34,11 +27,10 @@ const L_JOYSTICK_SENSITIVITY = .1
var speed
var walk_transition_speed
var double_jump = true
var air_dash = MAX_AIR_DASH
var gravity = 9.8
var air_dash
var gravity
var is_climbing = false
var ladder_center
var default_gravity = gravity
var moving_fast = false
var moving_fast_top_speed = 0.0
var mouse_input : Vector2
@@ -113,7 +105,7 @@ var weapon_start_pos
var held_key_check = 0.0
# Slow Down Variables
var remaining_stamina : float = MAX_STAMINA
@onready var remaining_stamina : float = level_control.gamemode.max_stamina
# Wall Jump
var can_wall_jump = true
@@ -164,12 +156,13 @@ var controlled_elsewhere = false
@onready var weapon_select_menu: Control = $Head/Recoil/Camera3D/WeaponSelect
@onready var wall_jump_timer: Timer = $WallJumpTimer
func _ready():
level_control.player = self
SignalBus.enemy_hit.connect(enemy_hit)
SignalBus.enemy_killed.connect(enemy_killed)
air_dash = level_control.gamemode.air_dash_max
weapon_holder_start_rot = weapon_holder.rotation
weapon_holder_start_pos = weapon_holder.position
@@ -181,7 +174,7 @@ func _ready():
health_indicator.size = Vector2(viewportWidth,viewportHeight)
health_indicator.color = Color(0.471, 0, 0, 0)
speed = WALK_SPEED
speed = level_control.gamemode.walk_speed
motion_lines.visible = false
@@ -218,9 +211,9 @@ func _physics_process(delta):
# Add the gravity.
if is_on_floor():
double_jump = true
air_dash = MAX_AIR_DASH
air_dash = level_control.gamemode.air_dash_max
else:
velocity.y -= gravity * delta
velocity.y += level_control.gamemode.gravity * delta
if abs(velocity.y) >= .1:
moving_fast = true
@@ -228,13 +221,13 @@ func _physics_process(delta):
# Handle jump.
if Input.is_action_just_pressed("jump"):
if is_on_floor() and !is_climbing:
velocity.y += JUMP_VELOCITY
velocity.y += level_control.gamemode.jump_velocity
weapon_dip_pos += JUMP_WEAPON_DIP
crouched = false
elif wall_jump():
velocity += Vector3(velocity.x * 5,12,velocity.z * 5)
elif double_jump == true and !is_climbing:
velocity.y += JUMP_VELOCITY
velocity.y += level_control.gamemode.jump_velocity
double_jump = false
## HANDLE MOVEMENT DIRECTION
@@ -252,8 +245,8 @@ func _physics_process(delta):
# 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
velocity.x += direction.x * level_control.gamemode.dash_speed
velocity.z += direction.z * level_control.gamemode.dash_speed
air_dash -= 1
if Input.is_action_pressed("move_left"):
@@ -286,13 +279,12 @@ func _physics_process(delta):
#walking
if is_on_floor() and !is_climbing:
walk_transition_speed = AIR_TRANSITION_SPEED
if direction:
velocity.x = lerp(velocity.x, direction.x * speed, delta * walk_transition_speed)
velocity.z = lerp(velocity.z, direction.z * speed, delta * walk_transition_speed)
velocity.x = lerp(velocity.x, direction.x * speed, delta * GROUND_TRANSITION_SPEED)
velocity.z = lerp(velocity.z, direction.z * speed, delta * GROUND_TRANSITION_SPEED)
else:
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5) + (direction.x * DASH_SPEED)
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5) + (direction.z * DASH_SPEED)
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5) + (direction.x * level_control.gamemode.dash_speed)
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5) + (direction.z * level_control.gamemode.dash_speed)
#ladder movement
elif is_climbing and !is_on_floor():
gravity = 0.0
@@ -304,8 +296,8 @@ func _physics_process(delta):
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
#movement in air
else:
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
velocity.x = lerp(velocity.x, direction.x * speed, delta * AIR_TRANSITION_SPEED)
velocity.z = lerp(velocity.z, direction.z * speed, delta * AIR_TRANSITION_SPEED)
## Wall Running
if wall_ray_1.is_colliding() or wall_ray_2.is_colliding():
if abs(Vector2(velocity.x,velocity.z)) >= Vector2(5.0,5.0):
@@ -322,9 +314,11 @@ func _physics_process(delta):
camera.fov = lerp(camera.fov, target_fov, delta * 8)
# Health Indicator
var health_opacity = 1.5 - level_control.health / level_control.start_health
if level_control.health < (level_control.start_health/2):
var health_opacity = 1.5 - level_control.health / level_control.gamemode.start_health
if level_control.health < (level_control.gamemode.start_health/2):
health_indicator.color = lerp(Color(0.471, 0, 0, 0), Color(0.471, 0, 0, .25),health_opacity)
else:
health_indicator.color = Color(0.471, 0, 0, 0)
# Moving Fast Sound
var wind_volume = clamp(velocity.length()/20,0,1) #expected max velocity for effect
@@ -356,14 +350,14 @@ 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 * 50) / Engine.time_scale)
Engine.time_scale = lerp(Engine.time_scale, level_control.gamemode.time_slowed_speed, (delta * 50) / Engine.time_scale)
#gun.random_spread_amt = 0
AudioServer.set_bus_effect_enabled(0,0,true)
clock_sound.play()
if sensitivity_shift == true:
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 * level_control.gamemode.stamina_drain) / Engine.time_scale),0,level_control.gamemode.max_stamina)
else:
ads = false
if !gamespeed_controlled:
@@ -372,8 +366,9 @@ func _physics_process(delta):
clock_sound.stop()
AudioServer.set_bus_effect_enabled(0,0,false)
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)
if remaining_stamina < level_control.gamemode.max_stamina and !Input.is_action_pressed("slow_down"):
if level_control.gamemode.stamina_regen == true:
remaining_stamina = clamp(remaining_stamina + (delta * level_control.gamemode.stamina_drain/Engine.time_scale), 0, level_control.gamemode.max_stamina)
# Reloading
@@ -562,7 +557,7 @@ func crouch(delta):
crouching_collision.disabled = true
if head.position != STAND_POS:
head.position = lerp(head.position, STAND_POS, delta * 8)
speed = WALK_SPEED
speed = level_control.gamemode.walk_speed
func _headbob(time) -> Vector3:
var pos = Vector3.ZERO
@@ -578,7 +573,7 @@ func ladder_collide():
if is_climbing == true:
gravity = 0.0
else:
gravity = default_gravity
gravity = level_control.gamemode.gravity
func wall_jump():
print("CAN JUMP? ",can_wall_jump)
@@ -724,7 +719,7 @@ func pickup_apply(type,ammo_type,value):
1: #STAMINA
remaining_stamina = clamp(remaining_stamina + value,0,100)
2: #HEALTH
level_control.health = clamp(level_control.health + value,0,level_control.start_health)
level_control.health = clamp(level_control.health + value,0,level_control.gamemode.start_health)
3: #MONEY
level_control.money += value
@@ -764,7 +759,7 @@ func weapon_bob(vel : float, delta):
if gun != null and !ads and !gun.ads:
weapon_holder.global_position.y += -clamp(velocity.y * .15,-1,1) * delta
if vel > 2 and is_on_floor():
var speed_adjust = speed/WALK_SPEED
var speed_adjust = speed/level_control.gamemode.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)
@@ -807,6 +802,7 @@ func hit(damage, fired_by, target_type):
await get_tree().create_timer(.15).timeout
health_indicator.color = Color(0.471, 0, 0, 0)
func save():
var save_dict = {
"filename" : get_scene_file_path(),