Afegit param.game.speed i retocats els update() de les seccions
This commit is contained in:
@@ -87,13 +87,11 @@ void Credits::run()
|
||||
// Actualiza las variables
|
||||
void Credits::update()
|
||||
{
|
||||
constexpr Uint32 TICKS_SPEED_ = 15;
|
||||
|
||||
if (SDL_GetTicks() - ticks_ > TICKS_SPEED_)
|
||||
if (SDL_GetTicks() - ticks_ > param.game.speed)
|
||||
{
|
||||
ticks_ = SDL_GetTicks();
|
||||
const int repeat = want_to_pass_ ? 4 : 1;
|
||||
for (int i = 0; i < repeat; ++i)
|
||||
const int REPEAT = want_to_pass_ ? 4 : 1;
|
||||
for (int i = 0; i < REPEAT; ++i)
|
||||
{
|
||||
tiled_bg_->update();
|
||||
balloon_manager_->update();
|
||||
@@ -106,6 +104,7 @@ void Credits::update()
|
||||
updateAllFades();
|
||||
++counter_;
|
||||
}
|
||||
|
||||
Screen::get()->update();
|
||||
globalInputs::update();
|
||||
|
||||
|
||||
@@ -957,9 +957,7 @@ void Game::updateTimeStopped()
|
||||
// Actualiza el juego
|
||||
void Game::update()
|
||||
{
|
||||
constexpr int TICKS_SPEED = 15;
|
||||
|
||||
if (SDL_GetTicks() - ticks_ > TICKS_SPEED)
|
||||
if (SDL_GetTicks() - ticks_ > param.game.speed)
|
||||
{
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
|
||||
@@ -58,28 +58,17 @@ HiScoreTable::~HiScoreTable()
|
||||
// Actualiza las variables
|
||||
void HiScoreTable::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 las posiciones de los sprites de texto
|
||||
updateSprites();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
|
||||
// Actualiza el fondo
|
||||
background_->update();
|
||||
|
||||
@@ -87,21 +76,16 @@ void HiScoreTable::update()
|
||||
updateFade();
|
||||
|
||||
// Gestiona el contador y sus eventos
|
||||
counter_++;
|
||||
|
||||
if (counter_ == 150)
|
||||
{
|
||||
background_->setColor(background_fade_color_.darken());
|
||||
background_->setAlpha(96);
|
||||
}
|
||||
|
||||
if (counter_ == COUNTER_END_)
|
||||
{
|
||||
fade_->activate();
|
||||
}
|
||||
updateCounter();
|
||||
|
||||
// Dibuja los sprites en la textura
|
||||
fillTexture();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,3 +414,29 @@ void HiScoreTable::glowEntryNames()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gestiona la musica
|
||||
void HiScoreTable::updateMusic()
|
||||
{
|
||||
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
|
||||
{
|
||||
JA_PlayMusic(Resource::get()->getMusic("title.ogg"));
|
||||
}
|
||||
}
|
||||
|
||||
// Gestiona el contador
|
||||
void HiScoreTable::updateCounter()
|
||||
{
|
||||
counter_++;
|
||||
|
||||
if (counter_ == 150)
|
||||
{
|
||||
background_->setColor(background_fade_color_.darken());
|
||||
background_->setAlpha(96);
|
||||
}
|
||||
|
||||
if (counter_ == COUNTER_END_)
|
||||
{
|
||||
fade_->activate();
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,12 @@ private:
|
||||
// Hace brillar los nombres de la tabla de records
|
||||
void glowEntryNames();
|
||||
|
||||
// Gestiona la musica
|
||||
void updateMusic();
|
||||
|
||||
// Gestiona el contador
|
||||
void updateCounter();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
HiScoreTable();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,3 +349,42 @@ void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, con
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,12 @@ private:
|
||||
// Método para renderizar las líneas
|
||||
void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines);
|
||||
|
||||
// Gestiona la musica
|
||||
void updateMusic();
|
||||
|
||||
// Gestiona la textura con los graficos
|
||||
void updateBackbuffer();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Instructions();
|
||||
|
||||
508
source/intro.cpp
508
source/intro.cpp
@@ -26,6 +26,263 @@ Intro::Intro()
|
||||
section::name = section::Name::INTRO;
|
||||
section::options = section::Options::NONE;
|
||||
|
||||
// Inicializa las imagens
|
||||
initSprites();
|
||||
|
||||
// Inicializa los textos
|
||||
initTexts();
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
void Intro::checkEvents()
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Intro::checkInput() { globalInputs::check(); }
|
||||
|
||||
// Actualiza las escenas de la intro
|
||||
void Intro::updateScenes()
|
||||
{
|
||||
switch (scene_)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
// Primera imagen - UPV
|
||||
if (!bitmaps_[0]->hasFinished())
|
||||
{
|
||||
bitmaps_[0]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Primer texto de la primera imagen
|
||||
if (bitmaps_[0]->hasFinished() && !texts_[0]->hasFinished())
|
||||
{
|
||||
texts_[0]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Segundo texto de la primera imagen
|
||||
if (texts_[0]->hasFinished() && !texts_[1]->hasFinished())
|
||||
{
|
||||
texts_[0]->setEnabled(false);
|
||||
texts_[1]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Tercer texto de la primera imagen
|
||||
if (texts_[1]->hasFinished() && !texts_[2]->hasFinished())
|
||||
{
|
||||
texts_[1]->setEnabled(false);
|
||||
texts_[2]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la primera escena
|
||||
if (texts_[2]->hasFinished())
|
||||
{
|
||||
bitmaps_[0]->setEnabled(false);
|
||||
texts_[2]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
// Segunda imagen - Máquina
|
||||
if (!bitmaps_[1]->hasFinished())
|
||||
{
|
||||
bitmaps_[1]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Primer texto de la segunda imagen
|
||||
if (bitmaps_[1]->hasFinished() && !texts_[3]->hasFinished())
|
||||
{
|
||||
texts_[3]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la segunda escena
|
||||
if (texts_[3]->hasFinished())
|
||||
{
|
||||
bitmaps_[1]->setEnabled(false);
|
||||
texts_[3]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
// Tercera imagen junto con primer texto - GRITO
|
||||
if (!bitmaps_[2]->hasFinished() && !texts_[4]->hasFinished())
|
||||
{
|
||||
bitmaps_[2]->setEnabled(true);
|
||||
texts_[4]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la tercera escena
|
||||
if (bitmaps_[2]->hasFinished() && texts_[4]->hasFinished())
|
||||
{
|
||||
bitmaps_[2]->setEnabled(false);
|
||||
texts_[4]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
// Cuarta imagen junto con primer texto - Reflexión
|
||||
if (!bitmaps_[3]->hasFinished() && !texts_[5]->hasFinished())
|
||||
{
|
||||
bitmaps_[3]->setEnabled(true);
|
||||
texts_[5]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Segundo texto de la cuarta imagen
|
||||
if (texts_[5]->hasFinished() && !texts_[6]->hasFinished())
|
||||
{
|
||||
texts_[5]->setEnabled(false);
|
||||
texts_[6]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la cuarta escena
|
||||
if (bitmaps_[3]->hasFinished() && texts_[6]->hasFinished())
|
||||
{
|
||||
bitmaps_[3]->setEnabled(false);
|
||||
texts_[6]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{
|
||||
// Quinta imagen - Patada
|
||||
if (!bitmaps_[4]->hasFinished())
|
||||
{
|
||||
bitmaps_[4]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Primer texto de la quinta imagen
|
||||
if (bitmaps_[4]->hasFinished() && !texts_[7]->hasFinished())
|
||||
{
|
||||
texts_[7]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la quinta escena
|
||||
if (bitmaps_[4]->hasFinished() && texts_[7]->hasFinished())
|
||||
{
|
||||
bitmaps_[4]->setEnabled(false);
|
||||
texts_[7]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 6:
|
||||
{
|
||||
// Sexta imagen junto con texto - Globos de café
|
||||
if (!bitmaps_[5]->hasFinished() && !texts_[8]->hasFinished())
|
||||
{
|
||||
bitmaps_[5]->setEnabled(true);
|
||||
texts_[8]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Acaba el último texto
|
||||
if (bitmaps_[5]->hasFinished() && texts_[8]->hasFinished())
|
||||
{
|
||||
bitmaps_[5]->setEnabled(false);
|
||||
texts_[8]->setEnabled(false);
|
||||
JA_StopMusic();
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void Intro::update()
|
||||
{
|
||||
if (SDL_GetTicks() - ticks_ > param.game.speed)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza los objetos
|
||||
for (auto &bitmap : bitmaps_)
|
||||
{
|
||||
bitmap->update();
|
||||
}
|
||||
|
||||
for (auto &text : texts_)
|
||||
{
|
||||
text->update();
|
||||
}
|
||||
|
||||
// Actualiza las escenas de la intro
|
||||
updateScenes();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void Intro::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean(bg_color);
|
||||
|
||||
// Dibuja los objetos
|
||||
for (const auto &bitmap : bitmaps_)
|
||||
{
|
||||
bitmap->render();
|
||||
}
|
||||
|
||||
for (const auto &text : texts_)
|
||||
{
|
||||
text->render();
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void Intro::run()
|
||||
{
|
||||
JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0);
|
||||
while (section::name == section::Name::INTRO)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Inicializa las imagens
|
||||
void Intro::initSprites()
|
||||
{
|
||||
const std::array<std::string, 6> BITMAP_LIST = {
|
||||
"intro1.png",
|
||||
"intro2.png",
|
||||
@@ -94,8 +351,11 @@ Intro::Intro()
|
||||
bitmaps_.at(5)->setVelY(0.0f);
|
||||
bitmaps_.at(5)->setAccelX(0.0f);
|
||||
bitmaps_.at(5)->setAccelY(0.0f);
|
||||
}
|
||||
|
||||
// Inicializa los textos de la intro
|
||||
// Inicializa los textos
|
||||
void Intro::initTexts()
|
||||
{
|
||||
constexpr int TOTAL_TEXTS = 9;
|
||||
for (int i = 0; i < TOTAL_TEXTS; ++i)
|
||||
{
|
||||
@@ -149,249 +409,3 @@ Intro::Intro()
|
||||
text->center(param.game.game_area.center_x);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
void Intro::checkEvents()
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
globalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Intro::checkInput()
|
||||
{
|
||||
globalInputs::check();
|
||||
}
|
||||
|
||||
// Actualiza las escenas de la intro
|
||||
void Intro::updateScenes()
|
||||
{
|
||||
switch (scene_)
|
||||
{
|
||||
case 1:
|
||||
{ // Primera imagen - UPV
|
||||
if (!bitmaps_[0]->hasFinished())
|
||||
{
|
||||
bitmaps_[0]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Primer texto de la primera imagen
|
||||
if (bitmaps_[0]->hasFinished() && !texts_[0]->hasFinished())
|
||||
{
|
||||
texts_[0]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Segundo texto de la primera imagen
|
||||
if (texts_[0]->hasFinished() && !texts_[1]->hasFinished())
|
||||
{
|
||||
texts_[0]->setEnabled(false);
|
||||
texts_[1]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Tercer texto de la primera imagen
|
||||
if (texts_[1]->hasFinished() && !texts_[2]->hasFinished())
|
||||
{
|
||||
texts_[1]->setEnabled(false);
|
||||
texts_[2]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la primera escena
|
||||
if (texts_[2]->hasFinished())
|
||||
{
|
||||
bitmaps_[0]->setEnabled(false);
|
||||
texts_[2]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{ // Segunda imagen - Máquina
|
||||
if (!bitmaps_[1]->hasFinished())
|
||||
{
|
||||
bitmaps_[1]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Primer texto de la segunda imagen
|
||||
if (bitmaps_[1]->hasFinished() && !texts_[3]->hasFinished())
|
||||
{
|
||||
texts_[3]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la segunda escena
|
||||
if (texts_[3]->hasFinished())
|
||||
{
|
||||
bitmaps_[1]->setEnabled(false);
|
||||
texts_[3]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{ // Tercera imagen junto con primer texto - GRITO
|
||||
if (!bitmaps_[2]->hasFinished() && !texts_[4]->hasFinished())
|
||||
{
|
||||
bitmaps_[2]->setEnabled(true);
|
||||
texts_[4]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la tercera escena
|
||||
if (bitmaps_[2]->hasFinished() && texts_[4]->hasFinished())
|
||||
{
|
||||
bitmaps_[2]->setEnabled(false);
|
||||
texts_[4]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{ // Cuarta imagen junto con primer texto - Reflexión
|
||||
if (!bitmaps_[3]->hasFinished() && !texts_[5]->hasFinished())
|
||||
{
|
||||
bitmaps_[3]->setEnabled(true);
|
||||
texts_[5]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Segundo texto de la cuarta imagen
|
||||
if (texts_[5]->hasFinished() && !texts_[6]->hasFinished())
|
||||
{
|
||||
texts_[5]->setEnabled(false);
|
||||
texts_[6]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la cuarta escena
|
||||
if (bitmaps_[3]->hasFinished() && texts_[6]->hasFinished())
|
||||
{
|
||||
bitmaps_[3]->setEnabled(false);
|
||||
texts_[6]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{ // Quinta imagen - Patada
|
||||
if (!bitmaps_[4]->hasFinished())
|
||||
{
|
||||
bitmaps_[4]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Primer texto de la quinta imagen
|
||||
if (bitmaps_[4]->hasFinished() && !texts_[7]->hasFinished())
|
||||
{
|
||||
texts_[7]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Fin de la quinta escena
|
||||
if (bitmaps_[4]->hasFinished() && texts_[7]->hasFinished())
|
||||
{
|
||||
bitmaps_[4]->setEnabled(false);
|
||||
texts_[7]->setEnabled(false);
|
||||
scene_++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 6:
|
||||
{ // Sexta imagen junto con texto - Globos de café
|
||||
if (!bitmaps_[5]->hasFinished() && !texts_[8]->hasFinished())
|
||||
{
|
||||
bitmaps_[5]->setEnabled(true);
|
||||
texts_[8]->setEnabled(true);
|
||||
}
|
||||
|
||||
// Acaba el último texto
|
||||
if (bitmaps_[5]->hasFinished() && texts_[8]->hasFinished())
|
||||
{
|
||||
bitmaps_[5]->setEnabled(false);
|
||||
texts_[8]->setEnabled(false);
|
||||
JA_StopMusic();
|
||||
section::name = section::Name::TITLE;
|
||||
section::options = section::Options::TITLE_1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void Intro::update()
|
||||
{
|
||||
constexpr int TICKS_SPEED = 15;
|
||||
|
||||
if (SDL_GetTicks() - ticks_ > TICKS_SPEED)
|
||||
{
|
||||
// Actualiza el contador de ticks
|
||||
ticks_ = SDL_GetTicks();
|
||||
|
||||
// Actualiza el objeto screen
|
||||
Screen::get()->update();
|
||||
|
||||
// Actualiza los objetos
|
||||
for (auto &bitmap : bitmaps_)
|
||||
{
|
||||
bitmap->update();
|
||||
}
|
||||
|
||||
for (auto &text : texts_)
|
||||
{
|
||||
text->update();
|
||||
}
|
||||
|
||||
// Actualiza las escenas de la intro
|
||||
updateScenes();
|
||||
|
||||
// Actualiza las variables de globalInputs
|
||||
globalInputs::update();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void Intro::render()
|
||||
{
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
Screen::get()->start();
|
||||
|
||||
// Limpia la pantalla
|
||||
Screen::get()->clean(bg_color);
|
||||
|
||||
// Dibuja los objetos
|
||||
for (const auto &bitmap : bitmaps_)
|
||||
{
|
||||
bitmap->render();
|
||||
}
|
||||
|
||||
for (const auto &text : texts_)
|
||||
{
|
||||
text->render();
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
Screen::get()->render();
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void Intro::run()
|
||||
{
|
||||
JA_PlayMusic(Resource::get()->getMusic("intro.ogg"), 0);
|
||||
while (section::name == section::Name::INTRO)
|
||||
{
|
||||
checkInput();
|
||||
update();
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,12 @@ private:
|
||||
// Actualiza las escenas de la intro
|
||||
void updateScenes();
|
||||
|
||||
// Inicializa las imagens
|
||||
void initSprites();
|
||||
|
||||
// Inicializa los textos
|
||||
void initTexts();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Intro();
|
||||
|
||||
@@ -154,9 +154,7 @@ void Logo::updateTextureColors()
|
||||
// Actualiza las variables
|
||||
void Logo::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();
|
||||
|
||||
@@ -26,6 +26,7 @@ void initParam()
|
||||
param.game.game_area.rect = {0, 0, param.game.width, param.game.height};
|
||||
param.game.play_area.rect = {0, 0, param.game.width, 216};
|
||||
param.game.enter_name_seconds = 30;
|
||||
param.game.speed = 15;
|
||||
precalculateZones();
|
||||
|
||||
// SCOREBOARD
|
||||
|
||||
@@ -16,6 +16,7 @@ struct ParamGame
|
||||
Zone play_area; // Rectangulo con la posición de la zona de juego
|
||||
Zone game_area; // Rectangulo con las dimensiones del juego
|
||||
int enter_name_seconds; // Duración en segundos para introducir el nombre al finalizar la partida
|
||||
Uint32 speed; // Velocidad a la que transcurre el juego
|
||||
};
|
||||
|
||||
// param.fade
|
||||
@@ -83,7 +84,5 @@ struct Param
|
||||
|
||||
extern Param param;
|
||||
|
||||
extern Param param;
|
||||
|
||||
// Establece valores para los parametros a partir de un fichero de texto
|
||||
void loadParamsFromFile(const std::string &file_path);
|
||||
171
source/title.cpp
171
source/title.cpp
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,12 @@ private:
|
||||
// Muestra información sobre los controles y los jugadores
|
||||
void showControllers();
|
||||
|
||||
// Actualiza el fade
|
||||
void updateFade();
|
||||
|
||||
// Actualiza el estado
|
||||
void updateState();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Title();
|
||||
|
||||
Reference in New Issue
Block a user