slopes solides i a cagar
This commit is contained in:
@@ -181,14 +181,6 @@ void Player::handleJumpAndDrop() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop-through: slope
|
||||
if (wanna_down_ && state_ == State::ON_SLOPE) {
|
||||
y_ += 1.0F;
|
||||
vy_ = 0.0F;
|
||||
transitionToState(State::ON_AIR);
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop-through: plataforma passable
|
||||
if (wanna_down_ && state_ == State::ON_GROUND) {
|
||||
auto [tc, ox, oy] = getCollisionContext();
|
||||
@@ -399,6 +391,17 @@ void Player::checkFalling() {
|
||||
// ON_GROUND: comprobar si sigue habiendo suelo
|
||||
float foot_y = (y_ + oy) + HEIGHT;
|
||||
if (!tc.hasGroundBelow(x_ + ox, foot_y, WIDTH)) {
|
||||
// Sticking: si no hay suelo pero hay slope debajo, snapear a ella
|
||||
// para transición suave suelo→slope (bajada de rampas sin caer)
|
||||
auto slope = tc.checkSlopeBelow(x_ + ox, foot_y, WIDTH);
|
||||
if (slope.on_slope) {
|
||||
y_ = slope.surface_y - HEIGHT - oy;
|
||||
slope_tile_x_ = slope.tile_x;
|
||||
slope_tile_y_ = slope.tile_y;
|
||||
slope_type_ = slope.type;
|
||||
transitionToState(State::ON_SLOPE);
|
||||
return;
|
||||
}
|
||||
vy_ = 0.0F;
|
||||
transitionToState(State::ON_AIR);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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};
|
||||
}
|
||||
|
||||
@@ -821,11 +821,20 @@ void Game::checkPlayerIsOnBorder() {
|
||||
// La dirección es la opuesta: si salimos por TOP, la vieja queda en BOTTOM
|
||||
Room::Border opposite = Room::Border::NONE;
|
||||
switch (BORDER) {
|
||||
case Room::Border::TOP: opposite = Room::Border::BOTTOM; break;
|
||||
case Room::Border::BOTTOM: opposite = Room::Border::TOP; break;
|
||||
case Room::Border::LEFT: opposite = Room::Border::RIGHT; break;
|
||||
case Room::Border::RIGHT: opposite = Room::Border::LEFT; break;
|
||||
default: break;
|
||||
case Room::Border::TOP:
|
||||
opposite = Room::Border::BOTTOM;
|
||||
break;
|
||||
case Room::Border::BOTTOM:
|
||||
opposite = Room::Border::TOP;
|
||||
break;
|
||||
case Room::Border::LEFT:
|
||||
opposite = Room::Border::RIGHT;
|
||||
break;
|
||||
case Room::Border::RIGHT:
|
||||
opposite = Room::Border::LEFT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
player_->setAdjacentRoom(transition_old_room_, opposite);
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ class Game {
|
||||
float transition_timer_{0.0F}; // Tiempo transcurrido en la transición
|
||||
std::shared_ptr<Room> transition_old_room_; // Habitación saliente (se mantiene viva durante la transición)
|
||||
Room::Border transition_direction_{Room::Border::NONE}; // Dirección de la transición
|
||||
bool transition_just_ended_{false}; // Cooldown de 1 frame tras finalizar transición
|
||||
bool transition_just_ended_{false}; // Cooldown de 1 frame tras finalizar transición
|
||||
|
||||
// Variables de demo mode
|
||||
DemoData demo_; // Variables para el modo demo
|
||||
|
||||
Reference in New Issue
Block a user