♻️REFACTOR: Mejoras en la viabilidad para desarrollo
This commit is contained in:
1 parent
5aba6c7b47
commit
fd0118d964
98 files changed
+5985
-3024
No files matched your search
@@ -1,12 +1,8 @@
|
||||
extends CanvasLayer
|
||||
|
||||
|
||||
## Minimal player HUD.
|
||||
##
|
||||
## This is a CanvasLayer on purpose: its coordinates belong to the camera
|
||||
## viewport, not to the level. Therefore (18, 18) always means "18 pixels from
|
||||
## the top-left corner currently visible by the camera", even while the player
|
||||
## and Camera2D move through the world.
|
||||
## Interfaz de vida en CanvasLayer: sus coordenadas pertenecen a la ventana,
|
||||
## no al escenario. Se mantiene en la misma esquina aunque avance la camara.
|
||||
|
||||
@onready var health_bar: ProgressBar = $HUD/HealthBar
|
||||
@onready var health_label: Label = $HUD/HealthBar/HealthLabel
|
||||
@@ -15,22 +11,23 @@ extends CanvasLayer
|
||||
var player_ref: Node
|
||||
|
||||
|
||||
## 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.")
|
||||
return
|
||||
# Children enter _ready before Player. Its initial signal arrives afterward.
|
||||
# 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
|
||||
|
||||
|
||||
## Actualiza los tiempos restantes de las mejoras temporales.
|
||||
func _process(_delta: float) -> void:
|
||||
if player_ref == null:
|
||||
return
|
||||
|
||||
# Display each active effect individually: essential when validating all
|
||||
# eight pickup families on a phone. Property names match Player's timers.
|
||||
# Muestra cada mejora por separado. Los nombres de propiedades corresponden al estado temporal de Player.
|
||||
var active: Array[String] = []
|
||||
var speed_seconds: float = float(player_ref.get("_speed_boost_timer"))
|
||||
if speed_seconds > 0.0:
|
||||
@@ -56,6 +53,7 @@ func _process(_delta: float) -> void:
|
||||
effects_label.text = "\n".join(active)
|
||||
|
||||
|
||||
## 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)
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
extends CanvasLayer
|
||||
|
||||
|
||||
## Minimal HUD showing the player's special attack charge.
|
||||
##
|
||||
## Expects to be a child of a Player that exposes a `special_charge_changed`
|
||||
## signal, just like PlayerHealthHUD expects `health_changed`.
|
||||
## Medidor de carga especial. Debe ser hijo de un jugador que emita
|
||||
## special_charge_changed, igual que el HUD de vida depende de health_changed.
|
||||
|
||||
|
||||
@onready var special_bar: ProgressBar = $HUD/SpecialBar
|
||||
@onready var special_label: Label = $HUD/SpecialBar/SpecialLabel
|
||||
|
||||
|
||||
## Conecta el medidor antes de recibir el estado inicial del jugador.
|
||||
func _ready() -> void:
|
||||
var player: Node = get_parent()
|
||||
if player == null or not player.has_signal(&"special_charge_changed"):
|
||||
push_error("SpecialChargeHUD must be a child of a Player with special_charge_changed signal.")
|
||||
return
|
||||
|
||||
# Child _ready() runs before Player._ready(). We connect here first and the
|
||||
# Player will emit its initial charge a moment later during its _ready().
|
||||
# Se conecta antes del _ready del jugador para recibir tambien la carga inicial.
|
||||
player.connect(&"special_charge_changed", _on_special_charge_changed)
|
||||
|
||||
|
||||
## Actualiza la barra y la etiqueta de carga especial.
|
||||
func _on_special_charge_changed(current_charge: int, max_charge: int) -> void:
|
||||
special_bar.max_value = float(max_charge)
|
||||
special_bar.value = float(current_charge)
|
||||
|
||||
@@ -12,7 +12,7 @@ extends CanvasLayer
|
||||
## Player
|
||||
##
|
||||
## Cuando llegue el arte definitivo, esta escena puede cambiar por completo sin
|
||||
## tocar player.gd mientras conserve estas cuatro acciones.
|
||||
## tocar player.gd mientras conserve estas seis acciones.
|
||||
|
||||
@onready var move_left_button: Button = $Controls/MoveLeft
|
||||
@onready var move_right_button: Button = $Controls/MoveRight
|
||||
@@ -24,6 +24,7 @@ extends CanvasLayer
|
||||
var direction_touch_index: int = -1
|
||||
|
||||
|
||||
## Asocia botones con las mismas acciones utilizadas por el teclado.
|
||||
func _ready() -> void:
|
||||
_bind_button(jump_button, &"jump")
|
||||
_bind_button(attack_button, &"attack")
|
||||
@@ -31,6 +32,7 @@ func _ready() -> void:
|
||||
_bind_button(special_attack_button, &"special_attack")
|
||||
|
||||
|
||||
## Mantiene un unico dedo para direccion y permite deslizarlo entre ambos lados.
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventScreenTouch:
|
||||
var touch := event as InputEventScreenTouch
|
||||
@@ -49,6 +51,7 @@ func _input(event: InputEvent) -> void:
|
||||
_press_direction(action)
|
||||
|
||||
|
||||
## Libera acciones al cambiar de escena para no dejar botones virtuales pulsados.
|
||||
func _exit_tree() -> void:
|
||||
# Si la escena cambia mientras un dedo sigue apoyado, Godot puede no llegar
|
||||
# a emitir button_up. Liberamos las acciones para no dejar una tecla virtual
|
||||
@@ -61,6 +64,7 @@ func _exit_tree() -> void:
|
||||
Input.action_release(&"special_attack")
|
||||
|
||||
|
||||
## Determina que control horizontal contiene la posicion tactil.
|
||||
func _direction_at(position: Vector2) -> StringName:
|
||||
if move_left_button.get_global_rect().has_point(position):
|
||||
return &"move_left"
|
||||
@@ -69,26 +73,31 @@ func _direction_at(position: Vector2) -> StringName:
|
||||
return &""
|
||||
|
||||
|
||||
## Activa una direccion y desactiva la opuesta.
|
||||
func _press_direction(action: StringName) -> void:
|
||||
var other_action: StringName = &"move_right" if action == &"move_left" else &"move_left"
|
||||
Input.action_release(other_action)
|
||||
Input.action_press(action)
|
||||
|
||||
|
||||
## Suelta ambas direcciones y libera el dedo reservado.
|
||||
func _release_direction() -> void:
|
||||
Input.action_release(&"move_left")
|
||||
Input.action_release(&"move_right")
|
||||
direction_touch_index = -1
|
||||
|
||||
|
||||
## Conecta pulsacion y liberacion con la accion indicada.
|
||||
func _bind_button(button: Button, action: StringName) -> void:
|
||||
button.button_down.connect(_press_action.bind(action))
|
||||
button.button_up.connect(_release_action.bind(action))
|
||||
|
||||
|
||||
## Envia una pulsacion al InputMap compartido.
|
||||
func _press_action(action: StringName) -> void:
|
||||
Input.action_press(action)
|
||||
|
||||
|
||||
## Libera la accion tactil en el InputMap compartido.
|
||||
func _release_action(action: StringName) -> void:
|
||||
Input.action_release(action)
|
||||
Reference in new issue
Block a user