154 lines
4.4 KiB
GDScript
154 lines
4.4 KiB
GDScript
class_name Player
|
|
extends CharacterBody3D
|
|
|
|
#Condition Effect
|
|
enum CONDITION {NORMAL, SPRINTING, VAPING, COUGHING, SEVERE_COUGHING}
|
|
@export var current_condition = CONDITION.NORMAL
|
|
|
|
const SPEED_NORMAL = 5.0
|
|
const SPEED_SPRINTING = 8.0
|
|
const SPEED_VAPING = 4.5
|
|
const SPEED_SLOWED = 3.0
|
|
const SPEED_IMMOBILE = 0.0
|
|
const JUMP_VELOCITY = 4.5
|
|
var current_speed
|
|
|
|
var will_cough = false
|
|
var timealive = 0
|
|
var vapes_per_min = 0
|
|
|
|
#Looking Variables
|
|
var mouse_sensitivity = 0.02
|
|
var joystick_sensitity = 2
|
|
|
|
var is_paused = false
|
|
|
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
|
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
|
|
|
func _physics_process(delta):
|
|
if not is_paused:
|
|
match current_condition:
|
|
CONDITION.NORMAL:
|
|
current_speed = SPEED_NORMAL
|
|
CONDITION.SPRINTING:
|
|
current_speed = SPEED_SPRINTING
|
|
CONDITION.VAPING:
|
|
current_speed = SPEED_VAPING
|
|
CONDITION.COUGHING:
|
|
current_speed = SPEED_SLOWED
|
|
CONDITION.SEVERE_COUGHING:
|
|
current_speed = SPEED_IMMOBILE
|
|
|
|
# Add the gravity.
|
|
if not is_on_floor():
|
|
velocity.y -= gravity * delta
|
|
|
|
# Handle jump.
|
|
if Input.is_action_just_pressed("ui_accept") and is_on_floor() and current_condition != CONDITION.COUGHING and current_condition != CONDITION.SEVERE_COUGHING:
|
|
velocity.y = JUMP_VELOCITY
|
|
|
|
# Get the input direction and handle the movement/deceleration.
|
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
|
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
|
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
if direction:
|
|
velocity.x = direction.x * current_speed
|
|
velocity.z = direction.z * current_speed
|
|
else:
|
|
velocity.x = move_toward(velocity.x, 0, current_speed)
|
|
velocity.z = move_toward(velocity.z, 0, current_speed)
|
|
|
|
|
|
move_and_slide()
|
|
|
|
var look_velocity = Input.get_vector("look_left", "look_right", "look_up", "look_down")
|
|
rotate_y(-look_velocity.x * GlobalSettings.Joystick_Sensitivity * delta)
|
|
|
|
func _process(delta):
|
|
#Calculations for seeing if you vaped too many times within a short span
|
|
timealive += delta
|
|
if int(timealive) % 60 == 0:
|
|
vapes_per_min = 0
|
|
if vapes_per_min == randi_range(10,20):
|
|
will_cough = true
|
|
vapes_per_min = 0
|
|
|
|
func _input(event):
|
|
if event.is_action("ui_text_backspace"):
|
|
respawn()
|
|
if not is_paused:
|
|
if event is InputEventMouseMotion:
|
|
rotate_y(-event.relative.x * GlobalSettings.Mouse_Sensitivity)
|
|
|
|
if event.is_action_pressed("vape"):
|
|
if current_condition == CONDITION.NORMAL:
|
|
set_condition(CONDITION.VAPING)
|
|
|
|
if event.is_action_released("vape"):
|
|
if current_condition == CONDITION.VAPING:
|
|
if will_cough and current_condition != CONDITION.SEVERE_COUGHING:
|
|
set_condition(CONDITION.COUGHING)
|
|
else:
|
|
set_condition(CONDITION.NORMAL)
|
|
|
|
if event.is_action_pressed("sprint"):
|
|
if current_condition == CONDITION.NORMAL:
|
|
set_condition(CONDITION.SPRINTING)
|
|
|
|
if event.is_action_released("sprint"):
|
|
if current_condition == CONDITION.SPRINTING:
|
|
set_condition(CONDITION.NORMAL)
|
|
|
|
func set_condition(con):
|
|
current_condition = con
|
|
print("Setting Condition to ", con)
|
|
match con:
|
|
CONDITION.VAPING:
|
|
vapes_per_min += 1
|
|
$Head/VapeLight.on()
|
|
$"Coughing Timer".start()
|
|
$"Severe Coughing Timer".start()
|
|
CONDITION.NORMAL:
|
|
$Head/VapeLight.off()
|
|
$"Coughing Timer".stop()
|
|
$"Severe Coughing Timer".stop()
|
|
CONDITION.COUGHING:
|
|
$Head/VapeLight.off()
|
|
$"Coughing Recovery".start()
|
|
$"Severe Coughing Timer".stop()
|
|
GlobalSettings.Player_Last_Location = global_transform.origin
|
|
CONDITION.SEVERE_COUGHING:
|
|
$Head/VapeLight.off()
|
|
$"Severe Coughing Recovery".start()
|
|
$"Coughing Timer".stop()
|
|
GlobalSettings.Player_Last_Location = global_transform.origin
|
|
|
|
func recover():
|
|
will_cough = false
|
|
match current_condition:
|
|
CONDITION.COUGHING:
|
|
set_condition(CONDITION.NORMAL)
|
|
CONDITION.SEVERE_COUGHING:
|
|
set_condition(CONDITION.NORMAL)
|
|
|
|
func respawn():
|
|
global_position = GlobalSettings.SpawnPoint
|
|
|
|
#Timers
|
|
func _on_coughing_timer_timeout():
|
|
will_cough = true
|
|
|
|
func _on_severe_coughing_timer_timeout():
|
|
if current_condition == CONDITION.VAPING:
|
|
set_condition(CONDITION.SEVERE_COUGHING)
|
|
$Node3D/VapeLight.off()
|
|
#Play Coughing Sound
|
|
$"Severe Coughing Recovery".start()
|
|
|
|
func _on_coughing_recovery_timeout():
|
|
recover()
|
|
|
|
func _on_severe_coughing_recovery_timeout():
|
|
recover()
|