fix: les rampes s'acabaven de trencar
This commit is contained in:
@@ -202,9 +202,9 @@ void Player::handleJumpAndDrop() {
|
||||
if (wanna_down_ && state_ == State::ON_GROUND) {
|
||||
const auto& tc = room_->getTileCollider();
|
||||
float foot_y = y_ + HEIGHT;
|
||||
int foot_row = static_cast<int>(foot_y) / Tile::SIZE;
|
||||
int left_col = static_cast<int>(x_) / Tile::SIZE;
|
||||
int right_col = static_cast<int>(x_ + WIDTH - 1) / Tile::SIZE;
|
||||
int foot_row = tc.toTile(static_cast<int>(foot_y));
|
||||
int left_col = tc.toTile(static_cast<int>(x_));
|
||||
int right_col = tc.toTile(static_cast<int>(x_ + WIDTH - 1));
|
||||
|
||||
for (int col = left_col; col <= right_col; ++col) {
|
||||
if (tc.getTileAt(col, foot_row) == TileCollider::Tile::PASSABLE) {
|
||||
@@ -267,9 +267,9 @@ void Player::followSlope() {
|
||||
float surface_y = tc.getSlopeY(slope_tile_x_, slope_tile_y_, foot_x);
|
||||
y_ = surface_y - HEIGHT;
|
||||
|
||||
// Comprobar si hemos salido del tile actual
|
||||
int foot_tile_x = static_cast<int>(foot_x) / Tile::SIZE;
|
||||
int foot_tile_y = static_cast<int>(y_ + HEIGHT) / Tile::SIZE;
|
||||
// Comprobar si hemos salido del tile actual (coordenadas del mapa extendido)
|
||||
int foot_tile_x = tc.toTile(static_cast<int>(foot_x));
|
||||
int foot_tile_y = tc.toTile(static_cast<int>(y_ + HEIGHT));
|
||||
|
||||
if (foot_tile_x != slope_tile_x_ || foot_tile_y != slope_tile_y_) {
|
||||
// Buscar slope en el tile calculado y en el de abajo (la escalera de slopes
|
||||
@@ -302,8 +302,8 @@ void Player::exitSlope() {
|
||||
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;
|
||||
int row = tc.toTile(static_cast<int>(check_y));
|
||||
y_ = tc.toPixel(row) - HEIGHT;
|
||||
transitionToState(State::ON_GROUND);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,14 @@ class TileCollider {
|
||||
// Devuelve true si el rectángulo del jugador solapa algún tile KILL
|
||||
[[nodiscard]] auto touchesKillTile(float x, float y, float w, float h) const -> bool;
|
||||
|
||||
// Convierte píxeles en room-space a índice de tile en el mapa extendido.
|
||||
[[nodiscard]] auto toTile(int px) const -> int { return (px + border_px_) / TS; }
|
||||
|
||||
// Convierte índice de tile del mapa extendido a píxeles en room-space.
|
||||
[[nodiscard]] auto toPixel(int tile) const -> float {
|
||||
return static_cast<float>((tile * TS) - border_px_);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr int TS = ::Tile::SIZE;
|
||||
|
||||
@@ -61,13 +69,4 @@ class TileCollider {
|
||||
int border_px_; // Offset en píxeles (CollisionBorder::PX)
|
||||
|
||||
const std::vector<int>& tile_map_;
|
||||
|
||||
// Convierte píxeles en room-space a índice de tile en el mapa extendido.
|
||||
// Nota: asume que px >= -border_px_ (el jugador no puede estar más allá del borde).
|
||||
[[nodiscard]] auto toTile(int px) const -> int { return (px + border_px_) / TS; }
|
||||
|
||||
// Convierte índice de tile del mapa extendido a píxeles en room-space.
|
||||
[[nodiscard]] auto toPixel(int tile) const -> float {
|
||||
return static_cast<float>((tile * TS) - border_px_);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user