From 7016849587ff59232a9db6f173485741daffaf3c Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 9 Dec 2024 19:08:22 +0100 Subject: [PATCH] =?UTF-8?q?FIX:=20afegit=20StopChannel=20en=20lloc=20de=20?= =?UTF-8?q?PauseChannel=20en=20el=20destructor=20del=20Logo=20Retocada=20l?= =?UTF-8?q?a=20animaci=C3=B3=20del=20logo=20del=20joc=20en=20Title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game_logo.cpp | 61 +++++++++++++++++++++++++++++++++----------- source/game_logo.h | 37 ++++++++++++++++++++------- source/logo.cpp | 3 +-- source/title.cpp | 1 + source/title.h | 2 +- 5 files changed, 77 insertions(+), 27 deletions(-) diff --git a/source/game_logo.cpp b/source/game_logo.cpp index b86ede3..81755b7 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -1,4 +1,5 @@ #include "game_logo.h" +#include #include // Para SDL_FLIP_HORIZONTAL #include // Para max #include "animated_sprite.h" // Para AnimatedSprite @@ -9,6 +10,8 @@ #include "sprite.h" // Para Sprite #include "texture.h" // Para Texture +constexpr int ZOOM_FACTOR = 4; + // Constructor GameLogo::GameLogo(int x, int y) : dust_texture_(Resource::get()->getTexture("title_dust.png")), @@ -21,7 +24,7 @@ GameLogo::GameLogo(int x, int y) crisis_sprite_(std::make_unique(crisis_texture_)), arcade_edition_sprite_(std::make_unique(arcade_edition_texture_, (param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight())), x_(x), - y_(y) { } + y_(y) {} // Inicializa las variables void GameLogo::init() @@ -32,15 +35,8 @@ void GameLogo::init() // Variables coffee_crisis_status_ = Status::DISABLED; arcade_edition_status_ = Status::DISABLED; - - shake_.desp = 1; - shake_.delay = 2; - shake_.lenght = 8; - shake_.remaining = shake_.lenght; - shake_.counter = shake_.delay; - shake_.origin = xp; - - zoom_ = 3.0f; + shake_.init(1, 2, 8, xp); + zoom_ = 3.0f * ZOOM_FACTOR; // Inicializa el bitmap de 'Coffee' coffee_sprite_->setPosX(xp); @@ -122,7 +118,6 @@ void GameLogo::update() if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished()) { coffee_crisis_status_ = Status::SHAKING; - arcade_edition_status_ = Status::MOVING; // Reproduce el efecto sonoro JA_PlaySound(Resource::get()->getSound("title.wav")); @@ -133,7 +128,7 @@ void GameLogo::update() case Status::SHAKING: { - // Agita el logo + // Agita "COFFEE CRISIS" if (shake_.remaining > 0) { if (shake_.counter > 0) @@ -154,6 +149,7 @@ void GameLogo::update() coffee_sprite_->setPosX(shake_.origin); crisis_sprite_->setPosX(shake_.origin + 15); coffee_crisis_status_ = Status::FINISHED; + arcade_edition_status_ = Status::MOVING; } dust_right_sprite_->update(); @@ -178,12 +174,40 @@ void GameLogo::update() { case Status::MOVING: { - zoom_ -= 0.1f; + zoom_ -= 0.1f * ZOOM_FACTOR; arcade_edition_sprite_->setZoom(zoom_); if (zoom_ <= 1.0f) { - arcade_edition_status_ = Status::FINISHED; + arcade_edition_status_ = Status::SHAKING; zoom_ = 1.0f; + arcade_edition_sprite_->setZoom(zoom_); + shake_.init(1, 2, 8, arcade_edition_sprite_->getX()); + JA_PlaySound(Resource::get()->getSound("title.wav")); + } + break; + } + + case Status::SHAKING: + { + // Agita "ARCADE EDITION" + if (shake_.remaining > 0) + { + if (shake_.counter > 0) + { + shake_.counter--; + } + else + { + shake_.counter = shake_.delay; + const auto desp = shake_.remaining % 2 == 0 ? shake_.desp * (-1) : shake_.desp; + arcade_edition_sprite_->setX(shake_.origin + desp); + shake_.remaining--; + } + } + else + { + arcade_edition_sprite_->setX(shake_.origin); + arcade_edition_status_ = Status::FINISHED; } break; } @@ -191,6 +215,13 @@ void GameLogo::update() default: break; } + + if (coffee_crisis_status_ == Status::FINISHED && + arcade_edition_status_ == Status::FINISHED && + post_finished_counter_ > 0) + { + --post_finished_counter_; + } } // Activa la clase @@ -203,7 +234,7 @@ void GameLogo::enable() // Indica si ha terminado la animación bool GameLogo::hasFinished() const { - return coffee_crisis_status_ == Status::FINISHED && arcade_edition_status_ == Status::FINISHED; + return post_finished_counter_ == 0; } // Recarga las texturas diff --git a/source/game_logo.h b/source/game_logo.h index 7b8ecc3..92ecd9c 100644 --- a/source/game_logo.h +++ b/source/game_logo.h @@ -20,12 +20,30 @@ private: struct Shake { - int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x - int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse - int counter; // Contador para el retraso - int lenght; // Cantidad de desplazamientos a realizar - int remaining; // Cantidad de desplazamientos pendientes a realizar - int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento + int desp = 1; // Pixels de desplazamiento para agitar la pantalla en el eje x + int delay = 2; // Retraso entre cada desplazamiento de la pantalla al agitarse + int lenght = 8; // Cantidad de desplazamientos a realizar + int remaining = lenght; // Cantidad de desplazamientos pendientes a realizar + int counter = delay; // Contador para el retraso + int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento + + // Constructor por defect + Shake() = default; + + // Constructor + Shake(int d, int de, int l, int o) + : desp(d), delay(de), lenght(l), remaining(l), counter(de), origin(o) {} + + // Inicializa los miembros + void init(int d, int de, int l, int o) + { + desp = d; + delay = de; + lenght = l; + remaining = l; + counter = de; + origin = o; + } }; // Objetos y punteros @@ -43,9 +61,10 @@ private: std::unique_ptr arcade_edition_sprite_; // Sprite con los graficos de "Arcade Edition" // Variables - int x_; // Posición donde dibujar el logo - int y_; // Posición donde dibujar el logo - float zoom_; // Zoom aplicado al texto "ARCADE EDITION" + int x_; // Posición donde dibujar el logo + int y_; // Posición donde dibujar el logo + float zoom_; // Zoom aplicado al texto "ARCADE EDITION" + int post_finished_counter_ = 30; // Contador final una vez terminada las animaciones de los logos Status coffee_crisis_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "COFFEE CRISIS" Status arcade_edition_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "ARCADE_EDITION" diff --git a/source/logo.cpp b/source/logo.cpp index d2565e9..06b7354 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -59,7 +59,7 @@ Logo::~Logo() { jail_texture_->setColor(255, 255, 255); since_texture_->setColor(255, 255, 255); - JA_PauseChannel(-1); + JA_StopChannel(-1); } // Recarga todas las texturas @@ -101,7 +101,6 @@ void Logo::checkInput() // Comprueba si se ha pulsado cualquier botón (de los usados para jugar) if (Input::get()->checkAnyButtonPressed()) { - JA_StopMusic(); section::name = section::Name::TITLE; section::options = section::Options::TITLE_1; return; diff --git a/source/title.cpp b/source/title.cpp index 2c6a9c6..cb0faff 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -54,6 +54,7 @@ Title::Title() Title::~Title() { Resource::get()->getTexture("smb2.gif")->setPalette(0); + JA_StopChannel(-1); } // Actualiza las variables del objeto diff --git a/source/title.h b/source/title.h index badce90..16d766c 100644 --- a/source/title.h +++ b/source/title.h @@ -18,7 +18,7 @@ namespace section constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner"; // Parámetros -constexpr bool ALLOW_TITLE_ANIMATION_SKIP = true; +constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false; /* Esta clase gestiona un estado del programa. Se encarga de la parte del titulo o menu