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:
@@ -1,4 +1,5 @@
|
|||||||
#include "game_logo.h"
|
#include "game_logo.h"
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL
|
#include <SDL2/SDL_render.h> // Para SDL_FLIP_HORIZONTAL
|
||||||
#include <algorithm> // Para max
|
#include <algorithm> // Para max
|
||||||
#include "animated_sprite.h" // Para AnimatedSprite
|
#include "animated_sprite.h" // Para AnimatedSprite
|
||||||
@@ -9,6 +10,8 @@
|
|||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "texture.h" // Para Texture
|
#include "texture.h" // Para Texture
|
||||||
|
|
||||||
|
constexpr int ZOOM_FACTOR = 4;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameLogo::GameLogo(int x, int y)
|
GameLogo::GameLogo(int x, int y)
|
||||||
: dust_texture_(Resource::get()->getTexture("title_dust.png")),
|
: 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_)),
|
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())),
|
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),
|
x_(x),
|
||||||
y_(y) { }
|
y_(y) {}
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
void GameLogo::init()
|
void GameLogo::init()
|
||||||
@@ -32,15 +35,8 @@ void GameLogo::init()
|
|||||||
// Variables
|
// Variables
|
||||||
coffee_crisis_status_ = Status::DISABLED;
|
coffee_crisis_status_ = Status::DISABLED;
|
||||||
arcade_edition_status_ = Status::DISABLED;
|
arcade_edition_status_ = Status::DISABLED;
|
||||||
|
shake_.init(1, 2, 8, xp);
|
||||||
shake_.desp = 1;
|
zoom_ = 3.0f * ZOOM_FACTOR;
|
||||||
shake_.delay = 2;
|
|
||||||
shake_.lenght = 8;
|
|
||||||
shake_.remaining = shake_.lenght;
|
|
||||||
shake_.counter = shake_.delay;
|
|
||||||
shake_.origin = xp;
|
|
||||||
|
|
||||||
zoom_ = 3.0f;
|
|
||||||
|
|
||||||
// Inicializa el bitmap de 'Coffee'
|
// Inicializa el bitmap de 'Coffee'
|
||||||
coffee_sprite_->setPosX(xp);
|
coffee_sprite_->setPosX(xp);
|
||||||
@@ -122,7 +118,6 @@ void GameLogo::update()
|
|||||||
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished())
|
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished())
|
||||||
{
|
{
|
||||||
coffee_crisis_status_ = Status::SHAKING;
|
coffee_crisis_status_ = Status::SHAKING;
|
||||||
arcade_edition_status_ = Status::MOVING;
|
|
||||||
|
|
||||||
// Reproduce el efecto sonoro
|
// Reproduce el efecto sonoro
|
||||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||||
@@ -133,7 +128,7 @@ void GameLogo::update()
|
|||||||
|
|
||||||
case Status::SHAKING:
|
case Status::SHAKING:
|
||||||
{
|
{
|
||||||
// Agita el logo
|
// Agita "COFFEE CRISIS"
|
||||||
if (shake_.remaining > 0)
|
if (shake_.remaining > 0)
|
||||||
{
|
{
|
||||||
if (shake_.counter > 0)
|
if (shake_.counter > 0)
|
||||||
@@ -154,6 +149,7 @@ void GameLogo::update()
|
|||||||
coffee_sprite_->setPosX(shake_.origin);
|
coffee_sprite_->setPosX(shake_.origin);
|
||||||
crisis_sprite_->setPosX(shake_.origin + 15);
|
crisis_sprite_->setPosX(shake_.origin + 15);
|
||||||
coffee_crisis_status_ = Status::FINISHED;
|
coffee_crisis_status_ = Status::FINISHED;
|
||||||
|
arcade_edition_status_ = Status::MOVING;
|
||||||
}
|
}
|
||||||
|
|
||||||
dust_right_sprite_->update();
|
dust_right_sprite_->update();
|
||||||
@@ -178,12 +174,40 @@ void GameLogo::update()
|
|||||||
{
|
{
|
||||||
case Status::MOVING:
|
case Status::MOVING:
|
||||||
{
|
{
|
||||||
zoom_ -= 0.1f;
|
zoom_ -= 0.1f * ZOOM_FACTOR;
|
||||||
arcade_edition_sprite_->setZoom(zoom_);
|
arcade_edition_sprite_->setZoom(zoom_);
|
||||||
if (zoom_ <= 1.0f)
|
if (zoom_ <= 1.0f)
|
||||||
{
|
{
|
||||||
arcade_edition_status_ = Status::FINISHED;
|
arcade_edition_status_ = Status::SHAKING;
|
||||||
zoom_ = 1.0f;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
@@ -191,6 +215,13 @@ void GameLogo::update()
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (coffee_crisis_status_ == Status::FINISHED &&
|
||||||
|
arcade_edition_status_ == Status::FINISHED &&
|
||||||
|
post_finished_counter_ > 0)
|
||||||
|
{
|
||||||
|
--post_finished_counter_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa la clase
|
// Activa la clase
|
||||||
@@ -203,7 +234,7 @@ void GameLogo::enable()
|
|||||||
// Indica si ha terminado la animación
|
// Indica si ha terminado la animación
|
||||||
bool GameLogo::hasFinished() const
|
bool GameLogo::hasFinished() const
|
||||||
{
|
{
|
||||||
return coffee_crisis_status_ == Status::FINISHED && arcade_edition_status_ == Status::FINISHED;
|
return post_finished_counter_ == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga las texturas
|
// Recarga las texturas
|
||||||
|
|||||||
@@ -20,12 +20,30 @@ private:
|
|||||||
|
|
||||||
struct Shake
|
struct Shake
|
||||||
{
|
{
|
||||||
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
int desp = 1; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
||||||
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
int delay = 2; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
||||||
int counter; // Contador para el retraso
|
int lenght = 8; // Cantidad de desplazamientos a realizar
|
||||||
int lenght; // Cantidad de desplazamientos a realizar
|
int remaining = lenght; // Cantidad de desplazamientos pendientes a realizar
|
||||||
int remaining; // 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
|
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
|
// Objetos y punteros
|
||||||
@@ -46,6 +64,7 @@ private:
|
|||||||
int x_; // Posición donde dibujar el logo
|
int x_; // Posición donde dibujar el logo
|
||||||
int y_; // Posición donde dibujar el logo
|
int y_; // Posición donde dibujar el logo
|
||||||
float zoom_; // Zoom aplicado al texto "ARCADE EDITION"
|
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 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"
|
Status arcade_edition_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "ARCADE_EDITION"
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ Logo::~Logo()
|
|||||||
{
|
{
|
||||||
jail_texture_->setColor(255, 255, 255);
|
jail_texture_->setColor(255, 255, 255);
|
||||||
since_texture_->setColor(255, 255, 255);
|
since_texture_->setColor(255, 255, 255);
|
||||||
JA_PauseChannel(-1);
|
JA_StopChannel(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
@@ -101,7 +101,6 @@ void Logo::checkInput()
|
|||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||||
if (Input::get()->checkAnyButtonPressed())
|
if (Input::get()->checkAnyButtonPressed())
|
||||||
{
|
{
|
||||||
JA_StopMusic();
|
|
||||||
section::name = section::Name::TITLE;
|
section::name = section::Name::TITLE;
|
||||||
section::options = section::Options::TITLE_1;
|
section::options = section::Options::TITLE_1;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ Title::Title()
|
|||||||
Title::~Title()
|
Title::~Title()
|
||||||
{
|
{
|
||||||
Resource::get()->getTexture("smb2.gif")->setPalette(0);
|
Resource::get()->getTexture("smb2.gif")->setPalette(0);
|
||||||
|
JA_StopChannel(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace section
|
|||||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
|
||||||
|
|
||||||
// Parámetros
|
// 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
|
Esta clase gestiona un estado del programa. Se encarga de la parte del titulo o menu
|
||||||
|
|||||||
Reference in New Issue
Block a user