diff --git a/data/ending/ending4.png b/data/ending/ending4.png index 80fb8d9..bbf97bd 100644 Binary files a/data/ending/ending4.png and b/data/ending/ending4.png differ diff --git a/source/common/input.cpp b/source/common/input.cpp index 71d9639..f3841d9 100644 --- a/source/common/input.cpp +++ b/source/common/input.cpp @@ -19,6 +19,7 @@ Input::Input(std::string file) gameControllerBindings.resize(17, gcb); verbose = true; + enabled = true; } // Actualiza el estado del objeto diff --git a/source/ending.cpp b/source/ending.cpp index 5fc0fbb..ca06ae6 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -100,6 +100,9 @@ void Ending::update() // Comprueba si se ha de cambiar de escena checkChangeScene(); + + // Actualiza el volumen de la musica + updateMusicVolume(); } } @@ -484,6 +487,7 @@ section_t Ending::run() } JA_StopMusic(); + JA_SetVolume(128); return section; } @@ -560,8 +564,12 @@ void Ending::checkChangeScene() coverCounter = 0; if (scene == 5) { + // Termina el bucle + section.name = SECTION_PROG_LOGO; + + // Mantiene los valores anteriores scene = 4; - section.name = SECTION_PROG_QUIT; + coverCounter = 100; } } } @@ -600,14 +608,20 @@ void Ending::renderCoverTexture() { if (coverCounter > 0) { // Dibuja la textura que cubre el texto - // const int offset = std::min(coverCounter, 200 / 2); - // SDL_Rect srcRect = {0, 0, 256, 200 - (offset * 2)}; - // SDL_Rect dstRect = {0, offset * 2, 256, 200 - (offset * 2)}; - // SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect); - const int offset = std::min(coverCounter, 100); SDL_Rect srcRect = {0, 200 - (coverCounter * 2), 256, offset * 2}; SDL_Rect dstRect = {0, 0, 256, offset * 2}; SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect); } +} + +// Actualiza el volumen de la musica +void Ending::updateMusicVolume() +{ + if (scene == 4 && coverCounter > 0) + { + const float step = (100.0f - coverCounter) / 100.0f; + const int volume = 128 * step; + JA_SetVolume(volume); + } } \ No newline at end of file diff --git a/source/ending.h b/source/ending.h index d0cb336..ffe6ebd 100644 --- a/source/ending.h +++ b/source/ending.h @@ -105,6 +105,9 @@ private: // Dibuja la cortinilla de cambio de escena void renderCoverTexture(); + // Actualiza el volumen de la musica + void updateMusicVolume(); + public: // Constructor Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); diff --git a/source/game.cpp b/source/game.cpp index abd0c70..90d8e24 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -212,6 +212,7 @@ void Game::update() checkPlayerAndItems(); checkPlayerAndEnemies(); checkIfPlayerIsAlive(); + checkGameOver(); checkEndGame(); scoreboard->update(); input->update(); @@ -372,7 +373,7 @@ void Game::checkIfPlayerIsAlive() } // Comprueba si ha terminado la partida -void Game::checkEndGame() +void Game::checkGameOver() { if (board.lives < 0) { @@ -497,4 +498,20 @@ void Game::setScoreBoardColor() // Si el color es negro brillante lo cambia a blanco const color_t cBrightBlack = stringToColor(options->palette, "bright_black"); board.color = colorAreEqual(c, cBrightBlack) ? stringToColor(options->palette, "white") : c; +} + +// Comprueba si ha finalizado el juego +bool Game::checkEndGame() +{ + const bool a = room->getName() == "THE JAIL"; + const bool b = board.items >= 2; + const bool c = player->getRect().x < 152; + + if (a && b && c) + { + section.name = SECTION_PROG_ENDING; + return true; + } + + return false; } \ No newline at end of file diff --git a/source/game.h b/source/game.h index 3f1eb0b..a25b6a6 100644 --- a/source/game.h +++ b/source/game.h @@ -89,7 +89,7 @@ private: void checkIfPlayerIsAlive(); // Comprueba si ha terminado la partida - void checkEndGame(); + void checkGameOver(); // Mata al jugador void killPlayer(); @@ -112,6 +112,9 @@ private: // Pone el color del marcador en función del color del borde de la habitación void setScoreBoardColor(); + // Comprueba si ha finalizado el juego + bool checkEndGame(); + public: // Constructor Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug);