breadwinner/scenes/player/stamina_component.gd
Hellie-xd 0a764354ba did a shitton of refactoring.
still has bugs, but almost works like the original, but has much better
structure. still might have to change around a bit, but closing in to
the final form.
2026-08-09 03:24:28 +02:00

24 lines
621 B
GDScript

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)