open-fpsz/components/health_component.gd
2024-04-09 15:15:04 +00:00

27 lines
534 B
GDScript

extends Area3D
class_name HealthComponent
@export var max_health : int = 100
@export var health : int
signal health_zeroed
func _ready():
health = max_health
area_entered.connect(_on_area_entered)
func damage(amount : int):
health = clampf(health - amount, 0.0, max_health)
if health == 0.0:
health_zeroed.emit()
func heal_full():
health = max_health
func heal(amount : int):
health = clampf(health + amount, 0.0, max_health)
func _on_area_entered(area : Area3D):
if area is AreaDamageComponent:
damage(area.damage)