breadwinner/scenes/player/state_handler_component.gd

79 lines
1.5 KiB
GDScript3
Raw Normal View History

extends Node
var walking: bool = false
var running: bool = false
var crouching: bool = false
var in_menu: bool = false
var breathing_mode = breath.calm
enum breath {
calm,
low,
mid,
heavy,
max,
exhausted
}
## 0 --> exhausted [br]
## 0 - 10 --> max [br]
## 10 -- 20 --> heavy [br]
## 20 -- 50 --> mid [br]
## 50 -- 80 --> low [br]
## 80 -- 100 --> calm
var _breath_change_points: Array[float] = [10, 20, 50, 80]
@onready var player_manager: Node = %PlayerManager
@onready var player: CharacterBody3D = $"../.."
var flying: bool = false
signal landed
signal jumped
func _process(_delta: float) -> void:
var stamina = player_manager.stamina
if stamina == 0:
breathing_mode = breath.exhausted
elif stamina <= _breath_change_points[0]:
breathing_mode = breath.max
elif stamina <= _breath_change_points[1]:
breathing_mode = breath.heavy
elif stamina <= _breath_change_points[2]:
breathing_mode = breath.mid
elif stamina <= _breath_change_points[3]:
breathing_mode = breath.low
else:
breathing_mode = breath.calm
if !player.is_on_floor() and !flying:
emit_signal("jumped", true)
flying = true
if player.is_on_floor() and flying:
emit_signal("landed", false)
flying = false
func is_crouched(yes:bool):
if yes:
crouching = true
walking = false
running = false
else:
crouching = false
func is_walking(yes:bool):
if yes:
crouching = false
walking = true
running = false
else:
walking = false
func is_running(yes:bool):
if yes:
crouching = false
walking = false
running = true
else:
running = false