mil arreglos en les putes costeres

This commit is contained in:
2026-04-06 22:51:30 +02:00
parent 5393a861d1
commit 5c40b9bbf9
6 changed files with 107 additions and 58 deletions

View File

@@ -246,10 +246,14 @@ void Player::moveHorizontal(float delta_time) {
}
}
// Ajusta Y del jugador para seguir la superficie de la slope mientras camina.
// Si el pie sale del tile actual, busca el siguiente tile de slope en la fila
// actual y la inferior (las slopes en escalera bajan una fila por tile).
// Si no encuentra slope, llama a exitSlope().
void Player::followSlope() {
const auto& tc = room_->getTileCollider();
// Seleccionar pie según tipo de slope
// SLOPE_L (\): pie izquierdo. SLOPE_R (/): pie derecho.
float foot_x = (slope_type_ == TileCollider::Tile::SLOPE_L) ? x_ : x_ + WIDTH - 1;
// Calcular Y en la slope actual
@@ -261,63 +265,56 @@ void Player::followSlope() {
int foot_tile_y = static_cast<int>(y_ + HEIGHT) / Tile::SIZE;
if (foot_tile_x != slope_tile_x_ || foot_tile_y != slope_tile_y_) {
// Mirar si el nuevo tile también es slope
auto new_tile = tc.getTileAt(foot_tile_x, foot_tile_y);
if (new_tile == TileCollider::Tile::SLOPE_L || new_tile == TileCollider::Tile::SLOPE_R) {
slope_tile_x_ = foot_tile_x;
slope_tile_y_ = foot_tile_y;
slope_type_ = new_tile;
surface_y = tc.getSlopeY(slope_tile_x_, slope_tile_y_, foot_x);
y_ = surface_y - HEIGHT;
} else {
exitSlope();
// Buscar slope en el tile calculado y en el de abajo (la escalera de slopes
// siempre tiene el siguiente tile una fila arriba o abajo)
for (int row = foot_tile_y; row <= foot_tile_y + 1; ++row) {
auto new_tile = tc.getTileAt(foot_tile_x, row);
if (new_tile == TileCollider::Tile::SLOPE_L || new_tile == TileCollider::Tile::SLOPE_R) {
slope_tile_x_ = foot_tile_x;
slope_tile_y_ = row;
slope_type_ = new_tile;
surface_y = tc.getSlopeY(slope_tile_x_, slope_tile_y_, foot_x);
y_ = surface_y - HEIGHT;
return;
}
}
exitSlope();
}
}
// El jugador ha salido del tile de slope sin encontrar otra slope adyacente.
// Comprueba si hay suelo debajo (foot_y y foot_y+1 para cubrir el boundary exacto
// entre filas cuando se sale por el extremo inferior de la slope).
// Si hay suelo, snapea al borde del tile. Si no, empieza a caer.
void Player::exitSlope() {
const auto& tc = room_->getTileCollider();
// Corrección de 1px al salir por arriba de la slope
y_ += 1.0F;
float foot_y = y_ + HEIGHT;
if (tc.hasGroundBelow(x_, foot_y, WIDTH)) {
transitionToState(State::ON_GROUND);
} else {
vy_ = 0.0F;
transitionToState(State::ON_AIR);
// Comprobar suelo en la fila actual y la siguiente (al salir por abajo de una slope,
// los pies pueden estar en el último pixel de la fila, justo antes del suelo)
for (int check = 0; check <= 1; ++check) {
float check_y = foot_y + check;
if (tc.hasGroundBelow(x_, check_y, WIDTH)) {
int row = static_cast<int>(check_y) / Tile::SIZE;
y_ = static_cast<float>(row * Tile::SIZE) - HEIGHT;
transitionToState(State::ON_GROUND);
return;
}
}
vy_ = 0.0F;
transitionToState(State::ON_AIR);
}
// Detecta si el jugador ha pisado una slope caminando desde suelo plano.
// Las slopes en escalera están una fila arriba del suelo, así que checkSlopeBelow
// también mira la fila superior.
void Player::detectSlopeEntry() {
const auto& tc = room_->getTileCollider();
float foot_y = y_ + HEIGHT;
auto slope = tc.checkSlopeBelow(x_, foot_y, WIDTH);
// LOG: siempre mostrar lo que ve detectSlopeEntry
int left_col = static_cast<int>(x_) / Tile::SIZE;
int right_col = static_cast<int>(x_ + WIDTH - 1) / Tile::SIZE;
int row = static_cast<int>(foot_y) / Tile::SIZE;
auto tile_l = tc.getTileAt(left_col, row);
auto tile_r = tc.getTileAt(right_col, row);
SDL_Log("detectSlopeEntry: foot_y=%.1f row=%d cols=[%d,%d] tiles=[%d,%d] slope.on=%d",
foot_y,
row,
left_col,
right_col,
static_cast<int>(tile_l),
static_cast<int>(tile_r),
slope.on_slope ? 1 : 0);
if (slope.on_slope) {
SDL_Log(" -> ENTERING slope type=%d tile=(%d,%d) surface_y=%.1f new_y=%.1f",
static_cast<int>(slope.type),
slope.tile_x,
slope.tile_y,
slope.surface_y,
slope.surface_y - HEIGHT);
y_ = slope.surface_y - HEIGHT;
slope_tile_x_ = slope.tile_x;
slope_tile_y_ = slope.tile_y;
@@ -392,9 +389,7 @@ void Player::checkFalling() {
// ON_GROUND: comprobar si sigue habiendo suelo
float foot_y = y_ + HEIGHT;
bool ground = tc.hasGroundBelow(x_, foot_y, WIDTH);
if (!ground) {
SDL_Log("checkFalling: NO ground at foot_y=%.1f x=%.1f -> ON_AIR", foot_y, x_);
if (!tc.hasGroundBelow(x_, foot_y, WIDTH)) {
vy_ = 0.0F;
transitionToState(State::ON_AIR);
}