fix: arreglades les colisions "the static cast menner"

This commit is contained in:
2025-10-16 14:14:33 +02:00
parent 9db902c024
commit 545d471654
4 changed files with 55 additions and 26 deletions

View File

@@ -252,7 +252,7 @@ void Player::move() {
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
if (state_ != PlayerState::JUMPING) {
const LineVertical LEFT_SIDE = {x_, y_ + HEIGHT_ - 2, y_ + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo
const LineVertical LEFT_SIDE = {static_cast<int>(x_), static_cast<int>(y_) + static_cast<int>(HEIGHT_) - 2, static_cast<int>(y_) + static_cast<int>(HEIGHT_) - 1}; // Comprueba solo los dos pixels de abajo
const int LY = room_->checkLeftSlopes(&LEFT_SIDE);
if (LY > -1) {
y_ = LY - HEIGHT_;
@@ -292,7 +292,7 @@ void Player::move() {
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
if (state_ != PlayerState::JUMPING) {
const LineVertical RIGHT_SIDE = {x_ + WIDTH_ - 1, y_ + HEIGHT_ - 2, y_ + HEIGHT_ - 1}; // Comprueba solo los dos pixels de abajo
const LineVertical RIGHT_SIDE = {static_cast<int>(x_) + static_cast<int>(WIDTH_) - 1, static_cast<int>(y_) + static_cast<int>(HEIGHT_) - 2, static_cast<int>(y_) + static_cast<int>(HEIGHT_) - 1}; // Comprueba solo los dos pixels de abajo
const int RY = room_->checkRightSlopes(&RIGHT_SIDE);
if (RY > -1) {
y_ = RY - HEIGHT_;
@@ -350,8 +350,8 @@ void Player::move() {
else if (vy_ > 0.0f) {
// Crea el rectangulo de proyección en el eje Y para ver si colisiona
SDL_FRect proj;
proj.x = static_cast<int>(x_);
proj.y = static_cast<int>(y_) + HEIGHT_;
proj.x = x_;
proj.y = y_ + HEIGHT_;
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
proj.w = WIDTH_;
@@ -371,8 +371,9 @@ void Player::move() {
} else {
// Si no hay colisión con los muros, comprueba la colisión con las rampas
if (state_ != PlayerState::JUMPING) { // Las rampas no se miran si se está saltando
const LineVertical LEFT_SIDE = {proj.x, proj.y, proj.y + proj.h - 1};
const LineVertical RIGHT_SIDE = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1};
auto rect = toSDLRect(proj);
const LineVertical LEFT_SIDE = {rect.x, rect.y, rect.y + rect.h - 1};
const LineVertical RIGHT_SIDE = {rect.x + rect.w - 1, rect.y, rect.y + rect.h - 1};
const float POINT = std::max(room_->checkRightSlopes(&RIGHT_SIDE), room_->checkLeftSlopes(&LEFT_SIDE));
if (POINT > -1) {
// No está saltando y hay colisión con una rampa