90 lines
1.7 KiB
GDScript
90 lines
1.7 KiB
GDScript
class_name PlayerState extends Node
|
|
|
|
var walking: bool = false
|
|
var running: bool = false
|
|
var crouching: bool = false
|
|
@onready var in_menu: bool = UiManager.in_game_menu.visible
|
|
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]
|
|
|
|
@export var player: Player
|
|
|
|
var flying: bool = false
|
|
|
|
func handle_state_change(new_state:String):
|
|
match new_state:
|
|
"idle":
|
|
is_idle()
|
|
"walking":
|
|
is_walking()
|
|
"running":
|
|
is_running()
|
|
"crouching":
|
|
is_crouching()
|
|
_:
|
|
print("invalid state")
|
|
|
|
func _process(_delta: float) -> void:
|
|
var stamina = player.stamina_component.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:
|
|
#jumped.emit(true)
|
|
#flying = true
|
|
#
|
|
#if player.is_on_floor() and flying:
|
|
#landed.emit(false)
|
|
#flying = false
|
|
|
|
func jump():
|
|
flying = true
|
|
|
|
func land():
|
|
flying = false
|
|
|
|
func is_crouching():
|
|
crouching = true
|
|
walking = false
|
|
running = false
|
|
|
|
func is_walking():
|
|
crouching = false
|
|
walking = true
|
|
running = false
|
|
|
|
func is_running():
|
|
crouching = false
|
|
walking = false
|
|
running = true
|
|
|
|
func is_idle():
|
|
crouching = false
|
|
walking = false
|
|
running = false
|