From de81b798b06893273a5276bea2763d2838b11b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Fri, 3 Jan 2025 22:02:48 +0100 Subject: [PATCH] Afegit custom fadeout de so sincronitzat amb el fadeout de video per a quan acaba la partida --- source/fade.cpp | 20 +++++++++++++++----- source/game.cpp | 11 ++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/source/fade.cpp b/source/fade.cpp index 119f8bc..06f61ce 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -151,7 +151,7 @@ void Fade::update() case FadeType::VENETIAN: { - // Counter debe ir de 0 a 150 + // Counter debe ir de 0 a 150 <-- comprobar si esto es aún cierto if (square_.back().h < param.fade.venetian_size) { // Dibuja sobre el backbuffer_ @@ -176,6 +176,16 @@ void Fade::update() // A partir del segundo rectangulo se pinta en función del anterior square_.at(i).h = i == 0 ? h : std::max(square_.at(i - 1).h - 2, 0); } + + int completed = 0; + for (const auto &square : square_) + { + if (square.h >= param.fade.venetian_size) + { + ++completed; + } + } + value_ = calculateValue(0, square_.size() - 1, completed); } else { @@ -315,9 +325,9 @@ void Fade::cleanBackbuffer(Uint8 r, Uint8 g, Uint8 b, Uint8 a) // Calcula el valor del estado del fade int Fade::calculateValue(int min, int max, int current) { - if (max == 0) - { + if (current < min) return 0; - } - return std::clamp(current * 100 / max, 0, 100); + if (current > max) + return 100; + return static_cast(100.0 * (current - min) / (max - min)); } \ No newline at end of file diff --git a/source/game.cpp b/source/game.cpp index 0462a1a..64ea3f0 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -35,7 +35,8 @@ #include "tabe.h" // Para Tabe #include "text.h" // Para Text #include "texture.h" // Para Texture -struct JA_Sound_t; // lines 37-37 +#include +struct JA_Sound_t; // lines 37-37 // Constructor Game::Game(int player_id, int current_stage, bool demo) @@ -319,6 +320,12 @@ void Game::updateGameStateGameOver() } } + if (fade_out_->isEnabled()) + { + const float vol = static_cast(64 * (100 - fade_out_->getValue())) / 100.0f; + JA_SetSoundVolume(to_JA_volume(static_cast(vol))); + } + if (fade_out_->hasEnded()) { if (game_completed_counter_ > 0) @@ -331,6 +338,8 @@ void Game::updateGameStateGameOver() // La partida ha terminado con la derrota de los jugadores section::name = section::Name::HI_SCORE_TABLE; } + JA_StopChannel(-1); + JA_SetSoundVolume(to_JA_volume(options.audio.sound.volume)); } }