summaryrefslogtreecommitdiff
path: root/UI/hp_bar.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-09-08 22:35:06 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-09-08 22:35:06 +0200
commit4597189f157834c80f56b12b701fd2b2a15c2798 (patch)
treef522e9a58ec756dc27306781da99e828b195c549 /UI/hp_bar.gd
parent7d7d845e76f78a87cf87c9464d700e52cd88ce6f (diff)
next commit
Diffstat (limited to 'UI/hp_bar.gd')
-rw-r--r--UI/hp_bar.gd48
1 files changed, 48 insertions, 0 deletions
diff --git a/UI/hp_bar.gd b/UI/hp_bar.gd
new file mode 100644
index 0000000..9df85e8
--- /dev/null
+++ b/UI/hp_bar.gd
@@ -0,0 +1,48 @@
+extends Control
+
+
+var value_difference = 0
+
+
+func init(health):
+ $HealthBar.max_value = health
+ $HealthBar.value = health
+
+ $ImmediateDamageBar.max_value = health
+ $ImmediateDamageBar.value = health
+
+ $TotalDamageBar.max_value = health
+ $TotalDamageBar.value = health
+
+
+func set_value(value):
+ value_difference = $HealthBar.value - value
+ $HealthBar.value = value
+
+ if $HealthBar.max_value == $HealthBar.value:
+ visible = false
+ else:
+ visible = true
+
+
+func _on_health_bar_value_changed(value: float) -> void:
+ if not $ImmediateDamageTimer.is_stopped():
+ $ImmediateDamageBar.value = $HealthBar.value + value_difference
+
+ $ImmediateDamageTimer.start()
+
+
+func _on_immediate_damage_timer_timeout() -> void:
+ var tween = get_tree().create_tween()
+ tween.tween_property($ImmediateDamageBar, "value", $HealthBar.value, 0.2)
+ $TotalDamageTimer.start()
+
+
+func _on_total_damage_timer_timeout() -> void:
+ var tween = get_tree().create_tween()
+ tween.tween_property(
+ $TotalDamageBar,
+ "value",
+ $HealthBar.value,
+ 0.3
+ )