mejoras en jugabilidad
This commit is contained in:
1 parent
d983bc2e69
commit
ec7e35ddf6
40 files changed
+856
-538
No files matched your search
+64
-13
@@ -40,7 +40,14 @@ enum AttackState {
|
||||
@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
|
||||
## Patrulla opcional alrededor del punto donde se coloco al enemigo en el editor.
|
||||
## Cero deja al enemigo esperando hasta detectar al jugador.
|
||||
@export_range(0.0, 500.0, 5.0) var patrol_range: float = 0.0
|
||||
@export_range(0.0, 4.0, 0.1) var patrol_pause: float = 0.8
|
||||
|
||||
## El enemigo retrocede si el jugador se acerca demasiado mientras recarga el ataque.
|
||||
## Cero lo desactiva (util para perseguidores cuerpo a cuerpo).
|
||||
@export_range(0.0, 250.0, 5.0) var preferred_distance: float = 0.0
|
||||
|
||||
## 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
|
||||
@@ -96,7 +103,11 @@ enum AttackState {
|
||||
@export_range(0, 100, 1) var stun_damage_threshold: int = 5
|
||||
|
||||
## Duracion del aturdimiento cuando el impacto supera el umbral.
|
||||
@export var strong_hit_stun_duration: float = 2.0
|
||||
@export var strong_hit_stun_duration: float = 0.7
|
||||
|
||||
## Los impactos durante esta ventana siguen causando dano, pero no reinician aturdimiento
|
||||
## ni interrumpen el barrido en preparacion. Evita bloquear enemigos a punetazos.
|
||||
@export_range(0.0, 3.0, 0.05) var stagger_resistance_duration: float = 0.95
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -171,6 +182,7 @@ var attack_phase_timer: float = 0.0
|
||||
var attack_cooldown_timer: float = 0.0
|
||||
var attack_direction: float = -1.0
|
||||
var hit_stun_timer: float = 0.0
|
||||
var stagger_resistance_timer: float = 0.0
|
||||
|
||||
var is_awake: bool = false
|
||||
var is_dead: bool = false
|
||||
@@ -178,6 +190,8 @@ var is_dead: bool = false
|
||||
var spawn_position: Vector2
|
||||
var target: Node2D
|
||||
var _is_pursuing: bool = false
|
||||
var _patrol_direction: float = 1.0
|
||||
var _patrol_wait_timer: float = 0.0
|
||||
var _jump_cooldown_timer: float = 0.0
|
||||
var _jump_in_progress: bool = false
|
||||
var _jump_target_x: float = 0.0
|
||||
@@ -348,16 +362,50 @@ func _update_idle_behaviour(delta: float) -> void:
|
||||
)
|
||||
|
||||
if _is_pursuing:
|
||||
_patrol_wait_timer = 0.0
|
||||
_face_target()
|
||||
if attack_cooldown_timer <= 0.0 and _is_target_in_attack_trigger():
|
||||
_start_attack()
|
||||
return
|
||||
_move_towards(target.global_position, delta)
|
||||
# Un enemigo a distancia puede conservar espacio durante la recarga sin
|
||||
# atravesar paredes ni bordes: sigue usando la misma navegacion local.
|
||||
if preferred_distance > 0.0 and absf(offset_to_target.x) < preferred_distance \
|
||||
and absf(offset_to_target.y) < attack_vertical_tolerance:
|
||||
var direction_away: float = -signf(offset_to_target.x)
|
||||
if direction_away == 0.0:
|
||||
direction_away = -facing_direction
|
||||
var retreat_x: float = global_position.x + direction_away * preferred_distance
|
||||
if chase_radius > 0.0:
|
||||
retreat_x = clampf(retreat_x, spawn_position.x - chase_radius, spawn_position.x + chase_radius)
|
||||
_move_towards(Vector2(retreat_x, global_position.y), delta)
|
||||
else:
|
||||
_move_towards(target.global_position, delta)
|
||||
elif patrol_range > 0.0 and absf(global_position.x - spawn_position.x) <= patrol_range + 24.0:
|
||||
_update_patrol(delta)
|
||||
else:
|
||||
# Regreso sin teletransporte ni curacion. Es navegacion local: no calcula rutas globales por el nivel.
|
||||
# Cuando pierde al jugador fuera de su ronda, vuelve al lugar donde aparecio.
|
||||
_move_towards(spawn_position, delta)
|
||||
|
||||
|
||||
## Ronda sencilla, con pausa en los extremos y sin saltos aleatorios.
|
||||
func _update_patrol(delta: float) -> void:
|
||||
if _patrol_wait_timer > 0.0:
|
||||
_patrol_wait_timer = maxf(0.0, _patrol_wait_timer - delta)
|
||||
velocity.x = 0.0
|
||||
return
|
||||
var destination_x: float = spawn_position.x + _patrol_direction * patrol_range
|
||||
if absf(destination_x - global_position.x) <= 12.0:
|
||||
_patrol_direction *= -1.0
|
||||
_patrol_wait_timer = patrol_pause
|
||||
velocity.x = 0.0
|
||||
return
|
||||
_move_towards(Vector2(destination_x, spawn_position.y), delta)
|
||||
# Ante una pared o un borde sin aterrizaje, da la vuelta en lugar de quedarse bloqueado.
|
||||
if is_on_floor() and absf(velocity.x) < 0.01:
|
||||
_patrol_direction *= -1.0
|
||||
_patrol_wait_timer = patrol_pause
|
||||
|
||||
|
||||
## Navegacion local con deteccion de paredes, bordes y aterrizaje comprometido.
|
||||
func _move_towards(destination: Vector2, delta: float) -> void:
|
||||
# Mantiene el aterrizaje elegido durante el salto. Un impacto cancela ese objetivo para respetar el retroceso.
|
||||
@@ -404,12 +452,7 @@ func _try_jump(destination: Vector2, wall_ahead: bool, edge_ahead: bool) -> bool
|
||||
return false
|
||||
var offset: Vector2 = destination - global_position
|
||||
var climb_needed: bool = offset.y < -36.0
|
||||
var wants_hop: bool = (
|
||||
hop_while_chasing and _is_pursuing
|
||||
and absf(offset.x) > attack_trigger_distance + 40.0
|
||||
and absf(offset.y) < 48.0
|
||||
)
|
||||
if not wall_ahead and not edge_ahead and not climb_needed and not wants_hop:
|
||||
if not wall_ahead and not edge_ahead and not climb_needed:
|
||||
return false
|
||||
|
||||
# Tambien limita los intentos fallidos para no explorar el terreno en cada fotograma.
|
||||
@@ -668,6 +711,7 @@ func _interrupt_attack() -> void:
|
||||
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)
|
||||
stagger_resistance_timer = maxf(0.0, stagger_resistance_timer - delta)
|
||||
_jump_cooldown_timer = maxf(_jump_cooldown_timer - delta, 0.0)
|
||||
|
||||
|
||||
@@ -694,8 +738,6 @@ func take_damage(amount: int, source_position: Vector2) -> void:
|
||||
_hit_flash_timer = 0.09
|
||||
is_awake = true
|
||||
_is_pursuing = true
|
||||
_jump_in_progress = false
|
||||
visual.scale = _visual_scale
|
||||
_last_hit_direction = signf(global_position.x - source_position.x)
|
||||
if _last_hit_direction == 0.0:
|
||||
_last_hit_direction = -facing_direction
|
||||
@@ -716,8 +758,13 @@ func take_damage(amount: int, source_position: Vector2) -> void:
|
||||
_die()
|
||||
return
|
||||
|
||||
# Los golpes interrumpen al enemigo y permiten usarlos como defensa a corta distancia.
|
||||
# El primer impacto deja una ventana para atacar, pero los siguientes
|
||||
# no pueden reiniciar indefinidamente el aturdimiento ni cancelar el ataque.
|
||||
if stagger_resistance_timer > 0.0:
|
||||
return
|
||||
_interrupt_attack()
|
||||
_jump_in_progress = false
|
||||
visual.scale = _visual_scale
|
||||
|
||||
# Los golpes mas fuertes empujan mas; la vida maxima amortigua ese retroceso.
|
||||
# La direccion siempre se aleja del origen del dano.
|
||||
@@ -736,6 +783,7 @@ func take_damage(amount: int, source_position: Vector2) -> void:
|
||||
hit_stun_timer = max(hit_stun_timer, strong_hit_stun_duration)
|
||||
else:
|
||||
hit_stun_timer = max(hit_stun_timer, hit_stun_duration)
|
||||
stagger_resistance_timer = maxf(stagger_resistance_duration, hit_stun_timer)
|
||||
|
||||
var reaction_direction: float = signf(source_position.x - global_position.x)
|
||||
if reaction_direction != 0.0:
|
||||
@@ -812,6 +860,8 @@ func _respawn() -> void:
|
||||
_death_elapsed = 0.0
|
||||
_hit_flash_timer = 0.0
|
||||
_is_pursuing = false
|
||||
_patrol_direction = 1.0
|
||||
_patrol_wait_timer = 0.0
|
||||
_jump_in_progress = false
|
||||
_jump_cooldown_timer = 0.0
|
||||
_jump_target_x = spawn_position.x
|
||||
@@ -828,6 +878,7 @@ func _respawn() -> void:
|
||||
attack_phase_timer = 0.0
|
||||
attack_cooldown_timer = 0.0
|
||||
hit_stun_timer = 0.0
|
||||
stagger_resistance_timer = 0.0
|
||||
knockback_timer = 0.0
|
||||
attack_hit_targets.clear()
|
||||
attack_direction = facing_direction
|
||||
|
||||
Reference in new issue
Block a user