From 354795d52ccbcda042c740bf0288ae5abe368d53 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 30 Jun 2024 21:18:12 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20FADE=5FVENETIAN=20a=20la=20clase?= =?UTF-8?q?=20fade=20La=20clase=20game=20utiliza=20un=20objeto=20fade=20pa?= =?UTF-8?q?ra=20sus=20fades=20en=20vez=20de=20sus=20propios=20procedimient?= =?UTF-8?q?os?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/config/param.txt | 1 + source/common/utils.h | 1 + source/fade.cpp | 54 +++++++++++++++++++++++++++++++++++ source/fade.h | 1 + source/game.cpp | 66 ++++++++++--------------------------------- source/game.h | 3 -- source/load_param.cpp | 6 ++++ 7 files changed, 78 insertions(+), 54 deletions(-) diff --git a/data/config/param.txt b/data/config/param.txt index 630831d..c7ac439 100644 --- a/data/config/param.txt +++ b/data/config/param.txt @@ -8,6 +8,7 @@ numSquaresHeight 120 fadeRandomSquaresDelay 1 fadeRandomSquaresMult 500 fadePostDuration 50 +venetianSize 16 #SCOREBOARD scoreboard.x 0 diff --git a/source/common/utils.h b/source/common/utils.h index 29567a8..47c4922 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -175,6 +175,7 @@ struct param_t int fadeRandomSquaresDelay; // Duración entre cada pintado de cuadrados int fadeRandomSquaresMult; // Cantidad de cuadrados que se pintaran cada vez int fadePostDuration; // Duración final del fade + int venetianSize; // Altura de los rectangulos para FADE_VENETIAN int pressStart; // Posición del texto para empezar a jugar int titleCounter; // Tiempo de inactividad del titulo diff --git a/source/fade.cpp b/source/fade.cpp index 82bd256..1f628cc 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -80,6 +80,17 @@ void Fade::render() break; } + case FADE_VENETIAN: + { + SDL_SetRenderDrawColor(renderer, r, g, b, 0xFF); + for (auto rect : square) + { + SDL_RenderFillRect(renderer, &rect); + } + + break; + } + default: { break; @@ -148,6 +159,32 @@ void Fade::update() break; } + + case FADE_VENETIAN: + { + // Counter debe ir de 0 a 150 + if (square.back().h < param->venetianSize) + { + const Uint8 h = counter / 3; + for (int i = 0; i < (int)square.size(); ++i) + { + if (i == 0) + { + square[i].h = h; + } + else + { + square[i].h = std::max(square[i - 1].h - 3, 0); + } + } + } + else + { + finished = true; + } + + break; + } } if (finished) @@ -223,6 +260,23 @@ void Fade::activate() } break; } + + case FADE_VENETIAN: + { + rect1 = {0, 0, param->gameWidth, 0}; + square.clear(); + + // Añade los cuadrados al vector + const int max = param->gameHeight / param->venetianSize; + + for (int i = 0; i < max; ++i) + { + rect1.y = i * param->venetianSize; + square.push_back(rect1); + } + + break; + } } } diff --git a/source/fade.h b/source/fade.h index 0f57cd6..8e5857c 100644 --- a/source/fade.h +++ b/source/fade.h @@ -11,6 +11,7 @@ #define FADE_FULLSCREEN 0 #define FADE_CENTER 1 #define FADE_RANDOM_SQUARE 2 +#define FADE_VENETIAN 3 // Clase Fade class Fade diff --git a/source/game.cpp b/source/game.cpp index 361b297..dd2bb10 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -278,7 +278,8 @@ void Game::init(int playerID) demo.counter = 0; // Inicializa el objeto para el fundido - fade->setColor(0x27, 0x27, 0x36); + fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); + fade->setType(FADE_VENETIAN); // Con los globos creados, calcula el nivel de amenaza evaluateAndSetMenace(); @@ -1627,52 +1628,21 @@ void Game::updateDeath() JA_Sound_t *sound[4] = {bubble1Sound, bubble2Sound, bubble3Sound, bubble4Sound}; JA_PlaySound(sound[index], 0); } + + if (deathCounter == 150) + { + fade->activate(); + } } - else + + if (fade->hasEnded()) { // section->subsection = SUBSECTION_GAME_GAMEOVER; - section->name = SECTION_PROG_TITLE; - section->subsection = SUBSECTION_TITLE_1; + section->name = SECTION_PROG_HI_SCORE_TABLE; } } } -// Renderiza el fade final cuando se acaba la partida -void Game::renderDeathFade(int counter) -{ - // Counter debe ir de 0 a 150 - SDL_SetRenderDrawColor(renderer, 0x27, 0x27, 0x36, 255); - - const int desp = 16; - const int max = param->gameHeight / desp; - if (counter < 150) - { - // 192 / 6 = 32, 6 cuadrados de 32 pixeles - SDL_Rect rect[max]; - Uint8 h = counter / 3; - for (int i = 0; i < max; ++i) - { - rect[i].x = 0; - rect[i].y = i * desp; - rect[i].w = param->gameWidth; - if (i == 0) - { - rect[i].h = h; - } - else - { - rect[i].h = std::max(rect[i - 1].h - 3, 0); - } - SDL_RenderFillRect(renderer, &rect[i]); - } - } - else - { - SDL_Rect rect = {0, 0, param->gameWidth, param->gameHeight}; - SDL_RenderFillRect(renderer, &rect); - } -} - // Actualiza los globos void Game::updateBalloons() { @@ -2541,6 +2511,9 @@ void Game::update() // Actualiza el objeto screen screen->update(); + // Actualiza el objeto fade + fade->update(); + // Actualiza las variables del jugador updatePlayers(); @@ -2671,17 +2644,8 @@ void Game::render() // Dibuja el separador del marcador de la zona de juego renderSeparator(); - // Dibuja el sprite del jugador al morir - if ((deathCounter <= 150) && !players[0]->isAlive()) - { - renderDeathFade(150 - deathCounter); - } - - // Dibuja el fade de fin de juego - if ((gameCompleted) && (gameCompletedCounter >= GAME_COMPLETED_START_FADE)) - { - renderDeathFade(gameCompletedCounter - GAME_COMPLETED_START_FADE); - } + // Dibuja el fade + fade->render(); // Vuelca el contenido del renderizador en pantalla screen->blit(); diff --git a/source/game.h b/source/game.h index 9b59870..32eeaef 100644 --- a/source/game.h +++ b/source/game.h @@ -275,9 +275,6 @@ private: // Actualiza el estado de muerte void updateDeath(); - // Renderiza el fade final cuando se acaba la partida - void renderDeathFade(int counter); - // Actualiza los globos void updateBalloons(); diff --git a/source/load_param.cpp b/source/load_param.cpp index 2b9367d..f7705a0 100644 --- a/source/load_param.cpp +++ b/source/load_param.cpp @@ -21,6 +21,7 @@ void initParam(param_t *param) param->fadeRandomSquaresDelay = 1; param->fadeRandomSquaresMult = 8; param->fadePostDuration = 20; + param->venetianSize = 16; // Posició del texto para empezar a jugar param->pressStart = 180; @@ -155,6 +156,11 @@ bool setOptions(param_t *param, std::string var, std::string value) param->fadePostDuration = std::stoi(value); } + else if (var == "venetianSize") + { + param->venetianSize = std::stoi(value); + } + else if (var == "scoreboard.x") { param->scoreboard.x = std::stoi(value);