|
|
|
@@ -39,7 +39,7 @@ const COMBAT_FX = preload("res://effects/combat_fx.gd")
|
|
|
|
|
@export_category("Movement")
|
|
|
|
|
|
|
|
|
|
## Aceleracion horizontal en el suelo; no alcanza la velocidad maxima instantaneamente.
|
|
|
|
|
@export var ground_acceleration: float = 2000.0
|
|
|
|
|
@export var ground_acceleration: float = 1800.0
|
|
|
|
|
|
|
|
|
|
## Frenado al soltar la direccion. Mayor que la aceleracion para evitar deslizamiento.
|
|
|
|
|
@export var ground_friction: float = 3200.0
|
|
|
|
@@ -51,6 +51,14 @@ const COMBAT_FX = preload("res://effects/combat_fx.gd")
|
|
|
|
|
@export var air_acceleration: float = 1100.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@export_category("Crouch / Drop through")
|
|
|
|
|
|
|
|
|
|
## Altura del cuerpo y de la zona vulnerable respecto a la altura de pie.
|
|
|
|
|
@export_range(0.4, 0.85, 0.01) var crouch_height_ratio: float = 0.62
|
|
|
|
|
## Impulso inicial hacia abajo al atravesar una plataforma de un solo sentido.
|
|
|
|
|
@export_range(60.0, 400.0, 10.0) var drop_through_speed: float = 180.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============================================================================
|
|
|
|
|
# SALTO
|
|
|
|
|
# ============================================================================
|
|
|
|
@@ -201,6 +209,7 @@ const COMBAT_FX = preload("res://effects/combat_fx.gd")
|
|
|
|
|
|
|
|
|
|
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
|
|
|
|
|
@onready var feedback_camera: Camera2D = $Camera2D
|
|
|
|
|
@onready var body_collision: CollisionShape2D = $CollisionShape2D
|
|
|
|
|
@onready var hurtbox_collision: CollisionShape2D = $Hurtbox/CollisionShape2D
|
|
|
|
|
@onready var punch_hitbox: Area2D = $PunchHitbox
|
|
|
|
|
@onready var punch_collision: CollisionShape2D = $PunchHitbox/CollisionShape2D
|
|
|
|
@@ -233,6 +242,15 @@ var ground_pound_debug_timer: float = 0.0
|
|
|
|
|
var is_dead: bool = false
|
|
|
|
|
|
|
|
|
|
var jumps_remaining: int = 2
|
|
|
|
|
var is_crouching: bool = false
|
|
|
|
|
var _standing_shape: RectangleShape2D
|
|
|
|
|
var _crouching_shape: RectangleShape2D
|
|
|
|
|
var _standing_body_position: Vector2
|
|
|
|
|
var _standing_hurtbox_position: Vector2
|
|
|
|
|
var _crouch_offset: Vector2
|
|
|
|
|
var _headroom_shape: RectangleShape2D
|
|
|
|
|
## Excepciones SOLO de este jugador y de los soportes que decidio atravesar.
|
|
|
|
|
var _dropped_platforms: Array[TerrainPiece] = []
|
|
|
|
|
|
|
|
|
|
var _speed_boost_timer: float = 0.0
|
|
|
|
|
var _speed_boost_multiplier: float = 0.0
|
|
|
|
@@ -296,6 +314,7 @@ func _ready() -> void:
|
|
|
|
|
|
|
|
|
|
jumps_remaining = max_jumps
|
|
|
|
|
|
|
|
|
|
_setup_crouch_shapes()
|
|
|
|
|
_setup_attack_hitboxes()
|
|
|
|
|
_update_facing()
|
|
|
|
|
_update_animation()
|
|
|
|
@@ -315,6 +334,7 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
|
|
|
|
|
_update_timers(delta)
|
|
|
|
|
_update_jump_windows(delta)
|
|
|
|
|
_update_crouch()
|
|
|
|
|
_handle_attack_input()
|
|
|
|
|
_handle_jump()
|
|
|
|
|
_apply_gravity(delta)
|
|
|
|
@@ -323,6 +343,8 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
_update_floating_texts(delta)
|
|
|
|
|
|
|
|
|
|
move_and_slide()
|
|
|
|
|
_restore_platform_collisions()
|
|
|
|
|
_update_crouch()
|
|
|
|
|
|
|
|
|
|
# Registra el punto mas alto desde el despegue para calcular el dano por altura de salto.
|
|
|
|
|
if not is_on_floor():
|
|
|
|
@@ -361,6 +383,13 @@ func _handle_horizontal_movement(delta: float) -> void:
|
|
|
|
|
var braking: float = 110.0 if _special_active else 550.0
|
|
|
|
|
velocity.x = move_toward(velocity.x, 0.0, braking * delta)
|
|
|
|
|
return
|
|
|
|
|
if is_crouching:
|
|
|
|
|
# Al soltar abajo bajo un techo, permite salir despacio sin quedar encerrado.
|
|
|
|
|
var crawl: float = 0.0
|
|
|
|
|
if not Input.is_action_pressed(&"move_down"):
|
|
|
|
|
crawl = Input.get_axis(&"move_left", &"move_right") * get_move_speed() * 0.35
|
|
|
|
|
velocity.x = move_toward(velocity.x, crawl, ground_friction * delta)
|
|
|
|
|
return
|
|
|
|
|
var direction: float = Input.get_axis("move_left", "move_right")
|
|
|
|
|
|
|
|
|
|
if direction != 0.0 and punch_timer <= 0.0:
|
|
|
|
@@ -394,6 +423,121 @@ func _handle_horizontal_movement(delta: float) -> void:
|
|
|
|
|
velocity.x = move_toward(velocity.x, target_speed, air_acceleration * delta)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ============================================================================
|
|
|
|
|
# AGACHARSE Y BAJAR PLATAFORMAS
|
|
|
|
|
# ============================================================================
|
|
|
|
|
|
|
|
|
|
## Dos formas propias por instancia; nunca se cambia el recurso compartido de la escena.
|
|
|
|
|
func _setup_crouch_shapes() -> void:
|
|
|
|
|
_standing_shape = body_collision.shape.duplicate() as RectangleShape2D
|
|
|
|
|
_crouching_shape = RectangleShape2D.new()
|
|
|
|
|
_crouching_shape.size = Vector2(_standing_shape.size.x, _standing_shape.size.y * crouch_height_ratio)
|
|
|
|
|
_standing_body_position = body_collision.position
|
|
|
|
|
_standing_hurtbox_position = hurtbox_collision.position
|
|
|
|
|
_crouch_offset = Vector2(0.0, (_standing_shape.size.y - _crouching_shape.size.y) * 0.5)
|
|
|
|
|
_headroom_shape = RectangleShape2D.new()
|
|
|
|
|
_headroom_shape.size = Vector2(_standing_shape.size.x, _crouch_offset.y * 2.0)
|
|
|
|
|
body_collision.shape = _standing_shape
|
|
|
|
|
hurtbox_collision.shape = _standing_shape
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Abajo solo agacha en suelo. No se cancelan ataques ya iniciados ni retrocesos.
|
|
|
|
|
func _update_crouch() -> void:
|
|
|
|
|
var wants_crouch: bool = is_on_floor() and Input.is_action_pressed(&"move_down")
|
|
|
|
|
wants_crouch = wants_crouch and not _special_active and not ground_pound_active
|
|
|
|
|
wants_crouch = wants_crouch and _hurt_animation_timer <= 0.0 and punch_timer <= 0.0
|
|
|
|
|
if wants_crouch:
|
|
|
|
|
_set_crouching(true)
|
|
|
|
|
elif is_crouching and _can_stand_up():
|
|
|
|
|
_set_crouching(false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _set_crouching(active: bool) -> void:
|
|
|
|
|
if is_crouching == active:
|
|
|
|
|
return
|
|
|
|
|
is_crouching = active
|
|
|
|
|
var shape: RectangleShape2D = _crouching_shape if active else _standing_shape
|
|
|
|
|
var offset: Vector2 = _crouch_offset if active else Vector2.ZERO
|
|
|
|
|
# El borde inferior no se mueve: ni saltito visual ni penetracion en el suelo.
|
|
|
|
|
body_collision.shape = shape
|
|
|
|
|
body_collision.position = _standing_body_position + offset
|
|
|
|
|
hurtbox_collision.shape = shape
|
|
|
|
|
hurtbox_collision.position = _standing_hurtbox_position + offset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Comprueba solo el espacio que ocuparia la cabeza al levantarse, no el suelo.
|
|
|
|
|
func _can_stand_up() -> bool:
|
|
|
|
|
var query := PhysicsShapeQueryParameters2D.new()
|
|
|
|
|
query.shape = _headroom_shape
|
|
|
|
|
var head_position: Vector2 = _standing_body_position + Vector2(0.0, -_standing_shape.size.y * 0.5 + _crouch_offset.y)
|
|
|
|
|
query.transform = global_transform * Transform2D(0.0, head_position)
|
|
|
|
|
query.collision_mask = WORLD_MASK
|
|
|
|
|
query.exclude = [get_rid()]
|
|
|
|
|
query.collide_with_areas = false
|
|
|
|
|
query.collide_with_bodies = true
|
|
|
|
|
for hit: Dictionary in get_world_2d().direct_space_state.intersect_shape(query, 32):
|
|
|
|
|
var terrain := hit.get("collider") as TerrainPiece
|
|
|
|
|
# Una plataforma unidireccional no es un techo solido desde abajo.
|
|
|
|
|
if terrain == null or not terrain.one_way:
|
|
|
|
|
return false
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Usa el soporte fisico actual, no una zona dibujada ni un temporizador global.
|
|
|
|
|
func _try_drop_through() -> bool:
|
|
|
|
|
if not is_on_floor() or not is_crouching:
|
|
|
|
|
return false
|
|
|
|
|
var added: Array[TerrainPiece] = []
|
|
|
|
|
var contact := KinematicCollision2D.new()
|
|
|
|
|
var probe: Vector2 = -up_direction * maxf(floor_snap_length + 1.0, 2.0)
|
|
|
|
|
# test_move funciona tambien quieto, cuando el floor snap no deja slide collisions.
|
|
|
|
|
# Si dos plataformas comparten una junta, comprobar tambien el segundo soporte.
|
|
|
|
|
while test_move(global_transform, probe, contact, safe_margin):
|
|
|
|
|
var platform := contact.get_collider() as TerrainPiece
|
|
|
|
|
if (
|
|
|
|
|
contact.get_normal().dot(up_direction) < cos(floor_max_angle)
|
|
|
|
|
or platform == null or not platform.collision_enabled or not platform.one_way
|
|
|
|
|
or added.has(platform) or _dropped_platforms.has(platform)
|
|
|
|
|
):
|
|
|
|
|
# Un soporte solido sigue bloqueando; deshacer cualquier excepcion provisional.
|
|
|
|
|
for piece: TerrainPiece in added:
|
|
|
|
|
remove_collision_exception_with(piece)
|
|
|
|
|
return false
|
|
|
|
|
add_collision_exception_with(platform)
|
|
|
|
|
added.append(platform)
|
|
|
|
|
if added.is_empty():
|
|
|
|
|
return false
|
|
|
|
|
_dropped_platforms.append_array(added)
|
|
|
|
|
# Consumir el salto de suelo impide que el coyote time o el buffer nos impulsen arriba.
|
|
|
|
|
jump_buffer_timer = 0.0
|
|
|
|
|
coyote_timer = 0.0
|
|
|
|
|
jumps_remaining = maxi(max_jumps - 1, 0)
|
|
|
|
|
velocity.y = drop_through_speed
|
|
|
|
|
if _can_stand_up():
|
|
|
|
|
_set_crouching(false)
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Recupera la colision cuando TODO el cuerpo de pie ha salido de esa pieza.
|
|
|
|
|
## No hay un plazo fijo que permita atravesar otra plataforma mas abajo.
|
|
|
|
|
func _restore_platform_collisions() -> void:
|
|
|
|
|
if _dropped_platforms.is_empty():
|
|
|
|
|
return
|
|
|
|
|
var standing_bounds: Rect2 = (global_transform * Transform2D(0.0, _standing_body_position)) * Rect2(-_standing_shape.size * 0.5, _standing_shape.size)
|
|
|
|
|
for index: int in range(_dropped_platforms.size() - 1, -1, -1):
|
|
|
|
|
var platform: TerrainPiece = _dropped_platforms[index]
|
|
|
|
|
if not is_instance_valid(platform):
|
|
|
|
|
_dropped_platforms.remove_at(index)
|
|
|
|
|
continue
|
|
|
|
|
var bounds: Rect2 = platform.global_transform * Rect2(-platform.dimensions * 0.5, platform.dimensions)
|
|
|
|
|
if (
|
|
|
|
|
not platform.collision_enabled or not platform.one_way
|
|
|
|
|
or not bounds.grow(platform.one_way_margin + safe_margin).intersects(standing_bounds, true)
|
|
|
|
|
):
|
|
|
|
|
remove_collision_exception_with(platform)
|
|
|
|
|
_dropped_platforms.remove_at(index)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Velocidad efectiva incluyendo mejoras. HUD y movimiento usan este mismo calculo.
|
|
|
|
|
func get_move_speed() -> float:
|
|
|
|
|
if character_data == null:
|
|
|
|
@@ -452,6 +596,13 @@ func _update_jump_windows(delta: float) -> void:
|
|
|
|
|
func _handle_jump() -> void:
|
|
|
|
|
if _special_active or _hurt_animation_timer > 0.0:
|
|
|
|
|
return
|
|
|
|
|
if is_crouching and jump_buffer_timer > 0.0:
|
|
|
|
|
# Abajo + salto es una orden distinta: si el soporte es solido no hace nada.
|
|
|
|
|
# Solo un toque nuevo en suelo puede bajar; no encadena caidas al mantener W.
|
|
|
|
|
jump_buffer_timer = 0.0
|
|
|
|
|
if Input.is_action_just_pressed(&"jump") and Input.is_action_pressed(&"move_down"):
|
|
|
|
|
_try_drop_through()
|
|
|
|
|
return
|
|
|
|
|
if (
|
|
|
|
|
jump_buffer_timer > 0.0
|
|
|
|
|
and not ground_pound_active
|
|
|
|
@@ -476,7 +627,7 @@ func _handle_jump() -> void:
|
|
|
|
|
|
|
|
|
|
## Decide que ataque puede iniciarse con la entrada y el estado actuales.
|
|
|
|
|
func _handle_attack_input() -> void:
|
|
|
|
|
if _special_active or _hurt_animation_timer > 0.0:
|
|
|
|
|
if is_crouching or _special_active or _hurt_animation_timer > 0.0:
|
|
|
|
|
return
|
|
|
|
|
if Input.is_action_just_pressed("attack"):
|
|
|
|
|
_start_punch()
|
|
|
|
@@ -919,6 +1070,8 @@ func _update_animation() -> void:
|
|
|
|
|
animation_name = &"ground_pound"
|
|
|
|
|
elif punch_timer > 0.0:
|
|
|
|
|
animation_name = &"punch"
|
|
|
|
|
elif is_crouching:
|
|
|
|
|
animation_name = &"crouch"
|
|
|
|
|
elif not is_on_floor():
|
|
|
|
|
animation_name = &"jump" if velocity.y < 0.0 else &"fall"
|
|
|
|
|
elif _pound_landing_timer > 0.0:
|
|
|
|
@@ -931,7 +1084,7 @@ func _update_animation() -> void:
|
|
|
|
|
# Cadencia proporcional al desplazamiento real, sin oscilacion artificial de piernas.
|
|
|
|
|
if animation_name == &"walk":
|
|
|
|
|
var pace: float = absf(velocity.x) / maxf(get_move_speed(), 1.0)
|
|
|
|
|
animated_sprite.speed_scale = lerpf(0.65, 1.55, clampf(pace, 0.0, 1.0))
|
|
|
|
|
animated_sprite.speed_scale = lerpf(0.65, 1.0, clampf(pace, 0.0, 1.0))
|
|
|
|
|
else:
|
|
|
|
|
animated_sprite.speed_scale = 1.0
|
|
|
|
|
|
|
|
|
|