From c905c348d59128b764710175856a8777393dee0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sat, 10 Sep 2022 19:18:56 +0200 Subject: [PATCH] Ya baja por las rampas --- source/player.cpp | 36 ++++++++++++++++++++++++++++++++++++ source/player.h | 3 +++ 2 files changed, 39 insertions(+) diff --git a/source/player.cpp b/source/player.cpp index 574d748b..99085d30 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -271,6 +271,12 @@ void Player::move() setState(s_standing); } } + + // Si está bajando la rampa, recoloca al jugador + if (isOnDownSlope()) + { + y += 1; + } } // Se mueve hacia la derecha @@ -307,6 +313,12 @@ void Player::move() setState(s_standing); } } + + // Si está bajando la rampa, recoloca al jugador + if (isOnDownSlope()) + { + y += 1; + } } // Si ha salido del suelo, el jugador cae @@ -557,6 +569,30 @@ bool Player::isOnFloor() return onFloor; } +// Comprueba si el jugador está sobre una rampa hacia abajo +bool Player::isOnDownSlope() +{ + bool onSlope = false; + + updateFeet(); + + // Cuando el jugador baja una escalera, se queda volando + // Hay que mirar otro pixel más por debajo + underFeet[0].y += 1; + underFeet[1].y += 1; + + // Comprueba las rampas + onSlope |= room->checkLeftSlopes(&underFeet[0]); + onSlope |= room->checkRightSlopes(&underFeet[1]); + + if (onSlope) + { + debug->add("ONSLOPE"); + } + + return onSlope; +} + // Comprueba que el jugador no atraviese ninguna pared bool Player::checkWalls() { diff --git a/source/player.h b/source/player.h index eaf62ab1..4eeacb73 100644 --- a/source/player.h +++ b/source/player.h @@ -91,6 +91,9 @@ public: // Comprueba si el jugador tiene suelo debajo de los pies bool isOnFloor(); + // Comprueba si el jugador está sobre una rampa hacia abajo + bool isOnDownSlope(); + // Comprueba que el jugador no atraviese ninguna pared bool checkWalls();