Terminada la intro

This commit is contained in:
2022-09-04 09:46:27 +02:00
parent eba04a32fb
commit 5eaf44d0b8
6 changed files with 121 additions and 76 deletions

View File

@@ -14,41 +14,23 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset)
texture2 = new LTexture(renderer, asset->get("loading_screen2.png"));
sprite = new Sprite(0, 0, texture->getWidth(), texture->getHeight(), texture, renderer);
sprite2 = new Sprite(0, 0, texture2->getWidth(), texture2->getHeight(), texture2, renderer);
loadingSound1 = JA_LoadMusic(asset->get("loading_sound1.ogg").c_str());
loadingSound2 = JA_LoadMusic(asset->get("loading_sound2.ogg").c_str());
loadingSound3 = JA_LoadMusic(asset->get("loading_sound3.ogg").c_str());
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
// text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
// Inicializa variables
preCounter = 0;
counter = 0;
section.name = SECTION_PROG_INTRO;
section.subsection = 0;
ticks = 0;
ticksSpeed = 15;
counterLoad1 = 0;
counterLoad2 = 0;
color_t c = stringToColor("black");
color.push_back(c);
c = stringToColor("blue");
color.push_back(c);
c = stringToColor("red");
color.push_back(c);
c = stringToColor("purple");
color.push_back(c);
c = stringToColor("green");
color.push_back(c);
c = stringToColor("cyan");
color.push_back(c);
c = stringToColor("yellow");
color.push_back(c);
c = stringToColor("light_white");
color.push_back(c);
loadCounter = 0;
loadCounter = 0;
load1 = true;
load2 = false;
}
// Destructor
@@ -59,8 +41,11 @@ Intro::~Intro()
delete sprite;
delete sprite2;
delete eventHandler;
JA_DeleteMusic(loadingSound1);
JA_DeleteMusic(loadingSound2);
JA_DeleteMusic(loadingSound3);
delete text;
// delete text;
}
// Comprueba el manejador de eventos
@@ -85,44 +70,102 @@ void Intro::checkEventHandler()
}
}
// Gestiona la primera parte de la carga
void Intro::updateLoad1()
// Gestiona el contador de carga
void Intro::updateLoad()
{
counterLoad1 = std::min(counter / 3, 65);
if (load1)
{
loadCounter = counter / 20;
if (loadCounter == 25)
{
load1 = false;
load2 = true;
loadCounter = 0;
JA_PlayMusic(loadingSound3);
}
}
else
{
loadCounter += 2;
loadCounter = std::min(loadCounter, 768);
}
}
// Gestiona la segunda parte de la carga
void Intro::updateLoad2()
// Gestiona el contador interno
void Intro::updateCounter()
{
if (counterLoad1 == 65)
if (preCounter >= 50)
{
counterLoad2 += 2;
counterLoad2 = std::min(counterLoad2, 768);
if (counter == 0)
{
JA_PlayMusic(loadingSound2);
}
counter++;
}
else
{
preCounter++;
}
}
// Dibuja la pantalla de carga
void Intro::renderLoad()
{
if (counterLoad1 <= 64)
// Carga 1 - Blanco y negro
if (load1)
{
sprite->render();
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_Rect rect = {0, 0 + counterLoad1, 256, 64 - counterLoad1};
SDL_RenderFillRect(renderer, &rect);
// Muestra las lineas 0..63
if (loadCounter < 8)
{
SDL_Rect rect = {0, 0 + loadCounter, 256, 8 - loadCounter};
SDL_RenderFillRect(renderer, &rect);
rect.y += 64;
SDL_RenderFillRect(renderer, &rect);
for (int i = 0; i < 6; i++)
{
rect.y += 8;
SDL_RenderFillRect(renderer, &rect);
}
rect.y += 8;
rect.h = 128;
SDL_RenderFillRect(renderer, &rect);
}
// Muestra las lineas 64..127
else if (loadCounter >= 8 && loadCounter < 16)
{
SDL_Rect rect = {0, 64 + (loadCounter - 8), 256, 8 - (loadCounter - 8)};
SDL_RenderFillRect(renderer, &rect);
rect.y += 64;
SDL_RenderFillRect(renderer, &rect);
for (int i = 0; i < 6; i++)
{
rect.y += 8;
SDL_RenderFillRect(renderer, &rect);
}
rect.y += 8;
rect.h = 64;
SDL_RenderFillRect(renderer, &rect);
}
// Muestra las lineas 128..191
else if (loadCounter >= 16 && loadCounter < 23)
{
SDL_Rect rect = {0, 128 + (loadCounter - 16), 256, 8 - (loadCounter - 16)};
SDL_RenderFillRect(renderer, &rect);
for (int i = 0; i < 6; i++)
{
rect.y += 8;
SDL_RenderFillRect(renderer, &rect);
}
}
}
else
// Carga 2 - Color
{
sprite->render();
SDL_Rect rect = {0, 0, 8, 8};
for (int i = 0; i < counterLoad2; i++)
for (int i = 0; i < loadCounter; i++)
{
rect.x = (i * 8) % 256;
rect.y = (i / 32) * 8;
@@ -145,20 +188,18 @@ void Intro::update()
// Comprueba el manejador de eventos
checkEventHandler();
// Incrementa el contador
counter++;
// Gestiona el contador interno
updateCounter();
// Gestiona la primera parte de la carga
updateLoad1();
// Gestiona la segunda parte de la carga
updateLoad2();
// Gestiona el contador de carga
updateLoad();
// Comprueba si ha terminado la intro
if (counterLoad2 >= 768)
if (loadCounter >= 768)
{
section.name = SECTION_PROG_TITLE;
section.subsection = 0;
JA_StopMusic();
}
}
}
@@ -174,8 +215,8 @@ void Intro::render()
// Dibuja la pantalla de carga
renderLoad();
text->write(0, 0, std::to_string(counterLoad1));
text->write(0, 8, std::to_string(counterLoad2));
// text->write(0, 0, std::to_string(loadCounter));
// text->write(0, 8, std::to_string(loadCounter));
// Vuelca el contenido del renderizador en pantalla
screen->blit();
@@ -184,8 +225,8 @@ void Intro::render()
// Bucle para el logo del juego
section_t Intro::run()
{
// Detiene la música
JA_StopMusic();
// Inicia el sonido de carga
JA_PlayMusic(loadingSound1);
while (section.name == SECTION_PROG_INTRO)
{