mirror of
https://github.com/kodzukye/omens-ascent.git
synced 2026-08-10 05:13:10 +00:00
37 lines
776 B
GDScript
37 lines
776 B
GDScript
class_name HealthComponent
|
|
extends Node
|
|
|
|
signal health_changed(new_value: int, max_value: int)
|
|
signal died
|
|
|
|
@export var max_health: int = 1
|
|
|
|
var current_health: int
|
|
|
|
func _ready() -> void:
|
|
current_health = max_health
|
|
|
|
func take_damage(amount: int) -> void:
|
|
if current_health <= 0:
|
|
return
|
|
|
|
current_health = max(current_health - amount, 0)
|
|
health_changed.emit(current_health, max_health)
|
|
|
|
if current_health == 0:
|
|
died.emit()
|
|
|
|
func kill() -> void:
|
|
if current_health <= 0:
|
|
return
|
|
current_health = 0
|
|
health_changed.emit(current_health, max_health)
|
|
died.emit()
|
|
|
|
func heal(amount: int) -> void:
|
|
if current_health <= 0:
|
|
return
|
|
current_health = min(current_health + amount, max_health)
|
|
health_changed.emit(current_health, max_health)
|
|
AudioManager.play_sfx("heal")
|