summaryrefslogtreecommitdiff
path: root/hp_bar.gd
diff options
context:
space:
mode:
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
+ )