54 lines
1.7 KiB
GDScript
54 lines
1.7 KiB
GDScript
extends Control
|
||
class_name HUD
|
||
|
||
# HUD для отображения информации об игроке
|
||
|
||
@onready var health_bar: ProgressBar = $HealthBar
|
||
@onready var health_label: Label = $HealthBar/HealthLabel
|
||
@onready var dash_cooldown_bar: ProgressBar = $DashCooldownBar
|
||
@onready var dash_cooldown_label: Label = $DashCooldownBar/DashCooldownLabel
|
||
|
||
var player: Player = null
|
||
|
||
func _ready():
|
||
# Находим игрока в сцене
|
||
call_deferred("find_player")
|
||
|
||
func find_player():
|
||
var players = get_tree().get_nodes_in_group("player")
|
||
if players.size() > 0:
|
||
player = players[0] as Player
|
||
if player:
|
||
# Подключаемся к сигналам
|
||
player.health_changed.connect(_on_player_health_changed)
|
||
player.dash_cooldown_changed.connect(_on_dash_cooldown_changed)
|
||
# Обновляем отображение
|
||
update_health_display()
|
||
update_dash_cooldown_display()
|
||
|
||
func _on_player_health_changed(new_health: float):
|
||
update_health_display()
|
||
|
||
func _on_dash_cooldown_changed(remaining_time: float):
|
||
update_dash_cooldown_display()
|
||
|
||
func update_health_display():
|
||
if not player:
|
||
return
|
||
|
||
var health_percent = (player.health / player.max_health) * 100.0
|
||
health_bar.value = health_percent
|
||
health_label.text = "HP: %d / %d" % [int(player.health), int(player.max_health)]
|
||
|
||
func update_dash_cooldown_display():
|
||
if not player:
|
||
return
|
||
|
||
var cooldown_percent = (player.dash_cooldown_timer / player.dash_cooldown) * 100.0
|
||
dash_cooldown_bar.value = cooldown_percent
|
||
|
||
if player.dash_cooldown_timer > 0.0:
|
||
dash_cooldown_label.text = "Рывок: %.1f" % player.dash_cooldown_timer
|
||
else:
|
||
dash_cooldown_label.text = "Рывок: готов (Пробел)"
|