-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.gd
38 lines (32 loc) · 842 Bytes
/
enemy.gd
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
extends Node2D
const CombatText = preload("res://combat_effect_text.tscn")
onready var bar = $ProgressBar
onready var tween = $Tween
onready var name_label = $RichTextLabel
signal died
var health = 30000
var alive = true
func _ready():
bar.max_value = health
bar.value = health
func initialize(boss : Boss):
alive = true
health = boss.hp
bar.max_value = boss.hp
bar.value = boss.hp
name_label.text = boss.name
func _update_bar():
tween.interpolate_property(bar, "value", bar.value, health, 0.2, Tween.TRANS_LINEAR)
tween.start()
func _take_damage(damage):
if alive:
var dmg = CombatText.instance()
var txt = dmg.get_node("RichTextLabel")
txt.modulate = Color(1, 0, 0, 1)
txt.text = "-" + str(damage)
health -= damage
add_child(dmg)
_update_bar()
if health <= 0 and alive:
alive = false
emit_signal("died")