Attempt2/lib/components/Health_Component.gd
2025-04-20 22:15:51 -07:00

27 lines
567 B
GDScript

class_name HealthComponent
extends Node
export var max_health: int = 0
onready var health :int = max_health
signal health_depleted()
func take_damage(damage_amount :int):
if damage_amount < 0:
push_error("Only positive numbers in health component functions.")
health -= damage_amount
if health <= 0:
emit_signal("health_depleted")
health = 0
func heal(heal_amount :int):
if heal_amount < 0:
push_error("ERROR: Only positive numbers in health component functions.")
return
health += heal_amount
if health > max_health:
health = max_health