feat(entities): bloc collision i anchor:feet per entitats amb falsa perspectiva
This commit is contained in:
1 parent
1af5ef861f
commit
e6b612d164
7 files changed
+162
-5
No files matched your search
@@ -14,6 +14,10 @@
|
||||
// T10 torch anim — Torch llegeix 4 frames del YAML i el tick avança frame.
|
||||
// T11 sarcofag — tile_size [3,1] llegit; perímetre 8; falsa perspectiva:
|
||||
// el sprite.height no canvia la caixa lògica 48×16.
|
||||
// T12 collision — `Entity::CollisionBox` encastada al sprite: la caixa
|
||||
// retornada coincideix amb les dimensions del bloc
|
||||
// `collision:` del YAML; sense caixa, coincideix amb el
|
||||
// sprite sencer (pixel_rect).
|
||||
//
|
||||
// Execució (des de la ruta del repo):
|
||||
// make build && cd build && ctest --output-on-failure
|
||||
@@ -342,6 +346,36 @@ namespace {
|
||||
REQUIRE(sarc->getPerimeterSize() == 8);
|
||||
}
|
||||
|
||||
void testCollisionBox() {
|
||||
std::cout << "[T12] collision box encastada al sprite\n";
|
||||
// Torch sense bloc `collision:` → getCollisionRect == pixel_rect.
|
||||
fkyaml::node torch_tmpl = EntityLoader::loadTemplate("torch");
|
||||
Torch torch(torch_tmpl);
|
||||
torch.setPixelRect({.x = 100.0F, .y = 200.0F, .w = 16.0F, .h = 16.0F});
|
||||
const auto TRECT = torch.getCollisionRect();
|
||||
REQUIRE(static_cast<int>(TRECT.w) == 16);
|
||||
REQUIRE(static_cast<int>(TRECT.h) == 16);
|
||||
REQUIRE(static_cast<int>(TRECT.x) == 100);
|
||||
REQUIRE(static_cast<int>(TRECT.y) == 200);
|
||||
|
||||
// Mummy amb `collision: { size: [12, 12] }` i sprite 12×24 → caixa
|
||||
// auto-centrada bottom dels peus: offset_x = (12-12)/2 = 0,
|
||||
// offset_y = 24 - 12 = 12. Amb pixel_rect a (100, 200, 12, 24),
|
||||
// la caixa ha de sortir a (100, 212, 12, 12) i feet_y = 224.
|
||||
fkyaml::node mummy_tmpl = EntityLoader::loadTemplate("mummy");
|
||||
Mummy mummy(mummy_tmpl);
|
||||
// Apliquem el CollisionBox com fa el loader (readCollisionBox)
|
||||
// amb sprite 12×24, offset calculat per defecte.
|
||||
mummy.setCollisionBox({.offset_x = 0, .offset_y = 12, .width = 12, .height = 12});
|
||||
mummy.setPixelRect({.x = 100.0F, .y = 200.0F, .w = 12.0F, .h = 24.0F});
|
||||
const auto MRECT = mummy.getCollisionRect();
|
||||
REQUIRE(static_cast<int>(MRECT.x) == 100);
|
||||
REQUIRE(static_cast<int>(MRECT.y) == 212);
|
||||
REQUIRE(static_cast<int>(MRECT.w) == 12);
|
||||
REQUIRE(static_cast<int>(MRECT.h) == 12);
|
||||
REQUIRE(static_cast<int>(mummy.getFeetY()) == 224);
|
||||
}
|
||||
|
||||
void testTorchAnimation() {
|
||||
std::cout << "[T10] torch animation wired from yaml\n";
|
||||
// Regressió: el torch.yaml declarava `frames: [0]` i el render no
|
||||
@@ -379,6 +413,7 @@ auto main() -> int {
|
||||
testDecorationFlags();
|
||||
testLoadFromLevel();
|
||||
testSarcophagusYaml();
|
||||
testCollisionBox();
|
||||
testTorchAnimation();
|
||||
|
||||
if (g_failures == 0) {
|
||||
|
||||
Reference in new issue
Block a user