extends CharacterBody2D const SPEED = 200.0 const STAMINA_DRAIN = 5.0 const STAMINA_REGEN = 3.0 var stats = { "health": 100, "stamina": 100, "hunger": 0, "thirst": 0, "mood": 100, "organs": { "heart": 100, "lungs": 100, "brain": 100, "cyber": 100 } } var hud: CanvasLayer func _ready() -> void: hud = get_tree().get_first_node_in_group("hud") if hud: hud.update_stats(stats) func _physics_process(delta: float) -> void: var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down") var moving = input_dir.length() > 0 if moving and stats.stamina > 0: velocity = input_dir * SPEED stats.stamina = max(0, stats.stamina - STAMINA_DRAIN * delta) elif not moving: velocity.x = move_toward(velocity.x, 0, SPEED) velocity.y = move_toward(velocity.y, 0, SPEED) stats.stamina = min(100, stats.stamina + STAMINA_REGEN * delta) else: velocity.x = move_toward(velocity.x, 0, SPEED) velocity.y = move_toward(velocity.y, 0, SPEED) move_and_slide() if input_dir.length() > 0: rotation = input_dir.angle() if hud: hud.update_stats(stats) func take_damage(amount: int) -> void: stats.health = max(0, stats.health - amount) func heal(amount: int) -> void: stats.health = min(100, stats.health + amount) func add_hunger(amount: int) -> void: stats.hunger = min(100, stats.hunger + amount) func add_thirst(amount: int) -> void: stats.thirst = min(100, stats.thirst + amount) func change_mood(amount: int) -> void: stats.mood = clamp(stats.mood + amount, 0, 100)