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

@@ -207,18 +207,13 @@ void Instructions::fillBackbuffer()
// Actualiza las variables
void Instructions::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();
// Mantiene la música sonando
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
}
updateMusic();
// Actualiza el objeto screen
Screen::get()->update();
@@ -232,24 +227,8 @@ void Instructions::update()
// Actualiza los sprites
updateSprites();
// Establece la ventana del backbuffer
view_.y = std::max(0, param.game.height - counter_ + 100);
// Verifica si view_.y == 0 y gestiona el temporizador
if (view_.y == 0)
{
if (!start_delay_triggered_)
{
// Activa el temporizador si no ha sido activado
start_delay_triggered_ = true;
start_delay_time_ = SDL_GetTicks();
}
else if (SDL_GetTicks() - start_delay_time_ >= 4000)
{
// Han pasado tres segundos, mover líneas
all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5);
}
}
// Gestiona la textura con los graficos
updateBackbuffer();
// Actualiza el mosaico de fondo
tiled_bg_->update();
@@ -259,13 +238,6 @@ void Instructions::update()
// Rellena el backbuffer
fillBackbuffer();
// Comprueba si el contador ha llegado al final
if (all_lines_off_screen_)
{
section::name = section::Name::TITLE;
section::options = section::Options::TITLE_1;
}
}
}
@@ -376,4 +348,43 @@ void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, con
SDL_Rect dstRect = {static_cast<int>(line.x), line.y, 320, 1};
SDL_RenderCopy(renderer, texture, &srcRect, &dstRect);
}
}
// Gestiona la musica
void Instructions::updateMusic()
{
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
}
}
// Gestiona la textura con los graficos
void Instructions::updateBackbuffer()
{
// Establece la ventana del backbuffer
view_.y = std::max(0, param.game.height - counter_ + 100);
// Verifica si view_.y == 0 y gestiona el temporizador
if (view_.y == 0)
{
if (!start_delay_triggered_)
{
// Activa el temporizador si no ha sido activado
start_delay_triggered_ = true;
start_delay_time_ = SDL_GetTicks();
}
else if (SDL_GetTicks() - start_delay_time_ >= 4000)
{
// Han pasado tres segundos, mover líneas
all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5);
}
}
// Comprueba si el contador ha llegado al final
if (all_lines_off_screen_)
{
section::name = section::Name::TITLE;
section::options = section::Options::TITLE_1;
}
}