Au, paca casa. M'he quedat a mitjes fent un fade de audio sincronitzat amb el fade de video en el titol
This commit is contained in:
@@ -54,7 +54,7 @@ Director::Director(int argc, const char *argv[])
|
||||
section::name = section::Name::GAME;
|
||||
section::options = section::Options::GAME_PLAY_1P;
|
||||
#elif DEBUG
|
||||
section::name = section::Name::GAME;
|
||||
section::name = section::Name::LOGO;
|
||||
#else // NORMAL GAME
|
||||
section::name = section::Name::LOGO;
|
||||
section::attract_mode = section::AttractMode::TITLE_TO_DEMO;
|
||||
|
||||
@@ -100,6 +100,8 @@ void Fade::update()
|
||||
|
||||
SDL_RenderFillRect(renderer_, &rect1_);
|
||||
SDL_RenderFillRect(renderer_, &rect2_);
|
||||
|
||||
value_ = calculateValue(0, counter_, i);
|
||||
}
|
||||
|
||||
// Deja el renderizador como estaba
|
||||
@@ -139,6 +141,8 @@ void Fade::update()
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
value_ = calculateValue(0, static_cast<int>(num_squares_width_ * num_squares_height_), static_cast<int>(counter_ * fade_random_squares_mult_ / fade_random_squares_delay_));
|
||||
|
||||
// Comprueba si ha terminado
|
||||
if (counter_ * fade_random_squares_mult_ / fade_random_squares_delay_ >= num_squares_width_ * num_squares_height_)
|
||||
{
|
||||
@@ -337,4 +341,12 @@ void Fade::cleanBackbuffer(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
|
||||
// Vuelve a dejar el renderizador como estaba
|
||||
SDL_SetRenderTarget(renderer_, temp);
|
||||
}
|
||||
|
||||
// Calcula el valor del estado del fade
|
||||
int Fade::calculateValue(int min, int max, int current)
|
||||
{
|
||||
if (max == 0)
|
||||
return 0;
|
||||
return std::clamp(current * 100 / max, 0, 100);
|
||||
}
|
||||
@@ -45,6 +45,7 @@ private:
|
||||
int fade_random_squares_mult_; // Cantidad de cuadrados que se pintaran cada vez
|
||||
int post_duration_; // Duración posterior del fade tras finalizar
|
||||
int post_counter_; // Contador para la duración posterior
|
||||
int value_ = 0; // Estado actual del fade entre 0 y 100
|
||||
|
||||
// Inicializa las variables
|
||||
void init();
|
||||
@@ -52,6 +53,9 @@ private:
|
||||
// Limpia el backbuffer
|
||||
void cleanBackbuffer(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
// Calcula el valor del estado del fade
|
||||
int calculateValue(int min, int max, int current);
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Fade();
|
||||
@@ -88,4 +92,7 @@ public:
|
||||
|
||||
// Establece la duración posterior
|
||||
void setPost(int value);
|
||||
|
||||
// Getters
|
||||
int getValue() const { return value_; }
|
||||
};
|
||||
@@ -44,7 +44,8 @@ Game::Game(int player_id, int current_stage, bool demo)
|
||||
input_(Input::get()),
|
||||
background_(std::make_unique<Background>()),
|
||||
canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h)),
|
||||
fade_(std::make_unique<Fade>()),
|
||||
fade_in_(std::make_unique<Fade>()),
|
||||
fade_out_(std::make_unique<Fade>()),
|
||||
balloon_manager_(std::make_unique<BalloonManager>())
|
||||
{
|
||||
// Pasa variables
|
||||
@@ -63,9 +64,15 @@ Game::Game(int player_id, int current_stage, bool demo)
|
||||
Scoreboard::init();
|
||||
scoreboard_ = Scoreboard::get();
|
||||
|
||||
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_->setPost(param.fade.post_duration);
|
||||
fade_->setType(FadeType::VENETIAN);
|
||||
fade_in_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_in_->setPost(param.fade.post_duration);
|
||||
fade_in_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_in_->setMode(FadeMode::IN);
|
||||
fade_in_->activate();
|
||||
|
||||
fade_out_->setColor(fade_color.r, fade_color.g, fade_color.b);
|
||||
fade_out_->setPost(param.fade.post_duration);
|
||||
fade_out_->setType(FadeType::VENETIAN);
|
||||
|
||||
background_->setPos(param.game.play_area.rect);
|
||||
|
||||
@@ -213,8 +220,8 @@ void Game::updatePlayers()
|
||||
|
||||
if (demo_.enabled && allPlayersAreNotPlaying())
|
||||
{
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->activate();
|
||||
fade_out_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_out_->activate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,23 +298,13 @@ void Game::updateGameOverState()
|
||||
|
||||
game_over_counter_--;
|
||||
|
||||
/*
|
||||
if ((game_over_counter_ == 250) || (game_over_counter_ == 200) || (game_over_counter_ == 180) || (game_over_counter_ == 120) || (game_over_counter_ == 60))
|
||||
{
|
||||
// Hace sonar aleatoriamente uno de los 4 sonidos de burbujas
|
||||
const auto index = rand() % 4;
|
||||
JA_Sound_t *sound[4] = {Resource::get()->getSound("bubble1.wav"), Resource::get()->getSound("bubble2.wav"), Resource::get()->getSound("bubble3.wav"), Resource::get()->getSound("bubble4.wav")};
|
||||
JA_PlaySound(sound[index], 0);
|
||||
}
|
||||
*/
|
||||
|
||||
if (game_over_counter_ == 150)
|
||||
{
|
||||
fade_->activate();
|
||||
fade_out_->activate();
|
||||
}
|
||||
}
|
||||
|
||||
if (fade_->hasEnded())
|
||||
if (fade_out_->hasEnded())
|
||||
{
|
||||
if (game_completed_counter_ > 0)
|
||||
{
|
||||
@@ -945,7 +942,8 @@ void Game::render()
|
||||
scoreboard_->render();
|
||||
|
||||
// Dibuja el fade
|
||||
fade_->render();
|
||||
fade_in_->render();
|
||||
fade_out_->render();
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
screen_->blit();
|
||||
@@ -1729,12 +1727,12 @@ void Game::updateDemo()
|
||||
// Activa el fundido antes de acabar con los datos de la demo
|
||||
if (demo_.counter == TOTAL_DEMO_DATA - 200)
|
||||
{
|
||||
fade_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_->activate();
|
||||
fade_out_->setType(FadeType::RANDOM_SQUARE);
|
||||
fade_out_->activate();
|
||||
}
|
||||
|
||||
// Si ha terminado el fundido, cambia de sección
|
||||
if (fade_->hasEnded())
|
||||
if (fade_out_->hasEnded())
|
||||
{
|
||||
section::name = section::Name::HI_SCORE_TABLE;
|
||||
return;
|
||||
@@ -1773,7 +1771,8 @@ void Game::updateGame()
|
||||
Stage::addPower(5);
|
||||
}
|
||||
#endif
|
||||
fade_->update();
|
||||
fade_in_->update();
|
||||
fade_out_->update();
|
||||
updatePlayers();
|
||||
checkPlayersStatusPlaying();
|
||||
updateScoreboard();
|
||||
|
||||
@@ -140,7 +140,8 @@ private:
|
||||
std::vector<std::vector<std::string>> item_animations_; // Vector con las animaciones de los items
|
||||
std::vector<std::vector<std::string>> player_animations_; // Vector con las animaciones del jugador
|
||||
|
||||
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Fade> fade_in_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Fade> fade_out_; // Objeto para renderizar fades
|
||||
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
|
||||
std::vector<Path> paths_; // Vector con los recorridos precalculados almacenados
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ void Title::update()
|
||||
|
||||
// Comprueba el fundido y si se ha acabado
|
||||
fade_->update();
|
||||
JA_SetMusicVolume(100 - fade_->getValue());
|
||||
if (fade_->hasEnded())
|
||||
{
|
||||
if (post_fade_ == -1)
|
||||
|
||||
Reference in New Issue
Block a user