mil arreglos en les putes costeres
This commit is contained in:
@@ -25,6 +25,10 @@ auto TileCollider::isSolid(int tile_x, int tile_y) const -> bool {
|
||||
return getTileAt(tile_x, tile_y) == Tile::WALL;
|
||||
}
|
||||
|
||||
// Calcula la Y de la superficie de una slope en un pixel X concreto.
|
||||
// Las slopes son de 45° y ocupan un tile de 8x8:
|
||||
// SLOPE_L (\): alto a la izquierda, bajo a la derecha. surface = bottom - (7 - x_in_tile)
|
||||
// SLOPE_R (/): alto a la derecha, bajo a la izquierda. surface = bottom - x_in_tile
|
||||
auto TileCollider::getSlopeY(int tile_x, int tile_y, float px) const -> float {
|
||||
float tile_bottom = static_cast<float>((tile_y + 1) * TS - 1);
|
||||
float x_in_tile = px - static_cast<float>(tile_x * TS);
|
||||
@@ -32,11 +36,9 @@ auto TileCollider::getSlopeY(int tile_x, int tile_y, float px) const -> float {
|
||||
|
||||
auto tile = getTileAt(tile_x, tile_y);
|
||||
if (tile == Tile::SLOPE_L) {
|
||||
// \ descendente de izquierda a derecha
|
||||
return tile_bottom - (static_cast<float>(TS - 1) - x_in_tile);
|
||||
}
|
||||
if (tile == Tile::SLOPE_R) {
|
||||
// / descendente de derecha a izquierda
|
||||
return tile_bottom - x_in_tile;
|
||||
}
|
||||
return tile_bottom;
|
||||
@@ -88,12 +90,21 @@ auto TileCollider::checkCeiling(float x, float y, float w) const -> float {
|
||||
|
||||
// --- Colisión con suelo (landing) ---
|
||||
|
||||
// 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).
|
||||
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));
|
||||
int end_row = toTile(static_cast<int>(foot_y_new));
|
||||
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) {
|
||||
@@ -109,10 +120,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 (tile == Tile::SLOPE_L || tile == Tile::SLOPE_R) {
|
||||
} else if (!block_slope_landing && (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);
|
||||
if (foot_y_new >= slope_y && foot_y_current <= slope_y + TS) {
|
||||
// Solo aterrizar si los pies estaban por encima de la superficie
|
||||
if (foot_y_new >= slope_y && foot_y_current <= slope_y) {
|
||||
floor_y = slope_y;
|
||||
}
|
||||
}
|
||||
@@ -149,15 +161,43 @@ auto TileCollider::hasGroundBelow(float x, float foot_y, float w) const -> bool
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- Comprueba si el jugador está parcialmente dentro de algún slope ---
|
||||
|
||||
// Devuelve true si algún pie del jugador está POR DEBAJO de la superficie de algún
|
||||
// tile de slope que solape. Esto indica que el jugador está "dentro" de una slope
|
||||
// (por ejemplo, tras hacer drop-through o al saltar desde abajo).
|
||||
// Cuando esto ocurre, checkFloor bloquea el aterrizaje en slopes para evitar que
|
||||
// el jugador se quede pegado encima de una slope que está atravesando.
|
||||
auto TileCollider::isInsideAnySlope(float x, float foot_y, float w) const -> bool {
|
||||
int foot_row = toTile(static_cast<int>(foot_y));
|
||||
int left_col = toTile(static_cast<int>(x));
|
||||
int right_col = toTile(static_cast<int>(x + w - 1));
|
||||
|
||||
for (int row = foot_row - 1; row <= foot_row; ++row) {
|
||||
for (int col = left_col; col <= right_col; ++col) {
|
||||
auto tile = getTileAt(col, row);
|
||||
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);
|
||||
if (foot_y > slope_y) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- Detección de slope debajo (transición ground→slope) ---
|
||||
|
||||
// Busca una slope directamente debajo del jugador (para transición ground→slope).
|
||||
// Escanea la fila de los pies Y la fila superior: las slopes en escalera siempre
|
||||
// tienen el tile de entrada una fila arriba del suelo desde el que se accede.
|
||||
auto TileCollider::checkSlopeBelow(float x, float foot_y, float w) const -> SlopeInfo {
|
||||
int foot_row = toTile(static_cast<int>(foot_y));
|
||||
int left_col = toTile(static_cast<int>(x));
|
||||
int right_col = toTile(static_cast<int>(x + w - 1));
|
||||
|
||||
// Comprobar la fila de los pies Y la fila de arriba
|
||||
// (la slope entry puede estar un tile arriba del nivel de la plataforma)
|
||||
for (int row = foot_row - 1; row <= foot_row; ++row) {
|
||||
for (int col = left_col; col <= right_col; ++col) {
|
||||
auto tile = getTileAt(col, row);
|
||||
|
||||
Reference in New Issue
Block a user