♻️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
+126
-110
@@ -1,11 +1,14 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
## Controlador comun de enemigos. Configura variantes en enemies/variants/*.tscn.
|
||||
## Navegacion local y combate comparten estado; no dependen del codigo de los niveles.
|
||||
|
||||
|
||||
signal died
|
||||
|
||||
|
||||
# The five scene variants share this controller. Their movement, jump and
|
||||
# attack settings live in enemies/variants; no separate AI hierarchy is needed.
|
||||
# Las cinco variantes comparten controlador. Sus ajustes viven en enemies/variants;
|
||||
# no hace falta duplicar la IA ni crear una jerarquia por cada enemigo.
|
||||
|
||||
const PLAYER_HURTBOX_MASK: int = 1 << 3
|
||||
const DROP_MANAGER := preload("res://pickups/drop_manager.gd")
|
||||
@@ -21,7 +24,7 @@ enum AttackState {
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# MOVEMENT
|
||||
# MOVIMIENTO
|
||||
# ============================================================================
|
||||
|
||||
@export_category("Movement")
|
||||
@@ -29,22 +32,22 @@ enum AttackState {
|
||||
@export var move_speed: float = 78.0
|
||||
@export var max_fall_speed: float = 800.0
|
||||
|
||||
## Seeing an enemy on screen wakes it, but proximity starts the pursuit.
|
||||
## Once engaged it keeps chasing up to 1.5 times this distance, within its leash.
|
||||
## Ver al enemigo lo activa; la proximidad inicia la persecucion.
|
||||
## Una vez iniciada, continua hasta 1,5 veces esta distancia, sin exceder Chase Radius.
|
||||
@export_range(80.0, 1200.0, 10.0) var aggro_range: float = 340.0
|
||||
|
||||
## Only agile variants jump. Others still stop at walls and platform edges.
|
||||
## Solo las variantes agiles saltan. Las demas se detienen ante paredes y bordes.
|
||||
@export var can_jump: bool = false
|
||||
@export_range(-900.0, -100.0, 10.0) var jump_velocity: float = -560.0
|
||||
@export_range(0.2, 3.0, 0.05) var jump_cooldown: float = 0.9
|
||||
@export var hop_while_chasing: bool = false
|
||||
|
||||
## A landing must exist within this drop; never jump into an unbounded pit.
|
||||
## Desnivel maximo aceptado para un aterrizaje; no salta a un vacio sin suelo detectado.
|
||||
@export_range(0.0, 400.0, 10.0) var max_jump_drop: float = 200.0
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# COMBAT
|
||||
# COMBATE
|
||||
# ============================================================================
|
||||
|
||||
@export_category("Combat")
|
||||
@@ -52,107 +55,99 @@ enum AttackState {
|
||||
@export_range(1, 100, 1) var max_health: int = 20
|
||||
@export_range(0, 100, 1) var attack_damage: int = 1
|
||||
|
||||
## Outgoing push on the player, independent of damage and enemy knockback.
|
||||
## Empuje aplicado al jugador, independiente del dano y del retroceso recibido por el enemigo.
|
||||
@export_range(0.0, 3.0, 0.05) var attack_knockback_multiplier: float = 1.0
|
||||
|
||||
## Minimum time between the beginning of two attacks.
|
||||
## Tiempo minimo entre el inicio de dos ataques.
|
||||
@export var attack_interval: float = 2.0
|
||||
|
||||
## Horizontal distance at which the Walker stops chasing and prepares a hit.
|
||||
## This is intentionally wider than the final hitbox so entering range does not
|
||||
## mean taking unavoidable damage.
|
||||
## Distancia horizontal para preparar el ataque. Supera el area final
|
||||
## para ofrecer tiempo de reaccion antes de que el golpe alcance al jugador.
|
||||
@export var attack_trigger_distance: float = 140.0
|
||||
|
||||
## Keeps the Walker from starting a ground attack against a player far above or
|
||||
## below it.
|
||||
## Evita iniciar ataques de suelo contra un jugador situado demasiado arriba o abajo.
|
||||
@export var attack_vertical_tolerance: float = 80.0
|
||||
|
||||
## Readable pause before the dangerous part of the attack starts. During this
|
||||
## time the direction is locked, so moving behind the enemy is a valid dodge.
|
||||
## Preparacion visible anterior al impacto. La direccion queda fijada y permite esquivar por detras.
|
||||
@export var attack_windup_duration: float = 0.35
|
||||
|
||||
## Duration of the actual hit. The hitbox sweeps forward during this window.
|
||||
## Duracion de la fase danina; el area de ataque avanza durante esta ventana.
|
||||
@export var attack_duration: float = 0.22
|
||||
|
||||
## Small recovery after the hit before the enemy can hitbox again.
|
||||
## Recuperacion tras el golpe antes de poder iniciar otro.
|
||||
@export var attack_recovery_duration: float = 0.30
|
||||
|
||||
## Where the hitbox starts, relative to the enemy while facing right.
|
||||
## Posicion inicial del area de ataque cuando el enemigo mira a la derecha.
|
||||
@export var attack_start_offset: Vector2 = Vector2(34.0, 0.0)
|
||||
|
||||
## Furthest horizontal position reached by the moving hitbox.
|
||||
## Distancia horizontal maxima que alcanza el barrido ofensivo.
|
||||
@export var attack_reach: float = 120.0
|
||||
|
||||
## A successful player hit briefly interrupts the Walker. This makes attacking
|
||||
## during its windup useful instead of forcing an unavoidable damage trade.
|
||||
## Interrupcion breve al recibir un golpe. Permite defenderse atacando durante la preparacion enemiga.
|
||||
@export var hit_stun_duration: float = 0.18
|
||||
|
||||
## Strength of the knockback applied per point of damage. The final push is
|
||||
## divided by the enemy's max health, so tougher enemies move less.
|
||||
## Impulso por punto de dano, dividido por la vida maxima: los enemigos resistentes retroceden menos.
|
||||
@export var knockback_strength: float = 400.0
|
||||
|
||||
## How long the knockback impulse lasts before friction brings the enemy to a halt.
|
||||
## Duracion del retroceso antes de que el frenado detenga al enemigo.
|
||||
@export var knockback_duration: float = 0.4
|
||||
|
||||
## Damage threshold to trigger a longer stun (e.g. a fully charged special attack).
|
||||
## Umbral de dano que provoca un aturdimiento prolongado.
|
||||
@export_range(0, 100, 1) var stun_damage_threshold: int = 5
|
||||
|
||||
## Stun duration when the received damage exceeds the threshold.
|
||||
## Duracion del aturdimiento cuando el impacto supera el umbral.
|
||||
@export var strong_hit_stun_duration: float = 2.0
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# RESPAWN
|
||||
# RECOMPENSAS Y REAPARICION
|
||||
# ============================================================================
|
||||
|
||||
@export_category("Drops")
|
||||
|
||||
## Default weighted drops for normal encounters.
|
||||
## Tabla de recompensas aleatorias para encuentros normales.
|
||||
@export var drop_table: PickupDropTable
|
||||
|
||||
## Optional fixed drop, used by the Level 01 test route. When assigned, this
|
||||
## object drops with 100% probability INSTEAD of the random table.
|
||||
## Recompensa fija opcional: reemplaza a la tabla aleatoria, no se suma a ella.
|
||||
@export var guaranteed_drop: PickupData
|
||||
|
||||
## In the Android lab, Level01 watches deaths and spawns the fixed reward.
|
||||
## Other levels keep using this enemy's own random/guaranteed drop logic.
|
||||
## El laboratorio observa las muertes y crea sus recompensas.
|
||||
## En los demas niveles el enemigo sigue gestionando sus propios objetos.
|
||||
var drops_handled_by_level: bool = false
|
||||
|
||||
|
||||
@export_category("Respawn")
|
||||
|
||||
## A value of 0 disables respawn (one enemy = one test item).
|
||||
## Cero desactiva la reaparicion: un enemigo muerto permanece derrotado.
|
||||
@export var respawn_delay: float = 5.0
|
||||
|
||||
## Visible launch, collapse and fade before the body disappears.
|
||||
## Duracion de lanzamiento, caida y desvanecimiento antes de ocultar el cuerpo.
|
||||
@export_range(0.3, 2.5, 0.05) var death_animation_duration: float = 0.9
|
||||
|
||||
## Horizontal leash from spawn; 0 = unrestricted. Losing the target or
|
||||
## reaching the leash makes the enemy return home rather than follow forever.
|
||||
## Limite horizontal desde el origen; cero significa sin limite.
|
||||
## Si pierde al jugador o supera este radio, vuelve a su posicion inicial.
|
||||
@export var chase_radius: float = 0.0
|
||||
|
||||
## Only used to describe enemy variants in test HUDs.
|
||||
## Nombre informativo para interfaces y pruebas de las variantes.
|
||||
@export var enemy_display_name: String = "Walker"
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# DEBUG
|
||||
# DEPURACION
|
||||
# ============================================================================
|
||||
|
||||
@export_category("Debug")
|
||||
|
||||
## Enabled while the enemy has no final sprite/animation. The grey rectangle is
|
||||
## the temporary body. Red overlays are the hurtbox and active attack hitbox.
|
||||
## The orange area during windup previews the complete attack sweep.
|
||||
## Dibuja zonas vulnerables y areas de ataque. La anticipacion naranja
|
||||
## es informacion de juego y permanece visible aunque esta opcion este desactivada.
|
||||
@export var show_debug_hitboxes: bool = false
|
||||
|
||||
## Shows the enemy health bar above its head and floating damage numbers when
|
||||
## it is hit. Purely debug: can be disabled once final art and UI exist.
|
||||
## Barra de vida y numeros de dano para depuracion; no cambia la logica de combate.
|
||||
@export var show_debug_enemy_info: bool = true
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# NODES
|
||||
# NODOS
|
||||
# ============================================================================
|
||||
|
||||
@onready var body_collision: CollisionShape2D = $CollisionShape2D
|
||||
@@ -165,7 +160,7 @@ var drops_handled_by_level: bool = false
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# RUNTIME STATE
|
||||
# ESTADO DE LA PARTIDA
|
||||
# ============================================================================
|
||||
|
||||
var current_health: int
|
||||
@@ -187,14 +182,13 @@ var _jump_cooldown_timer: float = 0.0
|
||||
var _jump_in_progress: bool = false
|
||||
var _jump_target_x: float = 0.0
|
||||
|
||||
## Prevents one sweep from damaging the same target once per physics frame.
|
||||
## Evita aplicar dano repetidamente al mismo objetivo durante un unico barrido.
|
||||
var attack_hit_targets: Dictionary = {}
|
||||
|
||||
## Timer for the knockback impulse applied when the enemy is hit.
|
||||
## Tiempo restante del impulso de retroceso.
|
||||
var knockback_timer: float = 0.0
|
||||
|
||||
## Floating damage numbers shown above the enemy when it takes damage.
|
||||
## Each entry: { text: String, local_pos: Vector2, timer: float }
|
||||
## Numeros flotantes de dano. Cada entrada contiene texto, posicion local y tiempo restante.
|
||||
var _damage_texts: Array = []
|
||||
var _hit_flash_timer: float = 0.0
|
||||
var _death_elapsed: float = 0.0
|
||||
@@ -205,6 +199,7 @@ var _visual_rotation: float
|
||||
var _visual_color: Color
|
||||
|
||||
|
||||
## Captura el punto de origen, resuelve al jugador y configura fisica, recompensas y activacion.
|
||||
func _ready() -> void:
|
||||
_visual_position = visual.position
|
||||
_visual_scale = visual.scale
|
||||
@@ -230,6 +225,7 @@ func _ready() -> void:
|
||||
queue_redraw()
|
||||
|
||||
|
||||
## Prioriza muerte, inactividad, retroceso, ataque y navegacion en ese orden.
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_dead:
|
||||
_update_death_animation(delta)
|
||||
@@ -241,8 +237,8 @@ func _physics_process(delta: float) -> void:
|
||||
_update_damage_texts(delta)
|
||||
_apply_gravity(delta)
|
||||
|
||||
# The enemy deliberately does nothing until the camera has shown it once.
|
||||
# After waking up it may pursue or return home even outside the screen.
|
||||
# Permanece inactivo hasta aparecer en pantalla una vez.
|
||||
# Tras activarse puede perseguir o regresar aunque vuelva a quedar fuera de camara.
|
||||
if not is_awake:
|
||||
velocity.x = 0.0
|
||||
move_and_slide()
|
||||
@@ -256,10 +252,8 @@ func _physics_process(delta: float) -> void:
|
||||
queue_redraw()
|
||||
return
|
||||
|
||||
# Being hit pauses both movement and attack. While the knockback impulse
|
||||
# lasts the enemy is pushed back, then friction brings it to a halt. The
|
||||
# cooldown keeps running, so interrupting an attack does not make the enemy
|
||||
# immediately start another one.
|
||||
# Un impacto pausa movimiento y ataque. Primero aplica retroceso y luego frena.
|
||||
# La espera entre ataques sigue avanzando para que la interrupcion no reinicie un golpe inmediato.
|
||||
if hit_stun_timer > 0.0:
|
||||
if knockback_timer > 0.0:
|
||||
knockback_timer = max(knockback_timer - delta, 0.0)
|
||||
@@ -283,13 +277,15 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# ACTIVATION AND TARGETING
|
||||
# ACTIVACION Y OBJETIVO
|
||||
# ============================================================================
|
||||
|
||||
## Activa permanentemente al enemigo al entrar por primera vez en pantalla.
|
||||
func _wake_up() -> void:
|
||||
is_awake = true
|
||||
|
||||
|
||||
## Recupera una referencia valida al jugador sin buscar mientras la actual sigue viva.
|
||||
func _acquire_target_if_needed() -> void:
|
||||
if target != null and is_instance_valid(target):
|
||||
return
|
||||
@@ -297,6 +293,7 @@ func _acquire_target_if_needed() -> void:
|
||||
target = get_tree().get_first_node_in_group(&"player") as Node2D
|
||||
|
||||
|
||||
## Orienta al enemigo hacia el objetivo si hay una diferencia horizontal significativa.
|
||||
func _face_target() -> void:
|
||||
var direction_to_target: float = signf(target.global_position.x - global_position.x)
|
||||
if direction_to_target == 0.0 or direction_to_target == facing_direction:
|
||||
@@ -306,21 +303,23 @@ func _face_target() -> void:
|
||||
_update_facing()
|
||||
|
||||
|
||||
## Sincroniza textura y sonda frontal; no altera la direccion de un ataque ya fijada.
|
||||
func _update_facing() -> void:
|
||||
# The ledge probe follows the current movement direction. Attack direction is
|
||||
# stored separately once a windup starts so the enemy cannot rotate mid-hit.
|
||||
# La sonda del borde sigue el movimiento. La direccion ofensiva se guarda aparte
|
||||
# para impedir que un ataque ya preparado gire siguiendo al jugador.
|
||||
floor_probe.position.x = abs(floor_probe.position.x) * facing_direction
|
||||
|
||||
if attack_state == AttackState.IDLE:
|
||||
_reset_attack_hitbox_position()
|
||||
# The five variants share one collision box and AI, but use different sprites.
|
||||
# Las variantes comparten caja de colision e IA, pero tienen texturas diferentes.
|
||||
visual.flip_h = facing_direction < 0.0
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# MOVEMENT
|
||||
# MOVIMIENTO
|
||||
# ============================================================================
|
||||
|
||||
## Aplica gravedad con limite de caida y sin acumular velocidad dentro del suelo.
|
||||
func _apply_gravity(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
return
|
||||
@@ -329,6 +328,7 @@ func _apply_gravity(delta: float) -> void:
|
||||
velocity.y = min(velocity.y, max_fall_speed)
|
||||
|
||||
|
||||
## Decide entre perseguir, volver al origen o esperar, respetando los radios configurados.
|
||||
func _update_idle_behaviour(delta: float) -> void:
|
||||
var offset_to_target: Vector2 = target.global_position - global_position
|
||||
var detection_distance: float = aggro_range * (1.5 if _is_pursuing else 1.0)
|
||||
@@ -349,14 +349,13 @@ func _update_idle_behaviour(delta: float) -> void:
|
||||
return
|
||||
_move_towards(target.global_position, delta)
|
||||
else:
|
||||
# Return naturally, without teleporting or healing. Non-jumpers still
|
||||
# refuse ledges; this is local steering, not a global pathfinding system.
|
||||
# Regreso sin teletransporte ni curacion. Es navegacion local: no calcula rutas globales por el nivel.
|
||||
_move_towards(spawn_position, delta)
|
||||
|
||||
|
||||
## Navegacion local con deteccion de paredes, bordes y aterrizaje comprometido.
|
||||
func _move_towards(destination: Vector2, delta: float) -> void:
|
||||
# Commit to the chosen landing instead of homing onto a moving player in
|
||||
# mid-air. A hit clears this goal so it never cancels received knockback.
|
||||
# Mantiene el aterrizaje elegido durante el salto. Un impacto cancela ese objetivo para respetar el retroceso.
|
||||
if _jump_in_progress and not is_on_floor():
|
||||
velocity.x = clampf((_jump_target_x - global_position.x) / delta, -move_speed, move_speed)
|
||||
return
|
||||
@@ -375,8 +374,8 @@ func _move_towards(destination: Vector2, delta: float) -> void:
|
||||
velocity.x = 0.0
|
||||
return
|
||||
|
||||
# Refresh after turning: the previous physics frame's probe points the
|
||||
# other way. Look ahead early enough to jump BEFORE touching a step.
|
||||
# Actualiza la sonda tras girar: su resultado anterior miraba hacia el otro lado.
|
||||
# Se anticipa al borde para saltar antes de chocar con el escalon.
|
||||
floor_probe.force_raycast_update()
|
||||
var edge_ahead: bool = not floor_probe.is_colliding()
|
||||
var look_ahead: Vector2 = Vector2(facing_direction * maxf(32.0, move_speed * 0.25), 0.0)
|
||||
@@ -387,13 +386,14 @@ func _move_towards(destination: Vector2, delta: float) -> void:
|
||||
if absf(offset.x) <= stopping_distance or edge_ahead:
|
||||
velocity.x = 0.0
|
||||
return
|
||||
# Use a fresh forward test, not is_on_wall() from the previous direction.
|
||||
# Consulta frontal nueva, no is_on_wall() calculado con la direccion anterior.
|
||||
if test_move(global_transform, Vector2(facing_direction * 3.0, 0.0)):
|
||||
velocity.x = 0.0
|
||||
return
|
||||
velocity.x = facing_direction * minf(move_speed, absf(offset.x) / delta)
|
||||
|
||||
|
||||
## Comprueba capacidad, espera y aterrizaje antes de consumir un intento de salto.
|
||||
func _try_jump(destination: Vector2, wall_ahead: bool, edge_ahead: bool) -> bool:
|
||||
if not can_jump or not is_on_floor() or _jump_cooldown_timer > 0.0:
|
||||
return false
|
||||
@@ -407,7 +407,7 @@ func _try_jump(destination: Vector2, wall_ahead: bool, edge_ahead: bool) -> bool
|
||||
if not wall_ahead and not edge_ahead and not climb_needed and not wants_hop:
|
||||
return false
|
||||
|
||||
# Failed attempts are throttled too: no terrain scans every physics frame.
|
||||
# Tambien limita los intentos fallidos para no explorar el terreno en cada fotograma.
|
||||
_jump_cooldown_timer = 0.25
|
||||
var gravity_y: float = get_gravity().y
|
||||
if gravity_y <= 0.0 or jump_velocity >= 0.0:
|
||||
@@ -428,6 +428,7 @@ func _try_jump(destination: Vector2, wall_ahead: bool, edge_ahead: bool) -> bool
|
||||
return true
|
||||
|
||||
|
||||
## Busca un suelo cercano alcanzable, con hueco para el cuerpo y tiempo de vuelo suficiente.
|
||||
func _find_jump_landing(destination: Vector2, max_rise: float, gravity_y: float, climbing: bool) -> Vector2:
|
||||
var body_shape: RectangleShape2D = body_collision.shape as RectangleShape2D
|
||||
var half_size: Vector2 = body_shape.size * 0.5
|
||||
@@ -435,8 +436,8 @@ func _find_jump_landing(destination: Vector2, max_rise: float, gravity_y: float,
|
||||
var best_landing: Vector2 = Vector2.INF
|
||||
var best_score: float = INF
|
||||
var space: PhysicsDirectSpaceState2D = get_world_2d().direct_space_state
|
||||
# A handful of local candidates covers steps, nearby platforms and small
|
||||
# gaps. Both feet must fit, and flight time must permit the horizontal move.
|
||||
# Explora unos pocos aterrizajes locales: deben caber ambos pies
|
||||
# y el tiempo de vuelo debe permitir cubrir la distancia horizontal.
|
||||
for distance: float in [48.0, 80.0, 120.0, 160.0, 200.0, 240.0]:
|
||||
var x: float = global_position.x + facing_direction * distance
|
||||
if chase_radius > 0.0 and absf(x - spawn_position.x) > chase_radius:
|
||||
@@ -482,6 +483,7 @@ func _find_jump_landing(destination: Vector2, max_rise: float, gravity_y: float,
|
||||
return best_landing
|
||||
|
||||
|
||||
## Orienta ligeramente el sprite durante el vuelo sin cambiar su colision.
|
||||
func _update_jump_visual() -> void:
|
||||
if not _jump_in_progress:
|
||||
visual.scale = _visual_scale
|
||||
@@ -491,14 +493,15 @@ func _update_jump_visual() -> void:
|
||||
visual.scale = _visual_scale
|
||||
COMBAT_FX.spawn(get_parent(), global_position + Vector2(0.0, 26.0), &"dust")
|
||||
else:
|
||||
# A small airborne pose without changing collision sizes or sprite art.
|
||||
# Pose aerea sin modificar las colisiones ni los recursos de imagen.
|
||||
visual.scale = _visual_scale * Vector2(0.9, 1.08)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# ATTACK
|
||||
# ATAQUE
|
||||
# ============================================================================
|
||||
|
||||
## Comprueba distancia, altura y linea libre antes de permitir un ataque.
|
||||
func _is_target_in_attack_trigger() -> bool:
|
||||
var offset_to_target: Vector2 = target.global_position - global_position
|
||||
if (
|
||||
@@ -507,16 +510,16 @@ func _is_target_in_attack_trigger() -> bool:
|
||||
or absf(offset_to_target.y) > attack_vertical_tolerance
|
||||
):
|
||||
return false
|
||||
# A player behind a step should trigger navigation, not attacks through it.
|
||||
# Una pared entre ambos exige navegar, no atacar a traves de ella.
|
||||
var query := PhysicsRayQueryParameters2D.create(
|
||||
global_position, target.global_position, collision_mask, [get_rid()]
|
||||
)
|
||||
return get_world_2d().direct_space_state.intersect_ray(query).is_empty()
|
||||
|
||||
|
||||
## Fija la direccion y entra en la fase de anticipacion.
|
||||
func _start_attack() -> void:
|
||||
# Lock the direction here. During windup/active frames the player can dodge
|
||||
# behind the enemy without the hitbox snapping around to follow them.
|
||||
# Fija la direccion al preparar el golpe; el jugador puede esquivar por detras sin que el area lo persiga.
|
||||
_face_target()
|
||||
attack_direction = facing_direction
|
||||
attack_state = AttackState.WINDUP
|
||||
@@ -527,6 +530,7 @@ func _start_attack() -> void:
|
||||
_reset_attack_hitbox_position()
|
||||
|
||||
|
||||
## Despacha la fase actual: preparacion, barrido danino o recuperacion.
|
||||
func _update_attack(delta: float) -> void:
|
||||
velocity.x = 0.0
|
||||
|
||||
@@ -539,6 +543,7 @@ func _update_attack(delta: float) -> void:
|
||||
_update_attack_recovery(delta)
|
||||
|
||||
|
||||
## Espera el tiempo de anticipacion antes de activar el barrido.
|
||||
func _update_attack_windup(delta: float) -> void:
|
||||
attack_phase_timer = max(attack_phase_timer - delta, 0.0)
|
||||
if attack_phase_timer > 0.0:
|
||||
@@ -549,11 +554,11 @@ func _update_attack_windup(delta: float) -> void:
|
||||
_set_attack_hitbox_progress(0.0)
|
||||
|
||||
|
||||
## Avanza el area danina y resuelve sus contactos.
|
||||
func _update_active_attack(delta: float) -> void:
|
||||
attack_phase_timer = max(attack_phase_timer - delta, 0.0)
|
||||
|
||||
# Sweep the actual physics hitbox from close to the enemy towards its maximum
|
||||
# reach. This gives the player time to jump, back away or move behind it.
|
||||
# Desplaza el area fisica desde cerca del cuerpo hasta su alcance maximo, dando margen para esquivar.
|
||||
var progress: float = 1.0
|
||||
if attack_duration > 0.0:
|
||||
progress = 1.0 - (attack_phase_timer / attack_duration)
|
||||
@@ -567,6 +572,7 @@ func _update_active_attack(delta: float) -> void:
|
||||
attack_phase_timer = attack_recovery_duration
|
||||
|
||||
|
||||
## Finaliza la recuperacion y devuelve el control a la navegacion.
|
||||
func _update_attack_recovery(delta: float) -> void:
|
||||
attack_phase_timer = max(attack_phase_timer - delta, 0.0)
|
||||
if attack_phase_timer > 0.0:
|
||||
@@ -577,6 +583,7 @@ func _update_attack_recovery(delta: float) -> void:
|
||||
_reset_attack_hitbox_position()
|
||||
|
||||
|
||||
## Interpola el barrido entre su origen y su alcance, reflejado por la direccion fijada.
|
||||
func _set_attack_hitbox_progress(progress: float) -> void:
|
||||
var start_x: float = abs(attack_start_offset.x)
|
||||
var current_x: float = lerpf(start_x, attack_reach, progress)
|
||||
@@ -586,6 +593,7 @@ func _set_attack_hitbox_progress(progress: float) -> void:
|
||||
)
|
||||
|
||||
|
||||
## Devuelve el area ofensiva a su posicion inicial.
|
||||
func _reset_attack_hitbox_position() -> void:
|
||||
var direction: float = attack_direction
|
||||
if attack_state == AttackState.IDLE:
|
||||
@@ -597,6 +605,7 @@ func _reset_attack_hitbox_position() -> void:
|
||||
)
|
||||
|
||||
|
||||
## Aplica un solo impacto por objetivo y evita golpear a traves del escenario.
|
||||
func _update_attack_damage() -> void:
|
||||
for area in attack_hitbox.get_overlapping_areas():
|
||||
var damage_target: Node = area.get_parent()
|
||||
@@ -607,8 +616,7 @@ func _update_attack_damage() -> void:
|
||||
if attack_hit_targets.has(target_id):
|
||||
continue
|
||||
|
||||
# A swept hitbox must not reach through solid walls. Use the enemy's
|
||||
# body as the source: a hitbox past the player could push them backwards.
|
||||
# El barrido no atraviesa paredes. El origen del empuje es el cuerpo enemigo, no su area adelantada.
|
||||
var query := PhysicsRayQueryParameters2D.create(
|
||||
global_position, (damage_target as Node2D).global_position,
|
||||
collision_mask, [get_rid()]
|
||||
@@ -619,6 +627,7 @@ func _update_attack_damage() -> void:
|
||||
damage_target.take_damage(attack_damage, global_position, attack_knockback_multiplier)
|
||||
|
||||
|
||||
## Cancela el ataque y vacia su registro de impactos.
|
||||
func _interrupt_attack() -> void:
|
||||
if attack_state == AttackState.IDLE:
|
||||
return
|
||||
@@ -629,13 +638,15 @@ func _interrupt_attack() -> void:
|
||||
_reset_attack_hitbox_position()
|
||||
|
||||
|
||||
## Descuenta los tiempos de ataque, salto, retroceso y aturdimiento.
|
||||
func _update_timers(delta: float) -> void:
|
||||
attack_cooldown_timer = max(attack_cooldown_timer - delta, 0.0)
|
||||
hit_stun_timer = max(hit_stun_timer - delta, 0.0)
|
||||
_jump_cooldown_timer = maxf(_jump_cooldown_timer - delta, 0.0)
|
||||
|
||||
|
||||
# Updates floating damage numbers: they drift upward and fade out over time.
|
||||
# Los numeros de dano ascienden y pierden opacidad con el tiempo.
|
||||
## Actualiza y elimina las entradas visuales de dano.
|
||||
func _update_damage_texts(delta: float) -> void:
|
||||
for i in range(_damage_texts.size() - 1, -1, -1):
|
||||
var entry: Dictionary = _damage_texts[i]
|
||||
@@ -645,9 +656,10 @@ func _update_damage_texts(delta: float) -> void:
|
||||
_damage_texts.remove_at(i)
|
||||
|
||||
# ============================================================================
|
||||
# DAMAGE AND RESPAWN
|
||||
# DANO Y REAPARICION
|
||||
# ============================================================================
|
||||
|
||||
## Aplica vida, interrupcion, empuje y aturdimiento antes de comprobar muerte.
|
||||
func take_damage(amount: int, source_position: Vector2) -> void:
|
||||
if amount <= 0 or is_dead:
|
||||
return
|
||||
@@ -666,7 +678,7 @@ func take_damage(amount: int, source_position: Vector2) -> void:
|
||||
if camera != null and camera.has_method("impact"):
|
||||
camera.call("impact", 1.0, 0.12)
|
||||
|
||||
# Floating damage number (debug only).
|
||||
# Numero flotante de dano, exclusivamente visual.
|
||||
if show_debug_enemy_info:
|
||||
_damage_texts.append({
|
||||
"text": str(amount),
|
||||
@@ -678,12 +690,11 @@ func take_damage(amount: int, source_position: Vector2) -> void:
|
||||
_die()
|
||||
return
|
||||
|
||||
# Light enemies are interruptible. This makes a well-timed player attack a
|
||||
# defensive option and avoids mandatory damage trades at close range.
|
||||
# Los golpes interrumpen al enemigo y permiten usarlos como defensa a corta distancia.
|
||||
_interrupt_attack()
|
||||
|
||||
# Knockback: stronger hits push harder, tougher enemies (more max health)
|
||||
# resist the push. Direction is away from the damage source.
|
||||
# Los golpes mas fuertes empujan mas; la vida maxima amortigua ese retroceso.
|
||||
# La direccion siempre se aleja del origen del dano.
|
||||
var knockback_dir: float = signf(global_position.x - source_position.x)
|
||||
if knockback_dir == 0.0:
|
||||
knockback_dir = 1.0
|
||||
@@ -694,8 +705,7 @@ func take_damage(amount: int, source_position: Vector2) -> void:
|
||||
|
||||
knockback_timer = knockback_duration
|
||||
|
||||
# Stun: normal hits use the brief hit stun; very strong hits (e.g. a fully
|
||||
# charged special attack) trigger a longer stun.
|
||||
# Un impacto normal causa una pausa breve; superar el umbral provoca aturdimiento prolongado.
|
||||
if amount >= stun_damage_threshold:
|
||||
hit_stun_timer = max(hit_stun_timer, strong_hit_stun_duration)
|
||||
else:
|
||||
@@ -707,6 +717,7 @@ func take_damage(amount: int, source_position: Vector2) -> void:
|
||||
_update_facing()
|
||||
|
||||
|
||||
## Emite la muerte una vez y delega la recompensa segun el modo del nivel.
|
||||
func _die() -> void:
|
||||
if is_dead:
|
||||
return
|
||||
@@ -715,11 +726,10 @@ func _die() -> void:
|
||||
_death_elapsed = 0.0
|
||||
velocity = Vector2(_last_hit_direction * 150.0, -210.0)
|
||||
COMBAT_FX.spawn(get_parent(), global_position, &"death", _last_hit_direction)
|
||||
# Logical death happens now, exactly once. Animation must not delay rewards.
|
||||
# La muerte logica y su senal ocurren una sola vez; la animacion no retrasa las recompensas.
|
||||
died.emit()
|
||||
|
||||
# Test encounters always drop their assigned item, including the two items
|
||||
# absent from the normal Walker table. Other levels keep their random loot.
|
||||
# Los encuentros de laboratorio entregan su objeto asignado; el resto conserva su tabla aleatoria.
|
||||
var drops: Array[PickupData] = []
|
||||
if not drops_handled_by_level:
|
||||
if guaranteed_drop != null:
|
||||
@@ -732,13 +742,14 @@ func _die() -> void:
|
||||
parent = get_tree().root
|
||||
DROP_MANAGER.spawn_drops(drops, parent, global_position)
|
||||
|
||||
# Disable combat immediately; keep the body colliding with the WORLD while it
|
||||
# falls. Disabling the body now would let the death pose fall through streets.
|
||||
# Desactiva el combate inmediatamente pero conserva la colision con World durante la caida
|
||||
# para evitar que el cuerpo atraviese el suelo en la animacion de muerte.
|
||||
hurtbox_collision.set_deferred("disabled", true)
|
||||
attack_collision.set_deferred("disabled", true)
|
||||
queue_redraw()
|
||||
|
||||
|
||||
## Anima el cuerpo derrotado conservando el suelo y sin permitir nuevos ataques.
|
||||
func _update_death_animation(delta: float) -> void:
|
||||
_death_elapsed += delta
|
||||
_update_damage_texts(delta)
|
||||
@@ -762,12 +773,13 @@ func _update_death_animation(delta: float) -> void:
|
||||
velocity = Vector2.ZERO
|
||||
body_collision.set_deferred("disabled", true)
|
||||
if respawn_delay <= 0.0:
|
||||
# Keep the dead node for the lab's KO polling and Level02's total count.
|
||||
# Conserva el nodo muerto: el laboratorio lo consulta y el nivel 02 lo incluye en el total de enemigos.
|
||||
set_physics_process(false)
|
||||
elif _death_elapsed >= maxf(respawn_delay, duration):
|
||||
_respawn()
|
||||
|
||||
|
||||
## Restaura el estado inicial y decide si debe estar activo al reaparecer.
|
||||
func _respawn() -> void:
|
||||
set_physics_process(true)
|
||||
_death_elapsed = 0.0
|
||||
@@ -801,22 +813,22 @@ func _respawn() -> void:
|
||||
visible = true
|
||||
is_dead = false
|
||||
|
||||
# If the spawn point is currently inside the camera, wake immediately.
|
||||
# Otherwise the notifier will wake the enemy when the camera reaches it.
|
||||
# Si reaparece dentro de la camara se activa inmediatamente; de lo contrario espera al notificador.
|
||||
is_awake = visibility_notifier.is_on_screen()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# TEMPORARY VISUAL + DEBUG HITBOXES
|
||||
# PRESENTACION Y DEPURACION DE COLISIONES
|
||||
# ============================================================================
|
||||
|
||||
## Dibuja anticipacion ofensiva y elementos opcionales de depuracion.
|
||||
func _draw() -> void:
|
||||
if is_dead:
|
||||
if show_debug_enemy_info:
|
||||
_draw_damage_texts()
|
||||
return
|
||||
# Retain a fallback body if an imported sprite is missing.
|
||||
# Dibujo de reserva si no se ha podido importar la textura del enemigo.
|
||||
if visual.texture == null:
|
||||
_draw_rectangle_collision(
|
||||
body_collision,
|
||||
@@ -824,27 +836,27 @@ func _draw() -> void:
|
||||
Color(0.85, 0.85, 0.90, 1.0)
|
||||
)
|
||||
|
||||
# Enemy health bar and floating damage numbers (debug overlay).
|
||||
# Barra de vida y numeros flotantes de depuracion.
|
||||
if show_debug_enemy_info:
|
||||
_draw_enemy_health_bar()
|
||||
_draw_damage_texts()
|
||||
|
||||
# Orange windup is important gameplay feedback, not a debug hitbox.
|
||||
# Keep it visible on Android even when red collision overlays are disabled.
|
||||
# La anticipacion naranja comunica un ataque real, no es una colision de depuracion.
|
||||
# Permanece visible tambien en Android sin las superposiciones rojas.
|
||||
if attack_state == AttackState.WINDUP:
|
||||
_draw_attack_telegraph()
|
||||
|
||||
if not show_debug_hitboxes:
|
||||
return
|
||||
|
||||
# Hurtbox: where punches / ground pound are allowed to damage the enemy.
|
||||
# Zona vulnerable a punetazos y golpes aereos.
|
||||
_draw_rectangle_collision(
|
||||
hurtbox_collision,
|
||||
Color(1.0, 0.05, 0.05, 0.12),
|
||||
Color(1.0, 0.05, 0.05, 0.55)
|
||||
)
|
||||
|
||||
# Active attack: draw the real moving physics hitbox in strong red.
|
||||
# Area danina real del barrido, resaltada en rojo.
|
||||
if attack_state == AttackState.ACTIVE:
|
||||
_draw_rectangle_collision(
|
||||
attack_collision,
|
||||
@@ -854,6 +866,7 @@ func _draw() -> void:
|
||||
)
|
||||
|
||||
|
||||
## Anticipa visualmente el recorrido peligroso del siguiente barrido.
|
||||
func _draw_attack_telegraph() -> void:
|
||||
var rectangle: RectangleShape2D = attack_collision.shape as RectangleShape2D
|
||||
if rectangle == null:
|
||||
@@ -871,6 +884,7 @@ func _draw_attack_telegraph() -> void:
|
||||
draw_rect(rect, Color(1.0, 0.55, 0.05, 0.85), false, 2.0)
|
||||
|
||||
|
||||
## Dibuja una forma rectangular en las coordenadas locales del enemigo.
|
||||
func _draw_rectangle_collision(
|
||||
collision: CollisionShape2D,
|
||||
fill_color: Color,
|
||||
@@ -886,25 +900,27 @@ func _draw_rectangle_collision(
|
||||
draw_rect(rect, fill_color, true)
|
||||
draw_rect(rect, outline_color, false, 2.0)
|
||||
|
||||
# Draws a small horizontal health bar just above the enemy's head.
|
||||
# Barra horizontal de vida situada sobre la cabeza.
|
||||
## Representa la proporcion de vida restante sobre el enemigo.
|
||||
func _draw_enemy_health_bar() -> void:
|
||||
var bar_width: float = 40.0
|
||||
var bar_height: float = 5.0
|
||||
var bar_pos: Vector2 = Vector2(-bar_width * 0.5, -48.0)
|
||||
|
||||
# Background.
|
||||
# Fondo de la barra.
|
||||
draw_rect(Rect2(bar_pos, Vector2(bar_width, bar_height)), Color(0.2, 0.2, 0.2, 0.8), true)
|
||||
# Fill.
|
||||
# Relleno proporcional a la vida restante.
|
||||
var fill_ratio: float = float(current_health) / float(max_health) if max_health > 0 else 0.0
|
||||
draw_rect(
|
||||
Rect2(bar_pos, Vector2(bar_width * fill_ratio, bar_height)),
|
||||
Color(0.85, 0.2, 0.2, 0.95),
|
||||
true
|
||||
)
|
||||
# Border.
|
||||
# Borde de la barra.
|
||||
draw_rect(Rect2(bar_pos, Vector2(bar_width, bar_height)), Color(1, 1, 1, 0.6), false, 1.0)
|
||||
|
||||
# Draws floating damage numbers that drift upward and fade out.
|
||||
# Numeros de dano que ascienden y se desvanecen.
|
||||
## Muestra numeros de dano con opacidad dependiente de su tiempo restante.
|
||||
func _draw_damage_texts() -> void:
|
||||
var font: Font = ThemeDB.get_default_theme().get_font("font", "Label")
|
||||
if font == null:
|
||||
|
||||
Reference in new issue
Block a user