From 0cb83657bece96595839624047d5c797385da97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 6 Nov 2022 14:48:02 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adida=20pantalla=20de=20game=20over=20fu?= =?UTF-8?q?ncional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 9 +++++++-- source/game.cpp | 15 +++++++-------- source/game_over.cpp | 16 ++++++++++++++-- source/game_over.h | 3 --- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 40a43a7..93880b8 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -443,10 +443,15 @@ void Director::loadResources(section_t section) else if (section.name == SECTION_PROG_GAME_OVER) { std::vector textureList; - textureList.push_back("jailgames.png"); - textureList.push_back("since_1998.png"); + textureList.push_back("smb2.png"); resource->loadTextures(textureList); + + // Offsets + std::vector offsetsList; + offsetsList.push_back("smb2.txt"); + + resource->loadOffsets(offsetsList); } else if (section.name == SECTION_PROG_GAME || section.name == SECTION_PROG_DEMO) diff --git a/source/game.cpp b/source/game.cpp index 6703671..67a993a 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -40,7 +40,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as // Inicializa el resto de variables ticks = 0; ticksSpeed = 15; - board.lives = 9; + board.lives = 2; board.items = 0; board.rooms = 1; board.music = true; @@ -372,7 +372,7 @@ void Game::checkGameOver() { if (board.lives < 0) { - section.name = SECTION_PROG_TITLE; + section.name = SECTION_PROG_GAME_OVER; } } @@ -410,7 +410,7 @@ void Game::killPlayer() this->player->pause(); // Deshabilita las entradas hasta que no haya ninguna activa - input->disableUntil(d_keyPressed); + //input->disableUntil(d_keyPressed); } // Recarga todas las texturas @@ -458,7 +458,7 @@ void Game::updateBlackScreen() if (blackScreen) { blackScreenCounter++; - if (blackScreenCounter > 10) + if (blackScreenCounter > 20) { blackScreen = false; blackScreenCounter = 0; @@ -498,10 +498,9 @@ void Game::setScoreBoardColor() // Comprueba si ha finalizado el juego bool Game::checkEndGame() { - - const bool a = room->getName() == "THE JAIL"; // Estar en la habitación que toca - const bool b = board.items >= totalItems * 0.9f; // Con mas del 90% de los items recogidos - const bool c = player->getRect().x <= 128; // Estar en la ubicación que toca (En la puerta) + const bool a = room->getName() == "THE JAIL"; // Estar en la habitación que toca + const bool b = board.items >= int(totalItems * 0.9f); // Con mas del 90% de los items recogidos + const bool c = player->getRect().x <= 128; // Y en la ubicación que toca (En la puerta) if (b) { diff --git a/source/game_over.cpp b/source/game_over.cpp index 84606d0..7e28de4 100644 --- a/source/game_over.cpp +++ b/source/game_over.cpp @@ -12,6 +12,7 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A // Reserva memoria para los punteros a objetos eventHandler = new SDL_Event(); + text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer); // Inicializa variables counter = 0; @@ -26,6 +27,7 @@ GameOver::~GameOver() { // Libera la memoria de los objetos delete eventHandler; + delete text; } // Actualiza el objeto @@ -39,6 +41,13 @@ void GameOver::update() // Comprueba el manejador de eventos checkEventHandler(); + + counter++; + + if (counter == 400) + { + section.name = SECTION_PROG_TITLE; + } } } @@ -51,6 +60,8 @@ void GameOver::render() // Limpia la pantalla screen->clean(); + text->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "G A M E O V E R"); + // Vuelca el contenido del renderizador en pantalla screen->blit(); } @@ -65,6 +76,7 @@ void GameOver::checkEventHandler() if (eventHandler->type == SDL_QUIT) { section.name = SECTION_PROG_QUIT; + section.subsection = 0; break; } @@ -112,8 +124,8 @@ void GameOver::checkEventHandler() break; default: - // section.name = SECTION_PROG_TITLE; - // section.subsection = 0; + //section.name = SECTION_PROG_TITLE; + //section.subsection = 0; break; } } diff --git a/source/game_over.h b/source/game_over.h index e22ce06..b98a4db 100644 --- a/source/game_over.h +++ b/source/game_over.h @@ -26,9 +26,6 @@ private: options_t *options; // Puntero a las opciones del juego SDL_Event *eventHandler; // Manejador de eventos Text *text; // Objeto para escribir texto en pantalla - SDL_Texture *textTexture; // Textura para dibujar el texto - SDL_Texture *coverTexture; // Textura para cubrir el texto - AnimatedSprite *sprite; // Sprite para el brillo del corazón // Variables int counter; // Contador