game: animate hp bars
This commit is contained in:
@@ -4,9 +4,42 @@ extends Control
|
||||
@onready var hp_bar: ProgressBar = $CenterContainer/VBoxContainer/ProgressBar
|
||||
@onready var elapsed_label: Label = $CenterContainer/VBoxContainer/ElapsedLabel
|
||||
|
||||
const ANIM_SPEED = 4.0
|
||||
const TRESHOLD = 1
|
||||
|
||||
func set_hp(value: float):
|
||||
hp_bar.value = value
|
||||
var wanted_hp_value: float
|
||||
var wanted_hp_max: float
|
||||
|
||||
var player: Player
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
player = get_tree().get_first_node_in_group("player")
|
||||
if player:
|
||||
hp_bar.value = player.player_stats.current_health
|
||||
hp_bar.max_value = player.player_stats.max_health
|
||||
|
||||
|
||||
func update_hp():
|
||||
if not player:
|
||||
push_error("cant update hp, no player found")
|
||||
var current_hp = player.player_stats.get_final("current_health", player.modifiers)
|
||||
var max_hp = player.player_stats.get_final("max_health", player.modifiers)
|
||||
wanted_hp_value = current_hp
|
||||
wanted_hp_max = max_hp
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if wanted_hp_max != hp_bar.max_value:
|
||||
print_debug("wanted: %f-%f" % [wanted_hp_max, hp_bar.max_value])
|
||||
hp_bar.max_value = lerpf(hp_bar.max_value, wanted_hp_max, ANIM_SPEED * delta)
|
||||
if abs(hp_bar.max_value - wanted_hp_max) < TRESHOLD:
|
||||
hp_bar.max_value = wanted_hp_max
|
||||
if wanted_hp_value != hp_bar.value:
|
||||
print_debug("current: %f-%f" % [wanted_hp_value, hp_bar.value])
|
||||
hp_bar.value = lerpf(hp_bar.value, wanted_hp_value, ANIM_SPEED * delta)
|
||||
if abs(hp_bar.value - wanted_hp_value) < TRESHOLD:
|
||||
hp_bar.value = wanted_hp_value
|
||||
|
||||
|
||||
func set_elapsed_time(value: float):
|
||||
|
Reference in New Issue
Block a user