Añadidas pausas en los creditos

This commit is contained in:
2022-10-24 14:01:59 +02:00
parent b8980d1b0b
commit 22c4724125
2 changed files with 52 additions and 15 deletions

View File

@@ -14,6 +14,8 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset)
// Inicializa variables
counter = 0;
counterEnabled = true;
subCounter = 0;
section.name = SECTION_PROG_CREDITS;
section.subsection = 0;
ticks = 0;
@@ -31,6 +33,7 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset)
texts.push_back({"FINISH THEM", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"KEYS:", stringToColor("yellow")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"USE CURSORS TO MOVE AND JUMP", stringToColor("white")});
@@ -41,10 +44,12 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset)
texts.push_back({"ESC TO EXIT GAME", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"A GAME BY JAILDESIGNER", stringToColor("yellow")});
texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor("yellow")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"LOVE JAILGAMES!}", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
@@ -116,7 +121,8 @@ void Credits::fillTexture()
{
// Rellena la textura de texto
SDL_SetRenderTarget(renderer, textTexture);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
const color_t c = stringToColor("black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0x00);
SDL_RenderClear(renderer);
// Escribe el texto en la textura
@@ -133,11 +139,11 @@ void Credits::fillTexture()
// Rellena la textura que cubre el texto
SDL_SetRenderTarget(renderer, coverTexture);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0x00);
SDL_RenderClear(renderer);
// Los primeros 8 pixels crea una malla
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
for (int i = 0; i < 256; i += 2)
{
SDL_RenderDrawPoint(renderer, i, 0);
@@ -158,6 +164,35 @@ void Credits::fillTexture()
SDL_SetRenderTarget(renderer, nullptr);
}
// Actualiza el contador
void Credits::updateCounter()
{
// Incrementa el contador
if (counterEnabled)
{
counter++;
if (counter == 224 || counter == 544 || counter == 672)
{
counterEnabled = false;
}
}
else
{
subCounter++;
if (subCounter == 100)
{
counterEnabled = true;
subCounter = 0;
}
}
// Comprueba si ha terminado la sección
if (counter > 1000)
{
section.name = SECTION_PROG_DEMO;
}
}
// Actualiza las variables
void Credits::update()
{
@@ -170,14 +205,8 @@ void Credits::update()
// Comprueba el manejador de eventos
checkEventHandler();
// Incrementa el contador
counter++;
// Comprueba si ha terminado la sección
if (counter > 1000)
{
section.name = SECTION_PROG_DEMO;
}
// Actualiza el contador
updateCounter();
}
}
@@ -198,6 +227,9 @@ void Credits::render()
SDL_Rect rect = {0, offset * 2, 256, 192};
SDL_RenderCopy(renderer, coverTexture, nullptr, &rect);
//text->write(0,0,std::to_string(counter));
//text->write(0,8,std::to_string(counterEnabled));
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}

View File

@@ -32,10 +32,12 @@ private:
SDL_Texture *coverTexture; // Textura para cubrir el texto
// Variables
int counter; // Contador
section_t section; // Estado del bucle principal para saber si continua o se sale
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
int counter; // Contador
bool counterEnabled; // Indica si esta activo el contador
int subCounter; // Contador secundario
section_t section; // Estado del bucle principal para saber si continua o se sale
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<captions_t> texts; // Vector con las letras de la marquesina
// Actualiza las variables
@@ -47,6 +49,9 @@ private:
// Comprueba el manejador de eventos
void checkEventHandler();
// Actualiza el contador
void updateCounter();
// Escribe el texto en la textura
void fillTexture();