27 lines
427 B
GDScript
27 lines
427 B
GDScript
extends Node
|
|
class_name Damageable
|
|
|
|
@export var health = 3
|
|
@export var hitback_velocity: float = 500
|
|
|
|
var active = true
|
|
|
|
signal got_hit
|
|
signal die
|
|
|
|
func set_active(new_active: bool):
|
|
active = new_active
|
|
|
|
func damage(value: int = 0, direction: Vector2 = Vector2.UP):
|
|
if not active:
|
|
return
|
|
|
|
health -= value
|
|
if health <= 0:
|
|
die.emit()
|
|
return
|
|
|
|
get_parent().velocity = hitback_velocity * direction
|
|
got_hit.emit()
|
|
|