2024-02-12 23:22:27 +00:00
|
|
|
class_name HealthComponent
|
|
|
|
extends Node
|
|
|
|
|
|
|
|
signal value_changed
|
2024-02-13 10:17:45 +00:00
|
|
|
signal death
|
|
|
|
|
|
|
|
const DEATH_THRESHOLD = 0.01
|
2024-02-12 23:22:27 +00:00
|
|
|
|
|
|
|
@export var max_value: float
|
|
|
|
var value: float
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
value = max_value
|
|
|
|
value_changed.emit()
|
|
|
|
|
|
|
|
func take_damage(attack: DamageInstance):
|
2024-02-13 10:17:45 +00:00
|
|
|
value = clampf(value - attack.damage, 0, max_value)
|
2024-02-12 23:22:27 +00:00
|
|
|
value_changed.emit()
|
|
|
|
|
2024-02-13 10:17:45 +00:00
|
|
|
if value < DEATH_THRESHOLD:
|
|
|
|
death.emit()
|