slopes solides i a cagar

This commit is contained in:
2026-04-07 20:58:37 +02:00
parent 70efb39b88
commit da5d880626
8 changed files with 73 additions and 67 deletions

View File

@@ -31,7 +31,6 @@ Room::Room(const std::string& room_path, std::shared_ptr<Scoreboard::Data> data)
// Crea el renderizador del tilemap (necesita tile_map_, tile_set_width_, surface_, bg_color_, conveyor_belt_direction_)
tilemap_renderer_ = std::make_unique<TilemapRenderer>(tile_map_, tile_set_width_, surface_, bg_color_, conveyor_belt_direction_);
tilemap_renderer_->initialize(room->collision_tile_map);
}
// Destructor

View File

@@ -81,7 +81,9 @@ auto TileCollider::checkCeiling(float x, float y, float w) const -> float {
int right_col = toTile(static_cast<int>(x + w - 1));
for (int col = left_col; col <= right_col; ++col) {
if (isSolid(col, top_row)) {
auto tile = getTileAt(col, top_row);
// Slopes actúan como techo (no se atraviesan desde abajo)
if (tile == Tile::WALL || tile == Tile::SLOPE_L || tile == Tile::SLOPE_R) {
return static_cast<float>((top_row + 1) * TS);
}
}
@@ -93,9 +95,7 @@ auto TileCollider::checkCeiling(float x, float y, float w) const -> float {
// Busca suelo entre foot_y_current y foot_y_new (rango de caída del frame).
// WALL: siempre bloquea.
// PASSABLE: solo si los pies estaban por encima del borde superior del tile.
// SLOPE: solo si los pies estaban por encima de la superficie Y el jugador no está
// parcialmente dentro de otra slope (evita aterrizar al hacer drop-through
// o al saltar a través de una slope desde abajo).
// SLOPE: siempre bloquea (las slopes son sólidas, como muros en diagonal).
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
auto TileCollider::checkFloor(float x, float foot_y_current, float w, float foot_y_new) const -> FloorHit {
int start_row = toTile(static_cast<int>(foot_y_current));
@@ -103,9 +103,6 @@ auto TileCollider::checkFloor(float x, float foot_y_current, float w, float foot
int left_col = toTile(static_cast<int>(x));
int right_col = toTile(static_cast<int>(x + w - 1));
// Si algún pie está por debajo de la superficie de algún slope → bloquear aterrizaje en slopes
bool block_slope_landing = isInsideAnySlope(x, foot_y_current, w);
FloorHit best;
for (int row = start_row; row <= end_row; ++row) {
@@ -121,11 +118,11 @@ auto TileCollider::checkFloor(float x, float foot_y_current, float w, float foot
if (foot_y_current <= tile_top) {
floor_y = tile_top;
}
} else if (!block_slope_landing && (tile == Tile::SLOPE_L || tile == Tile::SLOPE_R)) {
} else if (tile == Tile::SLOPE_L || tile == Tile::SLOPE_R) {
float check_x = (tile == Tile::SLOPE_L) ? x : x + w - 1;
float slope_y = getSlopeY(col, row, check_x);
// Solo aterrizar si los pies estaban por encima de la superficie
if (foot_y_new >= slope_y && foot_y_current <= slope_y) {
// Slopes son sólidas: aterrizar siempre que los pies lleguen a la superficie
if (foot_y_new >= slope_y) {
floor_y = slope_y;
}
}
@@ -204,15 +201,15 @@ auto TileCollider::checkSlopeBelow(float x, float foot_y, float w) const -> Slop
for (int col = left_col; col <= right_col; ++col) {
auto tile = getTileAt(col, row);
if (tile == Tile::SLOPE_L) {
float foot_x = (col == left_col) ? x : x + w - 1;
float slope_y = getSlopeY(col, row, foot_x);
// SLOPE_L (\): alta a la izquierda → siempre pie izquierdo
float slope_y = getSlopeY(col, row, x);
if (slope_y <= foot_y && slope_y >= foot_y - TS) {
return {.on_slope = true, .type = Tile::SLOPE_L, .tile_x = col, .tile_y = row, .surface_y = slope_y};
}
}
if (tile == Tile::SLOPE_R) {
float foot_x = (col == right_col) ? x + w - 1 : x;
float slope_y = getSlopeY(col, row, foot_x);
// SLOPE_R (/): alta a la derecha → siempre pie derecho
float slope_y = getSlopeY(col, row, x + w - 1);
if (slope_y <= foot_y && slope_y >= foot_y - TS) {
return {.on_slope = true, .type = Tile::SLOPE_R, .tile_x = col, .tile_y = row, .surface_y = slope_y};
}