summaryrefslogtreecommitdiff
path: root/hp_bar.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-08-25 23:47:22 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-08-25 23:47:22 +0200
commitcf4f54f8e43d1deb03e1b644f6a374530efa11e3 (patch)
tree7003af7af09775f09dda2164c4b16faa05a1290f /hp_bar.gd
parent8d4e709f7e2390e06c3e412c20662e8bc21f0d0c (diff)
next commit
Diffstat (limited to 'hp_bar.gd')
-rw-r--r--hp_bar.gd43
1 files changed, 43 insertions, 0 deletions
diff --git a/hp_bar.gd b/hp_bar.gd
new file mode 100644
index 0000000..e8c304f
--- /dev/null
+++ b/hp_bar.gd
@@ -0,0 +1,43 @@
+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
+
+
+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
+ )