blob: d6b736193c90e3eaeaae192b1b3656caebc9ea03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
extends Node
class_name Component_Health
signal died
@export_node_path("CharacterBody2D") var entityPath: NodePath
@onready var entity: CharacterBody2D = get_node(entityPath)
@export_node_path("AnimatedSprite2D") var spritePath: NodePath
@onready var sprite: AnimatedSprite2D = get_node(spritePath)
@export var health: int
func take_damage():
health -= 1
if health <= 0:
death()
func death():
emit_signal("died")
entity.set_physics_process(false)
sprite.play("death")
await sprite.animation_finished
sprite.play("death_post")
var tween: Tween = get_tree().create_tween()
tween.tween_property(
entity,
"scale",
Vector2(0, 0),
1 / sprite.sprite_frames.get_animation_speed("death_post")
)
tween.tween_callback(func():
entity.queue_free()
)
|