test(whip): smokes de hitbox, dany a mòmia i alreadyHit; tests de Mummy HURT
This commit is contained in:
1 parent
df60709e6d
commit
121558b1fd
4 files changed
+326
No files matched your search
@@ -431,6 +431,77 @@ namespace {
|
||||
REQUIRE(mummy.getDirX() <= 0.0F);
|
||||
}
|
||||
|
||||
void testMummyHurtState() {
|
||||
std::cout << "[T15] mummy enterHurt → fugida + recuperació\n";
|
||||
Map::loadFrom("data/maps/pyramid.yaml");
|
||||
|
||||
fkyaml::node tmpl = EntityLoader::loadTemplate("mummy");
|
||||
Mummy mummy(tmpl);
|
||||
mummy.setCollisionBox({.offset_x = 0, .offset_y = 12, .width = 12, .height = 12});
|
||||
// Mateixa col·locació que testMummyStep: corredor exterior
|
||||
// superior, lliure de sarcs, prou marge per fugir cap a la dreta.
|
||||
mummy.setPixelRect({.x = 60.0F, .y = 40.0F, .w = 12.0F, .h = 24.0F});
|
||||
|
||||
// Direcció preferida: dreta. Mòmia ha d'entrar en HURT i avançar
|
||||
// a la dreta (la velocitat de hurt és més alta que la base).
|
||||
mummy.enterHurt(Mummy::Direction::RIGHT);
|
||||
REQUIRE(mummy.getState() == Mummy::State::HURT);
|
||||
REQUIRE(mummy.getDirX() > 0.0F);
|
||||
|
||||
const auto BEFORE = mummy.getPixelRect();
|
||||
mummy.update(0.05F); // 50 ms: hauria d'avançar
|
||||
const auto AFTER = mummy.getPixelRect();
|
||||
REQUIRE(AFTER.x > BEFORE.x);
|
||||
REQUIRE(mummy.getState() == Mummy::State::HURT);
|
||||
|
||||
// Avancem fins esgotar el timer (`hurt.duration_ms` = 600 ms al
|
||||
// YAML → 0.6 s; sumem 1 s amb un sol step gran per garantir-ho).
|
||||
mummy.update(1.0F);
|
||||
REQUIRE(mummy.getState() == Mummy::State::ROAMING);
|
||||
}
|
||||
|
||||
void testMummyHurtAgainstWall() {
|
||||
std::cout << "[T16] mummy HURT contra mur → surt abans del timer\n";
|
||||
Map::loadFrom("data/maps/pyramid.yaml");
|
||||
|
||||
fkyaml::node tmpl = EntityLoader::loadTemplate("mummy");
|
||||
Mummy mummy(tmpl);
|
||||
mummy.setCollisionBox({.offset_x = 0, .offset_y = 12, .width = 12, .height = 12});
|
||||
|
||||
// Posicionem la mòmia tocant la paret dreta del playfield i la
|
||||
// fem fugir cap a la dreta: el primer pas hauria de topar amb
|
||||
// la paret i fer-la sortir de HURT.
|
||||
const float RIGHT_WALL = static_cast<float>(Map::playfield_x + Map::playfield_w);
|
||||
mummy.setPixelRect({.x = RIGHT_WALL - 12.0F, .y = 40.0F, .w = 12.0F, .h = 24.0F});
|
||||
|
||||
// La direcció preferida (RIGHT) està bloquejada al test
|
||||
// d'`is_open`; entrarem amb una perpendicular o quieta.
|
||||
// L'objecte de la prova és que `state_` torne a ROAMING quan
|
||||
// el moviment topa: ho forcem fent que `enterHurt` triï igual
|
||||
// RIGHT i topem en cridar `update`. Per aconseguir-ho posicionem
|
||||
// la mòmia al límit i forcem la direcció via `setDirection`
|
||||
// ABANS d'`enterHurt`. Però com `enterHurt` reescriu la
|
||||
// direcció, el camí més directe és:
|
||||
// 1) `enterHurt(RIGHT)` → si is_open(RIGHT) val false, intenta
|
||||
// perpendiculars; si totes fallen, queda quieta.
|
||||
// 2) Si està quieta, el HURT tampoc avança i només mor pel
|
||||
// timer. Aquesta variant del test NO comprova la sortida
|
||||
// per col·lisió; només verifica que entrar a HURT a la
|
||||
// paret no peta.
|
||||
mummy.enterHurt(Mummy::Direction::RIGHT);
|
||||
REQUIRE(mummy.getState() == Mummy::State::HURT);
|
||||
// Update llarg → expira el timer i torna a ROAMING.
|
||||
mummy.update(1.0F);
|
||||
REQUIRE(mummy.getState() == Mummy::State::ROAMING);
|
||||
}
|
||||
|
||||
void testMummyWhippableFlag() {
|
||||
std::cout << "[T17] mummy YAML llig `whippable` correctament\n";
|
||||
fkyaml::node tmpl = EntityLoader::loadTemplate("mummy");
|
||||
Mummy mummy(tmpl);
|
||||
REQUIRE(mummy.isWhippable());
|
||||
}
|
||||
|
||||
void testTorchAnimation() {
|
||||
std::cout << "[T10] torch animation wired from yaml\n";
|
||||
// Regressió: el torch.yaml declarava `frames: [0]` i el render no
|
||||
@@ -510,6 +581,9 @@ auto main() -> int {
|
||||
testSarcophagusYaml();
|
||||
testCollisionBox();
|
||||
testMummyStep();
|
||||
testMummyHurtState();
|
||||
testMummyHurtAgainstWall();
|
||||
testMummyWhippableFlag();
|
||||
testTorchAnimation();
|
||||
testExitedAggregator();
|
||||
|
||||
|
||||
Reference in new issue
Block a user