Added visibility component
This commit is contained in:
@ -8,23 +8,23 @@ const DEATH_THRESHOLD = 0.01
|
||||
|
||||
@export var max_value: float
|
||||
var value: float
|
||||
var is_dead: bool
|
||||
var is_alive: bool
|
||||
|
||||
func _ready():
|
||||
restore()
|
||||
|
||||
func restore():
|
||||
is_dead = false
|
||||
is_alive = true
|
||||
value = max_value
|
||||
value_changed.emit()
|
||||
|
||||
func take_damage(attack: DamageInstance):
|
||||
if is_dead:
|
||||
if !is_alive:
|
||||
return
|
||||
|
||||
value = clampf(value - attack.damage, 0, max_value)
|
||||
value_changed.emit()
|
||||
|
||||
if value < DEATH_THRESHOLD:
|
||||
is_dead = true
|
||||
is_alive = false
|
||||
death.emit()
|
||||
|
Reference in New Issue
Block a user