blob: ba51007aa1b1d9a439846d2ed9588eed5dcfde2f (
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
44
|
extends Control
var Health = preload("res://Scenes/UI/Health.tscn")
var player: Player
func connect_to_player(player_to_connect: Player):
self.player = player_to_connect
self.draw_health()
self.player.connect("health_changed", func (_health): self.draw_health())
func draw_health():
for child in $HBoxContainer.get_children():
child.queue_free()
for i in int(player.health / 4.0):
var healthNode = Health.instantiate()
healthNode.set_full()
$HBoxContainer.add_child(healthNode)
if player.health % 4 > 0:
var healthNode = Health.instantiate()
healthNode.set_full_parts(player.health % 4)
$HBoxContainer.add_child(healthNode)
var health_diff = player.maxHealth - player.health
for i in int(health_diff / 4.0):
var healthNode = Health.instantiate()
healthNode.set_empty()
$HBoxContainer.add_child(healthNode)
if player.extraHealth > 0:
for i in int(player.extraHealth / 4.0):
var healthNode = Health.instantiate()
healthNode.set_extra_full()
$HBoxContainer.add_child(healthNode)
if player.extraHealth % 4 > 0:
var healthNode = Health.instantiate()
healthNode.set_extra_full_parts(player.extraHealth % 4)
$HBoxContainer.add_child(healthNode)
|