25 lines
621 B
GDScript3
25 lines
621 B
GDScript3
|
|
class_name StaminaComponent extends Node
|
||
|
|
|
||
|
|
var stamina_recharge: bool = true
|
||
|
|
var stamina: float = 100.0
|
||
|
|
|
||
|
|
## how many seconds to wait for stamina recharge
|
||
|
|
@export var stamina_recharge_cooldown: float = 3.0
|
||
|
|
|
||
|
|
var _timer: Timer = Timer.new()
|
||
|
|
|
||
|
|
func restart_timer():
|
||
|
|
_timer.start()
|
||
|
|
|
||
|
|
func _process(delta: float) -> void:
|
||
|
|
if stamina_recharge:
|
||
|
|
stamina = move_toward(stamina, 100, 10 * delta)
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
_timer.wait_time = stamina_recharge_cooldown
|
||
|
|
_timer.autostart = false
|
||
|
|
_timer.timeout.connect(func (): stamina_recharge = true)
|
||
|
|
add_child(_timer)
|
||
|
|
|
||
|
|
GlobalSignals.stamina_recharge_off.connect(restart_timer)
|