Animaciones
This commit is contained in:
1 parent
b365c79251
commit
8a5290c5ef
10 files changed
+1581
-288
No files matched your search
@@ -0,0 +1,62 @@
|
||||
"""Engine-independent checks. Run: python -m unittest discover -s tests -v."""
|
||||
from pathlib import Path
|
||||
import math
|
||||
import re
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
FRAMES = ROOT / "player/characters/shared/prototype_sprite_frames.tres"
|
||||
|
||||
|
||||
class PixelCombatResourceTests(unittest.TestCase):
|
||||
def test_all_animation_cells_exist_and_fit_atlas(self):
|
||||
text = FRAMES.read_text(encoding="utf-8")
|
||||
atlas = ET.parse(ROOT / "assets/characters/ankarde/player_pixel.svg").getroot()
|
||||
width, height = int(atlas.attrib["width"]), int(atlas.attrib["height"])
|
||||
declared = re.findall(r'\[sub_resource type="AtlasTexture" id="([^"]+)"\]', text)
|
||||
used = re.findall(r'SubResource\("([^"]+)"\)', text)
|
||||
self.assertEqual(len(declared), 37)
|
||||
self.assertEqual(set(declared), set(used))
|
||||
self.assertEqual(len(declared), len(set(declared)))
|
||||
for x, y, w, h in re.findall(r'region = Rect2\((\d+), (\d+), (\d+), (\d+)\)', text):
|
||||
x, y, w, h = map(int, (x, y, w, h))
|
||||
self.assertEqual((w, h), (64, 64))
|
||||
self.assertLessEqual(x + w, width)
|
||||
self.assertLessEqual(y + h, height)
|
||||
|
||||
def test_player_poses_and_pixel_scale(self):
|
||||
names = set(re.findall(r'"name": &"([^"]+)"', FRAMES.read_text()))
|
||||
self.assertEqual(names, {"idle", "walk", "jump", "fall", "punch", "ground_pound",
|
||||
"land", "special_start", "special", "special_end", "hurt"})
|
||||
scene = (ROOT / "player/player.tscn").read_text()
|
||||
self.assertIn("size = Vector2(26, 52)", scene)
|
||||
self.assertIn("texture_filter = 1", scene)
|
||||
self.assertNotIn("scale = Vector2(0.56, 0.56)", scene)
|
||||
self.assertIn("speed_scale = 1.0", scene)
|
||||
|
||||
def test_new_asset_has_no_external_dependencies(self):
|
||||
atlas = ET.parse(ROOT / "assets/characters/ankarde/player_pixel.svg").getroot()
|
||||
self.assertEqual(atlas.attrib["shape-rendering"], "crispEdges")
|
||||
self.assertFalse(list(atlas.iter("{http://www.w3.org/2000/svg}image")))
|
||||
self.assertFalse(list(atlas.iter("{http://www.w3.org/2000/svg}text")))
|
||||
for rel in ("player/player.gd", "enemies/walker/walker.gd", str(FRAMES.relative_to(ROOT))):
|
||||
for path in re.findall(r'res://([^"\s]+)', (ROOT / rel).read_text()):
|
||||
self.assertTrue((ROOT / path).is_file(), path)
|
||||
|
||||
def test_pulse_rounding_preserves_the_damage_budget(self):
|
||||
# Mathematical invariant used by the GDScript cumulative damage formula.
|
||||
# Runtime behaviour is covered separately by test_pixel_combat_runtime.gd.
|
||||
for total in range(1, 101):
|
||||
for count in range(1, 9):
|
||||
dealt = 0
|
||||
for index in range(count):
|
||||
cumulative = math.ceil(total * (index + 1) / count)
|
||||
damage = cumulative - dealt
|
||||
self.assertGreaterEqual(damage, 0)
|
||||
dealt = cumulative
|
||||
self.assertEqual(dealt, total)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,134 @@
|
||||
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)
|
||||
Reference in new issue
Block a user