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 show_numbers(value: float): # TODO: factor out to scene var label = Label.new() label.text = str(value) label.position.x = randf_range(0.0, size.x) label.position.y = -size.y*5 label.add_theme_font_size_override("font_size", 8) add_child(label) var tween = create_tween() tween.tween_property(label, "position", Vector2(label.position.x, label.position.y - size.y), 0.25) tween.tween_property(label, "self_modulate", Color(1, 1, 1, 0), 0.25) await tween.finished label.queue_free() func _on_health_bar_value_changed(value: float) -> void: if not $ImmediateDamageTimer.is_stopped(): $ImmediateDamageBar.value = $HealthBar.value + value_difference $ImmediateDamageTimer.start() show_numbers(value_difference) 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 )