From 06cb1e748d60590436c772da5ddb681d38b29e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Thu, 15 Sep 2022 22:41:19 +0200 Subject: [PATCH] Fade acabado y no convence --- source/game.cpp | 32 ++++++++++++++++++++++---------- source/game.h | 3 +++ source/screen.cpp | 10 ++++++++-- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/source/game.cpp b/source/game.cpp index a3f66ff..3a2745e 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -112,7 +112,10 @@ void Game::checkEventHandler() case SDL_SCANCODE_M: board.music = !board.music; board.music ? JA_ResumeMusic() : JA_PauseMusic(); - screen->setFade(); + break; + + case SDL_SCANCODE_T: + screen->setspectrumFade(); break; case SDL_SCANCODE_P: @@ -215,7 +218,7 @@ void Game::update() checkIfPlayerIsAlive(); checkEndGame(); scoreboard->update(); - + updateDebugInfo(); updateBlackScreen(); screen->updateFX(); @@ -396,7 +399,7 @@ void Game::killPlayer() // Sonido JA_PlaySound(deathSound); - blackScreen = true; + setBlackScreen(); // Crea la nueva habitación y el nuevo jugador room = new Room(asset->get(currentRoom), renderer, screen, asset, itemTracker, &board.items, debug); @@ -415,20 +418,29 @@ void Game::reLoadTextures() text->reLoadTexture(); } +// Establece la pantalla en negro +void Game::setBlackScreen() +{ + blackScreen = true; + screen->setspectrumFade(); +} + // Actualiza las variables relativas a la pantalla en negro void Game::updateBlackScreen() { if (blackScreen) { - blackScreenCounter++; - if (blackScreenCounter > 50) + if (screen->spectrumFadeEnded()) { - blackScreen = false; - blackScreenCounter = 0; - - player->resume(); - room->resume(); + blackScreenCounter++; + if (blackScreenCounter > 50) + { + blackScreen = false; + blackScreenCounter = 0; + player->resume(); + room->resume(); + } } } } diff --git a/source/game.h b/source/game.h index 516d0f3..690dc6b 100644 --- a/source/game.h +++ b/source/game.h @@ -92,6 +92,9 @@ private: // Recarga todas las texturas void reLoadTextures(); + // Establece la pantalla en negro + void setBlackScreen(); + // Actualiza las variables relativas a la pantalla en negro void updateBlackScreen(); diff --git a/source/screen.cpp b/source/screen.cpp index e54725d..e5f4ac2 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -287,7 +287,9 @@ void Screen::iniSpectrumFade() { spectrumFade = false; spectrumFadeCounter = 0; - spectrumFadeLenght = 200; + spectrumFadeLenght = 50; + + spectrumColor.clear(); color_t c; c = stringToColor("black"); @@ -327,6 +329,7 @@ void Screen::updateSpectrumFade() if (spectrumFadeCounter > spectrumFadeLenght) { iniSpectrumFade(); + SDL_SetTextureColorMod(gameCanvas, 255, 255, 255); } } @@ -339,7 +342,10 @@ void Screen::renderSpectrumFade() } const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght; - SDL_SetTextureColorMod(gameCanvas, 255, 0, 0); + const int max = spectrumColor.size() - 1; + const int index = max + (0 - max) * step; + const color_t c = spectrumColor[index]; + SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b); } // Actualiza los efectos