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
void Title::update()
{
// Comprueba las entradas
checkInput();
// Calcula la lógica de los objetos
if (SDL_GetTicks() - ticks > ticksSpeed)
{
@@ -229,7 +226,7 @@ void Title::update()
// Sección 2 - Titulo vibrando
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 a = coffeeBitmap->getPosX();
static const int b = crisisBitmap->getPosX();
@@ -241,10 +238,10 @@ void Title::update()
dustBitmapL->update();
step++;
if (step == 33)
{
section->subsection = SUBSECTION_TITLE_3;
step = 0;
}
}
break;
@@ -262,6 +259,7 @@ void Title::update()
JA_PlayMusic(titleMusic);
}
// Actualiza los objetos
dustBitmapR->update();
dustBitmapL->update();
@@ -358,92 +356,38 @@ void Title::update()
// Dibuja el objeto en pantalla
void Title::render()
{
switch (section->subsection)
// 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 el logo
coffeeBitmap->render();
crisisBitmap->render();
// Dibuja el polvillo del logo
dustBitmapR->render();
dustBitmapL->render();
if (section->subsection == SUBSECTION_TITLE_3)
{
// Sección 1 - Titulo desplazandose
case SUBSECTION_TITLE_1:
{
// 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();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
break;
// Sección 2 - Titulo vibrando
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!
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);
}
// Fade
fade->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
break;
default:
break;
}
// Fade
fade->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Comprueba los eventos
@@ -463,18 +407,6 @@ void Title::checkEvents()
{
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();
}
else if (input->checkInput(input_accept, REPEAT_FALSE))
{
fade->activateFade();
postFade = 0;
}
}
// Actualiza el tileado de fondo
@@ -544,6 +482,7 @@ void Title::run()
{
while (section->name == SECTION_PROG_TITLE)
{
checkInput();
update();
checkEvents();
render();

View File

@@ -48,9 +48,9 @@ private:
section_t *section; // Indicador para el bucle del titulo
Background *backgroundObj; // Objeto para dibujar el fondo del juego
Texture *dustTexture; // Textura con los graficos del polvo
Texture *coffeeTexture; // Textura con los graficos de la palabra coffee
Texture *crisisTexture; // Textura con los graficos de la plabra crisis
Texture *dustTexture; // Textura con los graficos del polvo
Texture *coffeeTexture; // Textura con los graficos de la palabra coffee
Texture *crisisTexture; // Textura con los graficos de la plabra crisis
SDL_Rect backgroundWindow; // Ventana visible para la textura de fondo del titulo
SDL_Texture *background; // Textura dibujar el fondo del titulo