blob: 9df85e80108602780442730ba5a5d90bea35b757 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
)
|