21 lines
427 B
GDScript
21 lines
427 B
GDScript
extends CollisionShape2D
|
|
|
|
class_name Destructable
|
|
|
|
signal hit(damage, collision)
|
|
signal die(damage, collision)
|
|
|
|
export var max_health = 100
|
|
export var health = 100
|
|
|
|
func _ready():
|
|
pass
|
|
|
|
func trigger_hit(damage, collision):
|
|
emit_signal("hit", damage, collision)
|
|
health = clamp(health - damage, -max_health, max_health)
|
|
if health > max_health:
|
|
health = max_health
|
|
elif health <= 0:
|
|
emit_signal("die", damage, collision)
|