mejoras en interfaz y movimento de personaje
This commit is contained in:
1 parent
7a8b03e760
commit
f0fa01607c
29 files changed
+504320
-280
No files matched your search
@@ -0,0 +1,146 @@
|
||||
extends SceneTree
|
||||
|
||||
## godot --headless --path . --script res://tests/test_crouch_runtime.gd
|
||||
const PLAYER_SCENE: PackedScene = preload("res://player/player.tscn")
|
||||
const PLATFORM_SCENE: PackedScene = preload("res://world/terrain/platform.tscn")
|
||||
const GROUND_SCENE: PackedScene = preload("res://world/terrain/ground.tscn")
|
||||
const ENEMY_SCENE: PackedScene = preload("res://enemies/variants/roadie.tscn")
|
||||
var _failures: int = 0
|
||||
var _world: Node2D
|
||||
var _player: CharacterBody2D
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("_run")
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
preload("res://tests/runtime_test_profile.gd").prepare(self)
|
||||
_world = Node2D.new()
|
||||
root.add_child(_world)
|
||||
current_scene = _world
|
||||
var ground: TerrainPiece = _terrain(GROUND_SCENE, 360.0, 120.0)
|
||||
var lower: TerrainPiece = _terrain(PLATFORM_SCENE, 235.0, 20.0)
|
||||
var upper: TerrainPiece = _terrain(PLATFORM_SCENE, 125.0, 20.0)
|
||||
_player = PLAYER_SCENE.instantiate() as CharacterBody2D
|
||||
_player.position = Vector2(320.0, 65.0)
|
||||
_world.add_child(_player)
|
||||
var body: CollisionShape2D = _player.get_node("CollisionShape2D") as CollisionShape2D
|
||||
var hurtbox: CollisionShape2D = _player.get_node("Hurtbox/CollisionShape2D") as CollisionShape2D
|
||||
var sprite: AnimatedSprite2D = _player.get_node("AnimatedSprite2D") as AnimatedSprite2D
|
||||
await _frames(45)
|
||||
_check(_player.is_on_floor() and absf(_player.position.y - 99.0) < 2.0, "Land on upper platform normally")
|
||||
var standing_bottom: float = body.position.y + (body.shape as RectangleShape2D).size.y * 0.5
|
||||
var standing_y: float = _player.position.y
|
||||
Input.action_press(&"move_down")
|
||||
await _frames(5)
|
||||
_check(bool(_player.get("is_crouching")) and sprite.animation == &"crouch", "Down plays a held crouch pose")
|
||||
_check(absf(_player.position.y - standing_y) < 2.0, "Crouch leaves feet on the ground")
|
||||
_check((body.shape as RectangleShape2D).size.y < 52.0 and body.shape == hurtbox.shape, "Body and hurtbox shrink together")
|
||||
_check(is_equal_approx(body.position.y + (body.shape as RectangleShape2D).size.y * 0.5, standing_bottom), "Crouch keeps bottom anchored")
|
||||
_check(is_equal_approx(hurtbox.position.y + (hurtbox.shape as RectangleShape2D).size.y * 0.5, standing_bottom), "Hurtbox bottom anchored")
|
||||
await _frames(20)
|
||||
_check(_player.is_on_floor() and absf(_player.position.y - standing_y) < 2.0, "Down alone never drops")
|
||||
|
||||
Input.action_press(&"jump")
|
||||
await _frames(5)
|
||||
_check(not _player.is_on_floor() and _player.position.y > standing_y, "Down + jump drops instead of jumping up")
|
||||
_check(is_zero_approx(float(_player.get("coyote_timer"))) and int(_player.get("jumps_remaining")) == 1, "Drop consumes only the ground jump")
|
||||
_check(_player.get_collision_exceptions().has(upper) and not _player.get_collision_exceptions().has(lower), "Only the actual upper support is ignored")
|
||||
await _frames(70)
|
||||
_check(_player.is_on_floor() and absf(_player.position.y - 209.0) < 2.0, "Lower platform catches the player even while jump is held")
|
||||
_check(not _player.get_collision_exceptions().has(upper), "Upper collision restored after full clearance")
|
||||
_check(_player.get_collision_exceptions().is_empty(), "No persistent collision exceptions")
|
||||
Input.action_release(&"jump")
|
||||
await _frames(3)
|
||||
Input.action_press(&"jump")
|
||||
await _frames(70)
|
||||
_check(_player.is_on_floor() and absf(_player.position.y - 334.0) < 2.0, "A second press drops to solid ground")
|
||||
_check(_player.get_collision_exceptions().is_empty() and not _player.get_collision_exceptions().has(ground), "Solid ground stays enabled")
|
||||
Input.action_release(&"jump")
|
||||
await _frames(3)
|
||||
Input.action_press(&"jump")
|
||||
await _frames(30)
|
||||
_check(_player.is_on_floor() and absf(_player.position.y - 334.0) < 2.0 and bool(_player.get("is_crouching")), "Down + jump on solid ground neither jumps nor falls")
|
||||
Input.action_release(&"jump")
|
||||
Input.action_release(&"move_down")
|
||||
await _frames(5)
|
||||
_check(not bool(_player.get("is_crouching")) and is_equal_approx((body.shape as RectangleShape2D).size.y, 52.0), "Release restores standing shape")
|
||||
Input.action_press(&"jump")
|
||||
await _frames(10)
|
||||
_check(not _player.is_on_floor() and _player.velocity.y < 0.0, "Normal jump still works")
|
||||
await _frames(85)
|
||||
Input.action_release(&"jump")
|
||||
_check(_player.is_on_floor() and absf(_player.position.y - 209.0) < 2.0, "Can jump back onto previously ignored platform")
|
||||
|
||||
# Verify a blocked stand-up with an actual low solid ceiling.
|
||||
var ceiling: TerrainPiece = _terrain(GROUND_SCENE, 150.0, 35.0)
|
||||
# Avoid starting inside the ceiling: crouch before moving it above the head.
|
||||
ceiling.position.x = 1100.0
|
||||
Input.action_press(&"move_down")
|
||||
await _frames(5)
|
||||
ceiling.position.x = _player.position.x
|
||||
await _frames(3)
|
||||
Input.action_release(&"move_down")
|
||||
await _frames(5)
|
||||
_check(bool(_player.get("is_crouching")), "A solid ceiling prevents expansion into geometry")
|
||||
ceiling.queue_free()
|
||||
await _frames(5)
|
||||
_check(not bool(_player.get("is_crouching")), "Stands after headroom is clear")
|
||||
|
||||
# Freeze actors on the same floor: verify current shape, not cached Area2D overlaps.
|
||||
_player.set_physics_process(false)
|
||||
_player.position = Vector2(320.0, 334.0)
|
||||
_player.velocity = Vector2.ZERO
|
||||
var enemy: CharacterBody2D = ENEMY_SCENE.instantiate() as CharacterBody2D
|
||||
enemy.position = Vector2(270.0, 334.0)
|
||||
_world.add_child(enemy)
|
||||
enemy.set_physics_process(false)
|
||||
enemy.set("attack_direction", 1.0)
|
||||
enemy.call("_set_attack_hitbox_progress", 0.5)
|
||||
await _frames(3)
|
||||
var health: int = int(_player.get("current_health"))
|
||||
var damage: int = int(enemy.get("attack_damage"))
|
||||
_player.call("_set_crouching", true)
|
||||
enemy.call("_update_attack_damage")
|
||||
_check(int(_player.get("current_health")) == health and (enemy.get("attack_hit_targets") as Dictionary).is_empty(), "Crouch avoids a high punch immediately")
|
||||
_player.call("_set_crouching", false)
|
||||
enemy.call("_update_attack_damage")
|
||||
_check(int(_player.get("current_health")) == health - damage, "Standing in the same high punch takes damage")
|
||||
_player.set("invulnerability_timer", 0.0)
|
||||
_player.set("_hurt_animation_timer", 0.0)
|
||||
_player.call("_set_crouching", true)
|
||||
enemy.set("attack_hit_targets", {})
|
||||
enemy.set("attack_start_offset", Vector2(34.0, 12.0))
|
||||
enemy.call("_set_attack_hitbox_progress", 0.5)
|
||||
enemy.call("_update_attack_damage")
|
||||
_check(int(_player.get("current_health")) == health - damage * 2, "A low hit still damages a crouched player")
|
||||
_player.set("invulnerability_timer", 0.0)
|
||||
_player.call("take_damage", 1, enemy.position)
|
||||
_check(int(_player.get("current_health")) == health - damage * 2 - 1, "Crouch is not global invulnerability")
|
||||
current_scene = null
|
||||
_world.queue_free()
|
||||
await process_frame
|
||||
if _failures == 0:
|
||||
print("OK CROUCH: shapes, down+jump, stacked platforms, headroom, high and low attacks")
|
||||
quit(0 if _failures == 0 else 1)
|
||||
|
||||
|
||||
func _terrain(scene: PackedScene, top: float, height: float) -> TerrainPiece:
|
||||
var terrain: TerrainPiece = scene.instantiate() as TerrainPiece
|
||||
terrain.dimensions = Vector2(260.0, height)
|
||||
terrain.position = Vector2(320.0, top + height * 0.5)
|
||||
_world.add_child(terrain)
|
||||
return terrain
|
||||
|
||||
|
||||
func _frames(count: int) -> void:
|
||||
for _frame: int in range(count):
|
||||
await physics_frame
|
||||
await process_frame
|
||||
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
if not condition:
|
||||
_failures += 1
|
||||
push_error(message)
|
||||
Reference in new issue
Block a user