From 895955f122fc8b5a5805a530c289c1a6b12f5873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Mon, 24 Jun 2024 08:16:27 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20delay=20final=20al=20fade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/config/param.txt | 7 ++++--- source/common/utils.h | 9 +++++---- source/const.h | 2 +- source/fade.cpp | 26 +++++++++++++++++++------- source/fade.h | 29 +++++++++++++++++------------ source/load_param.cpp | 6 ++++++ source/title.cpp | 1 + 7 files changed, 53 insertions(+), 27 deletions(-) diff --git a/data/config/param.txt b/data/config/param.txt index 2e5e9dc..c2d50e4 100644 --- a/data/config/param.txt +++ b/data/config/param.txt @@ -1,6 +1,7 @@ gameWidth 320 gameHeight 240 -numSquaresWidth 80 -numSquaresHeight 60 +numSquaresWidth 160 +numSquaresHeight 120 fadeRandomSquaresDelay 1 -fadeRandomSquaresMult 8 \ No newline at end of file +fadeRandomSquaresMult 500 +fadePostDuration 50 \ No newline at end of file diff --git a/source/common/utils.h b/source/common/utils.h index 0b52d9b..a990e19 100644 --- a/source/common/utils.h +++ b/source/common/utils.h @@ -163,10 +163,11 @@ struct param_t SDL_Rect scoreboard; // Posición y tamaño del marcador - int numSquaresWidth; - int numSquaresHeight; - int fadeRandomSquaresDelay; - int fadeRandomSquaresMult; + int numSquaresWidth; // Cantidad total de cuadraditos en horizontal para el FADE_RANDOM_SQUARE + int numSquaresHeight; // Cantidad total de cuadraditos en vertical para el FADE_RANDOM_SQUARE + 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 }; // Calcula el cuadrado de la distancia entre dos puntos diff --git a/source/const.h b/source/const.h index 1e41b3b..b31cf4c 100644 --- a/source/const.h +++ b/source/const.h @@ -73,6 +73,6 @@ const color_t difficultyEasyColor = {75, 105, 47}; const color_t difficultyNormalColor = {255, 122, 0}; const color_t difficultyHardColor = {118, 66, 138}; const color_t flashColor = {0xFF, 0xFF, 0xFF}; -const color_t fadeColor = {0x17, 0x17, 0x26}; +const color_t fadeColor = {0x27, 0x27, 0x36}; #endif \ No newline at end of file diff --git a/source/fade.cpp b/source/fade.cpp index 23464e9..78c3cc4 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -34,6 +34,8 @@ void Fade::init() r = 0; g = 0; b = 0; + postDuration = 20; + postCounter = 0; numSquaresWidth = param->numSquaresWidth; numSquaresHeight = param->numSquaresHeight; fadeRandomSquaresDelay = param->fadeRandomSquaresDelay; @@ -149,7 +151,14 @@ void Fade::update() if (finished) { - enabled = false; + if (postCounter == postDuration) + { + enabled = false; + } + else + { + postCounter++; + } } counter++; @@ -162,6 +171,7 @@ void Fade::activate() enabled = true; finished = false; counter = 0; + postCounter = 0; switch (type) { @@ -204,15 +214,10 @@ void Fade::activate() int num = numSquaresWidth * numSquaresHeight; while (num > 1) { - // agafa un nombre aleatòri entre 0 i num-1 int num_arreu = rand() % num; - - // el element triat el swapechem amb l'ultim SDL_Rect temp = square[num_arreu]; square[num_arreu] = square[num - 1]; square[num - 1] = temp; - - // I ara queda un element menys per desordenar num--; } break; @@ -229,7 +234,8 @@ bool Fade::isEnabled() // Comprueba si ha terminado la transicion bool Fade::hasEnded() { - return finished; + // Ha terminado cuando ha finalizado la transición y se ha deshabilitado + return !enabled && finished; } // Establece el tipo de fade @@ -244,4 +250,10 @@ void Fade::setColor(Uint8 r, Uint8 g, Uint8 b) this->r = r; this->g = g; this->b = b; +} + +// Establece la duración posterior +void Fade::setPost(int value) +{ + postDuration = value; } \ No newline at end of file diff --git a/source/fade.h b/source/fade.h index 6a18211..0f57cd6 100644 --- a/source/fade.h +++ b/source/fade.h @@ -21,19 +21,21 @@ private: SDL_Texture *backbuffer; // Textura para usar como backbuffer // Variables - Uint8 type; // Tipo de fade a realizar - Uint16 counter; // Contador interno - bool enabled; // Indica si el fade está activo - bool finished; // Indica si ha terminado la transición - Uint8 r, g, b; // Colores para el fade - SDL_Rect rect1; // Rectangulo usado para crear los efectos de transición - SDL_Rect rect2; // Rectangulo usado para crear los efectos de transición - int numSquaresWidth; // Cantidad total de cuadraditos en horizontal para el FADE_RANDOM_SQUARE - int numSquaresHeight; // Cantidad total de cuadraditos en vertical para el FADE_RANDOM_SQUARE - param_t *param; // Puntero con todos los parametros del programa + Uint8 type; // Tipo de fade a realizar + Uint16 counter; // Contador interno + bool enabled; // Indica si el fade está activo + bool finished; // Indica si ha terminado la transición + Uint8 r, g, b; // Colores para el fade + SDL_Rect rect1; // Rectangulo usado para crear los efectos de transición + SDL_Rect rect2; // Rectangulo usado para crear los efectos de transición + int numSquaresWidth; // Cantidad total de cuadraditos en horizontal para el FADE_RANDOM_SQUARE + int numSquaresHeight; // Cantidad total de cuadraditos en vertical para el FADE_RANDOM_SQUARE + param_t *param; // Puntero con todos los parametros del programa std::vector square; // Vector con los indices de los cuadrados para el FADE_RANDOM_SQUARE - int fadeRandomSquaresDelay; - int fadeRandomSquaresMult; + int fadeRandomSquaresDelay; // Duración entre cada pintado de cuadrados + int fadeRandomSquaresMult; // Cantidad de cuadrados que se pintaran cada vez + int postDuration; // Duración posterior del fade tras finalizar + int postCounter; // Contador para la duración posterior // Inicializa las variables void init(); @@ -65,6 +67,9 @@ public: // Establece el color del fade void setColor(Uint8 r, Uint8 g, Uint8 b); + + // Establece la duración posterior + void setPost(int value); }; #endif \ No newline at end of file diff --git a/source/load_param.cpp b/source/load_param.cpp index 365189d..20892b5 100644 --- a/source/load_param.cpp +++ b/source/load_param.cpp @@ -20,6 +20,7 @@ void initParam(param_t *param) param->numSquaresHeight = 60; param->fadeRandomSquaresDelay = 1; param->fadeRandomSquaresMult = 8; + param->fadePostDuration = 20; } // Establece valores para los parametros a partir de un fichero de texto @@ -97,6 +98,11 @@ bool setOptions(param_t *param, std::string var, std::string value) param->fadeRandomSquaresMult = std::stoi(value); } + else if (var == "fadePostDuration") + { + param->fadePostDuration = std::stoi(value); + } + else { success = false; diff --git a/source/title.cpp b/source/title.cpp index 8cd5421..09165da 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -75,6 +75,7 @@ void Title::init() ticksSpeed = 15; fade->setColor(fadeColor.r, fadeColor.g, fadeColor.b); fade->setType(FADE_RANDOM_SQUARE); + fade->setPost(param->fadePostDuration); demo = true; // Pone valores por defecto a las opciones de control