mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
31 lines
616 B
GDScript
31 lines
616 B
GDScript
extends Area3D
|
|
class_name HealthComponent
|
|
|
|
@export var max_health : int = 100
|
|
@export var health : int:
|
|
set(value):
|
|
health = value
|
|
health_changed.emit(value)
|
|
|
|
signal health_zeroed
|
|
signal health_changed
|
|
|
|
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)
|