135 lines
5.9 KiB
GDScript
135 lines
5.9 KiB
GDScript
extends SceneTree
|
|
|
|
## Run after importing assets:
|
|
## godot --headless --path . --script res://tests/test_pixel_combat_runtime.gd
|
|
## Tests actual scene instantiation, pulse damage, death lifecycle and respawn.
|
|
|
|
var _failures: int = 0
|
|
var _death_signals: int = 0
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _run() -> void:
|
|
var packed: PackedScene = load("res://levels/level_02.tscn") as PackedScene
|
|
if packed == null:
|
|
push_error("Cannot load Level02")
|
|
quit(1)
|
|
return
|
|
var level: Node2D = packed.instantiate() as Node2D
|
|
if level == null:
|
|
push_error("Cannot instantiate Level02")
|
|
quit(1)
|
|
return
|
|
root.add_child(level)
|
|
current_scene = level
|
|
await process_frame
|
|
await physics_frame
|
|
|
|
var player: CharacterBody2D = level.get_node("Player") as CharacterBody2D
|
|
var sprite: AnimatedSprite2D = player.get_node("AnimatedSprite2D") as AnimatedSprite2D
|
|
for animation: StringName in [&"idle", &"walk", &"jump", &"fall", &"punch", &"ground_pound",
|
|
&"land", &"special_start", &"special", &"special_end", &"hurt"]:
|
|
_check(sprite.sprite_frames.has_animation(animation), "Missing animation: " + str(animation))
|
|
if sprite.sprite_frames.has_animation(animation):
|
|
for index: int in range(sprite.sprite_frames.get_frame_count(animation)):
|
|
_check(sprite.sprite_frames.get_frame_texture(animation, index) != null,
|
|
"Missing texture in " + str(animation))
|
|
|
|
# Keep positions fixed, so pulse falloff and screen clipping are deterministic.
|
|
player.set_physics_process(false)
|
|
for node: Node in get_nodes_in_group("enemy"):
|
|
node.set_physics_process(false)
|
|
node.set("is_dead", true)
|
|
var enemy: CharacterBody2D = level.get_node("Enemies").get_child(0) as CharacterBody2D
|
|
enemy.set("is_dead", false)
|
|
enemy.set("max_health", 200)
|
|
enemy.set("current_health", 200)
|
|
enemy.set("respawn_delay", 0.0)
|
|
enemy.set("drops_handled_by_level", true)
|
|
enemy.global_position = player.global_position + Vector2(50, 0)
|
|
var camera: Camera2D = player.get_node("Camera2D") as Camera2D
|
|
camera.force_update_scroll()
|
|
await process_frame
|
|
|
|
player.set("special_charge", 100)
|
|
player.call("_start_special_attack")
|
|
player.call("_update_animation")
|
|
_check(sprite.animation == &"special_start", "Solo must draw the guitar first")
|
|
_check(int(player.get("special_charge")) == 0, "Charge must be consumed once")
|
|
_check(int(enemy.get("current_health")) == 200, "No instant special damage")
|
|
player.set("special_charge", 50)
|
|
player.call("_start_special_attack")
|
|
_check(int(player.get("special_charge")) == 50, "Cannot recast during the solo")
|
|
player.call("_start_punch")
|
|
_check(float(player.get("punch_timer")) == 0.0, "Cannot punch during the solo")
|
|
|
|
player.call("_update_special_attack", 0.35)
|
|
_check(int(enemy.get("current_health")) == 200, "Damage must wait for the windup")
|
|
player.call("_update_special_attack", 0.02)
|
|
_check(int(enemy.get("current_health")) < 200, "First solo pulse must hit")
|
|
var budgets: Dictionary = player.get("_special_damage_budgets")
|
|
var budget: int = int(budgets.get(enemy.get_instance_id(), 0))
|
|
_check(budget > 0 and budget <= 30, "Invalid per-enemy special budget")
|
|
player.call("_update_special_attack", 2.1)
|
|
_check(not bool(player.get("_special_active")), "Solo must finish")
|
|
_check(int(player.get("_special_pulses_sent")) == 4, "Exactly four pulses")
|
|
_check(200 - int(enemy.get("current_health")) == budget, "Pulses must not multiply damage")
|
|
_check(enemy.velocity.x > 0.0 and player.velocity.x < 0.0, "Missing hit/recoil impulses")
|
|
var health_after_solo: int = int(enemy.get("current_health"))
|
|
player.call("_update_special_attack", 1.0)
|
|
_check(int(enemy.get("current_health")) == health_after_solo, "No damage after the solo")
|
|
|
|
enemy.connect(&"died", _on_test_enemy_died)
|
|
var charge_before_death: int = int(player.get("special_charge"))
|
|
enemy.call("take_damage", 1000, player.global_position)
|
|
_check(bool(enemy.get("is_dead")), "Logical death must be immediate")
|
|
_check(enemy.visible, "Enemy must not disappear at zero HP")
|
|
_check(_death_signals == 1, "Death signal must fire once")
|
|
enemy.call("take_damage", 1000, player.global_position)
|
|
_check(_death_signals == 1, "Repeated hits must not produce another death")
|
|
_check(int(player.get("special_charge")) == mini(100, charge_before_death + 25),
|
|
"Death must grant special charge exactly once")
|
|
enemy.call("_update_death_animation", 0.20)
|
|
var enemy_visual: Sprite2D = enemy.get_node("Visual") as Sprite2D
|
|
_check(enemy.visible and not is_zero_approx(enemy_visual.rotation), "Missing collapse animation")
|
|
enemy.call("_update_death_animation", 1.0)
|
|
_check(not enemy.visible, "Enemy must hide after the death animation")
|
|
_check(is_instance_valid(enemy), "Keep the dead node for level KO/total tracking")
|
|
enemy.call("_respawn")
|
|
enemy.set_physics_process(false)
|
|
_check(enemy.visible and not bool(enemy.get("is_dead")), "Respawn state was not restored")
|
|
_check(is_zero_approx(enemy_visual.rotation) and is_equal_approx(enemy_visual.self_modulate.a, 1.0),
|
|
"Respawn must restore the sprite transform and opacity")
|
|
|
|
# Shape query uses the new landing position, with combat shapes restored.
|
|
enemy.global_position = player.global_position + Vector2(30, 0)
|
|
enemy.set("max_health", 50)
|
|
enemy.set("current_health", 50)
|
|
await physics_frame
|
|
await physics_frame
|
|
player.set("_jump_start_position", player.global_position)
|
|
player.set("_jump_peak_height", player.global_position.y - 300.0)
|
|
player.call("_ground_pound_impact")
|
|
_check(int(enemy.get("current_health")) == 38, "High ground pound must deal exactly 12 damage")
|
|
|
|
# Exercise effect processing/cleanup, not just resource loading.
|
|
await create_timer(0.8).timeout
|
|
if _failures == 0:
|
|
print("OK PIXEL COMBAT: animations, solo pulses, recoil, death, rewards, respawn and ground pound")
|
|
else:
|
|
push_error("PIXEL COMBAT: %d failed checks" % _failures)
|
|
quit(0 if _failures == 0 else 1)
|
|
|
|
|
|
func _on_test_enemy_died() -> void:
|
|
_death_signals += 1
|
|
|
|
|
|
func _check(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
_failures += 1
|
|
push_error(message)
|