feat(decals): tiles de decal de sòl compten com a pintats des del load

This commit is contained in:
JailDesigner committed 2026-04-30 19:16:21 +02:00
1 parent 7cd7b4dc4f
commit 7d0aca506a
6 files changed
+74 -12

No files matched your search

-1
View File
@@ -37,5 +37,4 @@ class Hole : public StaticHazard {
};
// TODO(hole-feature): afegir reset de `falling_through_hole_` i `hole_clip_bottom_y_` a `Player::disable()` per simetria.
// TODO(hole-feature): si apareix un quart callsite del càlcul "pixel→tile" o "tileRect", factoritzar a `Map::` (avui: Mummy::reactToCurrentTile, Mummy::isDecalAheadInDir, Player::integrateJump).
// TODO(hole-feature): afegir tests dedicats del comportament de la mòmia amb forats (no requereixen Player real).
+7 -11
View File
@@ -291,13 +291,9 @@ void Mummy::reactToCurrentTile() {
// per a una direcció negativa, el menor (`x`); per a zero, qualsevol
// (no hi ha avenç en aquest eix).
const auto BOX = getCollisionRect();
const auto TS = static_cast<float>(Map::tile_size);
const auto ORIG_X = static_cast<float>(Map::tilemap_origin_x);
const auto ORIG_Y = static_cast<float>(Map::tilemap_origin_y);
const float LEAD_X = (dir_x_ > 0.0F) ? (BOX.x + BOX.w - 1.0F) : BOX.x;
const float LEAD_Y = (dir_y_ > 0.0F) ? (BOX.y + BOX.h - 1.0F) : BOX.y;
const int CUR_COL = static_cast<int>(std::floor((LEAD_X - ORIG_X) / TS));
const int CUR_ROW = static_cast<int>(std::floor((LEAD_Y - ORIG_Y) / TS));
const auto [CUR_COL, CUR_ROW] = Map::pixelToTile(LEAD_X, LEAD_Y);
// Sense canvi de tile no hi ha res a fer — això filtra també tots els
// ticks intra-tile (la majoria, ~16 frames per tile a velocitats típiques).
@@ -318,9 +314,10 @@ void Mummy::reactToCurrentTile() {
// Si el tile nou conté un decal trigger (Hole o futur pinchos plans,
// plaques, etc.), mitja volta immediata. `changeDirection` també
// selecciona l'animació cardinal corresponent.
const auto TS = static_cast<float>(Map::tile_size);
const SDL_FRect TILE_RECT{
.x = (static_cast<float>(CUR_COL) * TS) + ORIG_X,
.y = (static_cast<float>(CUR_ROW) * TS) + ORIG_Y,
.x = (static_cast<float>(CUR_COL) * TS) + static_cast<float>(Map::tilemap_origin_x),
.y = (static_cast<float>(CUR_ROW) * TS) + static_cast<float>(Map::tilemap_origin_y),
.w = TS,
.h = TS,
};
@@ -444,8 +441,6 @@ auto Mummy::isDecalAheadInDir(float dx_signed, float dy_signed) const -> bool {
// tile abans del veritablement adjacent al decal.
const auto BOX = getCollisionRect();
const auto TS = static_cast<float>(Map::tile_size);
const auto ORIG_X = static_cast<float>(Map::tilemap_origin_x);
const auto ORIG_Y = static_cast<float>(Map::tilemap_origin_y);
const auto SIGN_OF = [](float v) -> float {
if (v > 0.0F) { return 1.0F; }
if (v < 0.0F) { return -1.0F; }
@@ -453,8 +448,9 @@ auto Mummy::isDecalAheadInDir(float dx_signed, float dy_signed) const -> bool {
};
const float CENTER_X = BOX.x + (BOX.w * 0.5F);
const float CENTER_Y = BOX.y + (BOX.h * 0.5F);
const float TILE_X = (std::floor((CENTER_X - ORIG_X) / TS) * TS) + ORIG_X;
const float TILE_Y = (std::floor((CENTER_Y - ORIG_Y) / TS) * TS) + ORIG_Y;
const auto [CUR_COL, CUR_ROW] = Map::pixelToTile(CENTER_X, CENTER_Y);
const float TILE_X = (static_cast<float>(CUR_COL) * TS) + static_cast<float>(Map::tilemap_origin_x);
const float TILE_Y = (static_cast<float>(CUR_ROW) * TS) + static_cast<float>(Map::tilemap_origin_y);
const SDL_FRect NEXT{
.x = TILE_X + (SIGN_OF(dx_signed) * TS),
.y = TILE_Y + (SIGN_OF(dy_signed) * TS),