fix: les rampes s'acabaven de trencar

This commit is contained in:
2026-04-09 21:54:18 +02:00
parent 4f890586f1
commit 138eb26249
2 changed files with 16 additions and 17 deletions

View File

@@ -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;
}