From 46556d864b9685c3b09a0038f5de83966fe7ff94 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 10 Aug 2023 11:48:05 +0200 Subject: Initial commit --- Scenes/UI/HealthBar.gd | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Scenes/UI/HealthBar.gd (limited to 'Scenes/UI/HealthBar.gd') 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) -- cgit v1.2.3