FIX: afegit StopChannel en lloc de PauseChannel en el destructor del Logo

Retocada la animació del logo del joc en Title
This commit is contained in:
2024-12-09 19:08:22 +01:00
parent 301c059a26
commit 7016849587
5 changed files with 77 additions and 27 deletions

View File

@@ -1,4 +1,5 @@
#include "game_logo.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL
#include <algorithm> // 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<SmartSprite>(crisis_texture_)),
arcade_edition_sprite_(std::make_unique<Sprite>(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

View File

@@ -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<Sprite> 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"

View File

@@ -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;

View File

@@ -54,6 +54,7 @@ Title::Title()
Title::~Title()
{
Resource::get()->getTexture("smb2.gif")->setPalette(0);
JA_StopChannel(-1);
}
// Actualiza las variables del objeto

View File

@@ -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