Limpieza de código en la lógica y dibujado del titulo

This commit is contained in:
2024-06-11 16:53:20 +02:00
parent ab59604cff
commit 90bfd8349b
3 changed files with 39 additions and 99 deletions

View File

@@ -190,9 +190,6 @@ void Title::init()
// Actualiza las variables del objeto // Actualiza las variables del objeto
void Title::update() void Title::update()
{ {
// Comprueba las entradas
checkInput();
// Calcula la lógica de los objetos // Calcula la lógica de los objetos
if (SDL_GetTicks() - ticks > ticksSpeed) if (SDL_GetTicks() - ticks > ticksSpeed)
{ {
@@ -229,7 +226,7 @@ void Title::update()
// Sección 2 - Titulo vibrando // Sección 2 - Titulo vibrando
case SUBSECTION_TITLE_2: case SUBSECTION_TITLE_2:
{ {
// Agita la pantalla // Agita el logo
static const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0}; static const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
static const int a = coffeeBitmap->getPosX(); static const int a = coffeeBitmap->getPosX();
static const int b = crisisBitmap->getPosX(); static const int b = crisisBitmap->getPosX();
@@ -241,10 +238,10 @@ void Title::update()
dustBitmapL->update(); dustBitmapL->update();
step++; step++;
if (step == 33) if (step == 33)
{ {
section->subsection = SUBSECTION_TITLE_3; section->subsection = SUBSECTION_TITLE_3;
step = 0;
} }
} }
break; break;
@@ -262,6 +259,7 @@ void Title::update()
JA_PlayMusic(titleMusic); JA_PlayMusic(titleMusic);
} }
// Actualiza los objetos
dustBitmapR->update(); dustBitmapR->update();
dustBitmapL->update(); dustBitmapL->update();
@@ -358,11 +356,6 @@ void Title::update()
// Dibuja el objeto en pantalla // Dibuja el objeto en pantalla
void Title::render() void Title::render()
{ {
switch (section->subsection)
{
// Sección 1 - Titulo desplazandose
case SUBSECTION_TITLE_1:
{
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen->start(); screen->start();
@@ -370,80 +363,31 @@ void Title::render()
screen->clean(bgColor); screen->clean(bgColor);
// Dibuja el tileado de fondo // Dibuja el tileado de fondo
// SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr); SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr);
backgroundObj->render(); // backgroundObj->render();
// Dibuja los objetos // Dibuja el logo
coffeeBitmap->render(); coffeeBitmap->render();
crisisBitmap->render(); crisisBitmap->render();
// Vuelca el contenido del renderizador en pantalla // Dibuja el polvillo del logo
screen->blit(); dustBitmapR->render();
} dustBitmapL->render();
break;
// Sección 2 - Titulo vibrando if (section->subsection == SUBSECTION_TITLE_3)
case SUBSECTION_TITLE_2:
{ {
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean(bgColor);
// Dibuja el tileado de fondo
// SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr);
backgroundObj->render();
// Dibuja los objetos
coffeeBitmap->render();
crisisBitmap->render();
dustBitmapR->render();
dustBitmapL->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
break;
// Sección 3 - La pantalla de titulo con el menú y la música
case SUBSECTION_TITLE_3:
{ // Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean(bgColor);
// Dibuja el tileado de fondo
// SDL_RenderCopy(renderer, background, &backgroundWindow, nullptr);
backgroundObj->render();
coffeeBitmap->render();
crisisBitmap->render();
// Dibuja el polvillo del título
dustBitmapR->render();
dustBitmapL->render();
// PRESS ANY KEY! // PRESS ANY KEY!
if (counter % 50 > 14) if (counter % 50 > 14)
{ {
text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_THIRD_QUARTER_Y + BLOCK, lang->getText(23), 1, noColor, 1, shdwTxtColor); text1->writeDX(TXT_CENTER | TXT_SHADOW, GAMECANVAS_CENTER_X, GAMECANVAS_THIRD_QUARTER_Y + BLOCK, lang->getText(23), 1, noColor, 1, shdwTxtColor);
} }
}
// Fade // Fade
fade->render(); fade->render();
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen->blit(); screen->blit();
}
break;
default:
break;
}
} }
// Comprueba los eventos // Comprueba los eventos
@@ -463,18 +407,6 @@ void Title::checkEvents()
{ {
reLoadTextures(); reLoadTextures();
} }
if (section->subsection == SUBSECTION_TITLE_3)
{ // Si se pulsa alguna tecla durante la tercera sección del titulo
if ((eventHandler->type == SDL_KEYUP) || (eventHandler->type == SDL_JOYBUTTONUP))
{
// Muestra el menu
menuVisible = true;
// Reinicia el contador
counter = TITLE_COUNTER;
}
}
} }
} }
@@ -500,6 +432,12 @@ void Title::checkInput()
{ {
screen->incWindowSize(); screen->incWindowSize();
} }
else if (input->checkInput(input_accept, REPEAT_FALSE))
{
fade->activateFade();
postFade = 0;
}
} }
// Actualiza el tileado de fondo // Actualiza el tileado de fondo
@@ -544,6 +482,7 @@ void Title::run()
{ {
while (section->name == SECTION_PROG_TITLE) while (section->name == SECTION_PROG_TITLE)
{ {
checkInput();
update(); update();
checkEvents(); checkEvents();
render(); render();

View File

@@ -7,3 +7,4 @@
[] Valorar la opcion de que write devuelva texturas con el texto en lugar de pintar letra a letra [] Valorar la opcion de que write devuelva texturas con el texto en lugar de pintar letra a letra
[] Arreglar los anclajes en la pantalla de game over [] Arreglar los anclajes en la pantalla de game over
[] Al poner pausa, que se sigan moviendo las nubes [] Al poner pausa, que se sigan moviendo las nubes
[] Revisar la clase Fade