Afegit param.game.speed i retocats els update() de les seccions

This commit is contained in:
2025-03-12 10:06:38 +01:00
parent 90313da3ce
commit 5ccd7eebcd
13 changed files with 471 additions and 406 deletions

View File

@@ -61,95 +61,22 @@ Title::~Title()
// Actualiza las variables del objeto
void Title::update()
{
constexpr int TICKS_SPEED = 15;
if (SDL_GetTicks() - ticks_ > TICKS_SPEED)
if (SDL_GetTicks() - ticks_ > param.game.speed)
{
// Actualiza el contador de ticks_
ticks_ = SDL_GetTicks();
// Actualiza el fade
updateFade();
// Actualiza el estado
updateState();
// Actualiza el objeto screen
Screen::get()->update();
// Actualiza las variables de globalInputs
globalInputs::update();
// Comprueba el fundido
fade_->update();
if (fade_->hasEnded())
{
if (selection_ == section::Options::TITLE_TIME_OUT)
{
// El menu ha hecho time out
section::name = next_section_;
}
else
{
// Se ha pulsado para jugar
section::name = section::Name::GAME;
section::options = selection_;
JA_StopMusic();
}
}
// Establece la lógica según el estado
switch (state_)
{
case TitleState::LOGO_ANIMATING:
{
game_logo_->update();
if (game_logo_->hasFinished())
{
state_ = TitleState::LOGO_FINISHED;
}
break;
}
case TitleState::LOGO_FINISHED:
{
// El contador solo sube si no estamos definiendo botones
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
// Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
}
// Actualiza el logo con el título del juego
game_logo_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
if (counter_ == param.title.title_duration)
{
// El menu ha hecho time out
fade_->setPostDuration(0);
fade_->activate();
selection_ = section::Options::TITLE_TIME_OUT;
}
break;
}
case TitleState::START_HAS_BEEN_PRESSED:
{
// Actualiza el logo con el título del juego
game_logo_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
if (counter_ == 100)
{
fade_->activate();
}
++counter_;
break;
}
default:
break;
}
}
}
@@ -379,3 +306,87 @@ void Title::showControllers()
// Muestra la notificación
Notifier::get()->show({text.at(0), text.at(1)});
}
// Actualiza el fade
void Title::updateFade()
{
fade_->update();
if (fade_->hasEnded())
{
if (selection_ == section::Options::TITLE_TIME_OUT)
{
// El menu ha hecho time out
section::name = next_section_;
}
else
{
// Se ha pulsado para jugar
section::name = section::Name::GAME;
section::options = selection_;
JA_StopMusic();
}
}
}
// Actualiza el estado
void Title::updateState()
{
// Establece la lógica según el estado
switch (state_)
{
case TitleState::LOGO_ANIMATING:
{
game_logo_->update();
if (game_logo_->hasFinished())
{
state_ = TitleState::LOGO_FINISHED;
}
break;
}
case TitleState::LOGO_FINISHED:
{
// El contador solo sube si no estamos definiendo botones
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
// Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
}
// Actualiza el logo con el título del juego
game_logo_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
if (counter_ == param.title.title_duration)
{
// El menu ha hecho time out
fade_->setPostDuration(0);
fade_->activate();
selection_ = section::Options::TITLE_TIME_OUT;
}
break;
}
case TitleState::START_HAS_BEEN_PRESSED:
{
// Actualiza el logo con el título del juego
game_logo_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
if (counter_ == 100)
{
fade_->activate();
}
++counter_;
break;
}
default:
break;
}
}