diff --git a/source/player.cpp b/source/player.cpp index 1d1c704..6d969d8 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -240,17 +240,34 @@ void Player::move() // Comprueba colisiones con rampas else { - const tile_e slope = checkSlopes(); - // Se mueve hacia la derecha y cuesta hacia la derecha - if (sprite->getFlip() == SDL_FLIP_NONE && slope == t_slope_r) - { // Recoloca - y = -h + room->getSlopeHeight(feet[1], t_slope_r); + tile_e slope = checkUpSlopes(); + if (slope != t_empty) + { // Se mueve hacia la derecha y cuesta hacia la derecha + if (sprite->getFlip() == SDL_FLIP_NONE && slope == t_slope_r) + { // Recoloca + y = -h + room->getSlopeHeight(feet[1], t_slope_r); + } + + // Se mueve hacia la izquierda y cuesta hacia la izquierda + if (sprite->getFlip() == SDL_FLIP_HORIZONTAL && slope == t_slope_l) + { // Recoloca + y = -h + room->getSlopeHeight(feet[0], t_slope_l); + } } - // Se mueve hacia la izquierda y cuesta hacia la izquierda - if (sprite->getFlip() == SDL_FLIP_HORIZONTAL && slope == t_slope_l) - { // Recoloca - y = -h + room->getSlopeHeight(feet[0], t_slope_l); + slope = checkDownSlopes(); + if (slope != t_empty) + { // Se mueve hacia la derecha y cuesta hacia la izquierda + if (sprite->getFlip() == SDL_FLIP_NONE && slope == t_slope_l) + { // Recoloca + y = -h + room->getSlopeHeight(underFeet[0], t_slope_l); + } + + // Se mueve hacia la izquierda y cuesta hacia la derecha + if (sprite->getFlip() == SDL_FLIP_HORIZONTAL && slope == t_slope_r) + { // Recoloca + y = -h + room->getSlopeHeight(underFeet[1], t_slope_r); + } } } @@ -328,7 +345,7 @@ void Player::move() } } // EXPERIMENTAL - else if (checkSlopes()) + else if (checkUpSlopes() || checkDownSlopes()) { state = s_standing; vy = 0.0f; @@ -396,15 +413,15 @@ bool Player::checkWalls() } // Comprueba si el jugador está en una rampa -tile_e Player::checkSlopes() +tile_e Player::checkUpSlopes() { // Actualiza los puntos de colisión updateFeet(); - // Comprueba si ha colisionado con una rampa bool slope_l = false; bool slope_r = false; + // Comprueba si ha colisionado con una rampa for (auto f : feet) { slope_l |= (room->getTile(f) == t_slope_l); @@ -424,6 +441,35 @@ tile_e Player::checkSlopes() return t_empty; } +// Comprueba si el jugador está en una rampa +tile_e Player::checkDownSlopes() +{ + // Actualiza los puntos de colisión + updateFeet(); + + bool slope_l = false; + bool slope_r = false; + + // Comprueba si ha colisionado con una rampa + for (auto f : underFeet) + { + slope_l |= (room->getTile(f) == t_slope_l); + slope_r |= (room->getTile(f) == t_slope_r); + } + + if (slope_l) + { + return t_slope_l; + } + + if (slope_r) + { + return t_slope_r; + } + + return t_empty; +} + // Obtiene algunos parametros del jugador player_t Player::getSpawnParams() { diff --git a/source/player.h b/source/player.h index a1ffdbb..0719f68 100644 --- a/source/player.h +++ b/source/player.h @@ -91,7 +91,10 @@ public: bool checkWalls(); // Comprueba si el jugador está en una rampa - tile_e checkSlopes(); + tile_e checkUpSlopes(); + + // Comprueba si el jugador está en una rampa + tile_e checkDownSlopes(); // Actualiza los puntos de colisión void updateColliderPoints();