-
Notifications
You must be signed in to change notification settings - Fork 1
/
Enemy.gd
43 lines (32 loc) · 828 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
39
40
41
42
43
extends Node2D
const BattleUnits = preload("res://BattleUnits.tres")
export(int) var hp = 25 setget set_hp
export(int) var damage = 4
onready var hpLabel = $HPLabel
onready var animationPlayer = $AnimationPlayer
signal died
signal end_turn
func set_hp(new_hp):
hp = new_hp
if hpLabel != null:
hpLabel.text = str(hp) + "hp"
func _ready():
BattleUnits.Enemy = self
func _exit_tree():
BattleUnits.Enemy = null
func attack() -> void:
yield(get_tree().create_timer(0.4), "timeout")
animationPlayer.play("Attack")
yield(animationPlayer, "animation_finished")
emit_signal("end_turn")
func deal_damage():
BattleUnits.PlayerStats.hp -= damage
func take_damage(amount):
self.hp -= amount
if is_dead():
emit_signal("died")
queue_free()
else:
animationPlayer.play("Shake")
func is_dead():
return hp <= 0