Mejoras en la creacion de niveles, y el hud del jugador

This commit is contained in:
Diego De la Viuda Llorente committed 2026-10-29 15:25:31 +01:00
1 parent fd0118d964
commit 5b1a434778
29 files changed
+3210 -101

No files matched your search

+34 -10
View File
@@ -1,31 +1,49 @@
extends CanvasLayer
## Interfaz de vida en CanvasLayer: sus coordenadas pertenecen a la ventana,
## no al escenario. Se mantiene en la misma esquina aunque avance la camara.
## Conecta el estado de Player con el HUD. La estetica y la animacion viven en ThrashMeter.
## CanvasLayer mantiene la interfaz fija en pantalla aunque avance la camara.
@onready var health_bar: ProgressBar = $HUD/HealthBar
## Umbral de aviso visual; no cambia la vida ni la dificultad del combate.
@export_range(0.05, 0.5, 0.05) var low_health_ratio: float = 0.25
@onready var health_bar: ThrashMeter = $HUD/HealthBar
@onready var health_label: Label = $HUD/HealthBar/HealthLabel
@onready var effects_label: Label = $HUD/EffectsLabel
@onready var warning_label: Label = $HUD/WarningLabel
var player_ref: Node
var _received_health: bool = false
var _effects_refresh_timer: float = 0.0
## Valida el contrato del jugador y conecta la senal de vida.
func _ready() -> void:
player_ref = get_parent()
if not player_ref.has_signal(&"health_changed"):
push_error("PlayerHealthHUD must be a child of a Player.")
if player_ref == null or not player_ref.has_signal(&"health_changed"):
# Abrir esta escena sola permite revisar su diseno sin crear un jugador de mentira.
player_ref = null
set_process(false)
return
# Los hijos ejecutan _ready antes que Player; su senal inicial llegara despues de esta conexion.
player_ref.connect(&"health_changed", _on_health_changed)
effects_label.visible = false
# Tambien funciona si el HUD se instancia despues de _ready del jugador.
if player_ref.is_node_ready():
var data: Resource = player_ref.get("character_data") as Resource
if data != null:
_on_health_changed(int(player_ref.get("current_health")), int(data.get("max_health")))
## Actualiza los tiempos restantes de las mejoras temporales.
func _process(_delta: float) -> void:
if player_ref == null:
func _process(delta: float) -> void:
if not is_instance_valid(player_ref):
return
# Los contadores muestran segundos: refrescarlos a 10 Hz evita reconstruir texto cada frame.
_effects_refresh_timer -= delta
if _effects_refresh_timer > 0.0:
return
_effects_refresh_timer = 0.1
# Muestra cada mejora por separado. Los nombres de propiedades corresponden al estado temporal de Player.
var active: Array[String] = []
@@ -55,6 +73,12 @@ func _process(_delta: float) -> void:
## Sincroniza barra y texto a partir del mismo par de valores.
func _on_health_changed(current_health: int, max_health: int) -> void:
health_bar.max_value = float(max_health)
health_bar.value = float(current_health)
health_label.text = "HP %d / %d" % [current_health, max_health]
var capacity: int = maxi(max_health, 0)
var amount: int = clampi(current_health, 0, capacity)
health_bar.set_amount(amount, capacity, not _received_health)
_received_health = true
health_label.text = "%d / %d" % [amount, capacity]
var low_health: bool = capacity > 0 and float(amount) / float(capacity) <= low_health_ratio
health_bar.highlighted = low_health and amount > 0
warning_label.visible = low_health or amount == 0
warning_label.text = "SIN VIDA" if amount == 0 else "PELIGRO"