summaryrefslogtreecommitdiff
path: root/Scenes/UI/HealthBar.gd
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-10 11:48:05 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-10 11:48:05 +0200
commit46556d864b9685c3b09a0038f5de83966fe7ff94 (patch)
treec68082eacd35559e14565d1598dd694972fb8e0e /Scenes/UI/HealthBar.gd
Initial commit
Diffstat (limited to 'Scenes/UI/HealthBar.gd')
-rw-r--r--Scenes/UI/HealthBar.gd44
1 files changed, 44 insertions, 0 deletions
diff --git a/Scenes/UI/HealthBar.gd b/Scenes/UI/HealthBar.gd
new file mode 100644
index 0000000..8c4c90d
--- /dev/null
+++ b/Scenes/UI/HealthBar.gd
@@ -0,0 +1,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("damaged", 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)