forked from jaildesigner-jailgames/jaildoctors_dilemma
Actualizado el proceso de dibujado de la pantalla de carga
This commit is contained in:
131
source/intro.cpp
131
source/intro.cpp
@@ -10,10 +10,10 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
eventHandler = new SDL_Event();
|
||||
texture = new LTexture(renderer, asset->get("loading_screen1.png"));
|
||||
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);
|
||||
loadingScreenTexture1 = new LTexture(renderer, asset->get("loading_screen1.png"));
|
||||
loadingScreenTexture2 = new LTexture(renderer, asset->get("loading_screen2.png"));
|
||||
sprite1 = new Sprite(0, 0, loadingScreenTexture1->getWidth(), loadingScreenTexture1->getHeight(), loadingScreenTexture1, renderer);
|
||||
sprite2 = new Sprite(0, 0, loadingScreenTexture2->getWidth(), loadingScreenTexture2->getHeight(), loadingScreenTexture2, 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());
|
||||
@@ -26,9 +26,35 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
ticks = 0;
|
||||
ticksSpeed = 15;
|
||||
loadCounter = 0;
|
||||
loadCounter = 0;
|
||||
load1 = true;
|
||||
load2 = false;
|
||||
lineCounter = 0;
|
||||
loadingFirstPart = true;
|
||||
|
||||
// Ls lineas que tapan la primera textura
|
||||
for (int i = 0; i < 192; ++i)
|
||||
{
|
||||
lines[i].x1 = 0;
|
||||
lines[i].x2 = 257;
|
||||
lines[i].y = i;
|
||||
}
|
||||
|
||||
// Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum
|
||||
for (int i = 0; i < 192; ++i)
|
||||
{
|
||||
if (i < 64)
|
||||
{ // Primer bloque de 2K
|
||||
lineIndex[i] = ((i % 8) * 8) + (i / 8);
|
||||
}
|
||||
|
||||
else if (i >= 64 && i < 128)
|
||||
{ // Segundo bloque de 2K
|
||||
lineIndex[i] = 64 + ((i % 8) * 8) + ((i - 64) / 8);
|
||||
}
|
||||
|
||||
else if (i >= 128 && i < 192)
|
||||
{ // tercer bloque de 2K
|
||||
lineIndex[i] = 128 + ((i % 8) * 8) + ((i - 128) / 8);
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el color del borde
|
||||
screen->setBorderColor(stringToColor("black"));
|
||||
@@ -37,9 +63,9 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
||||
// Destructor
|
||||
Intro::~Intro()
|
||||
{
|
||||
delete texture;
|
||||
delete texture2;
|
||||
delete sprite;
|
||||
delete loadingScreenTexture1;
|
||||
delete loadingScreenTexture2;
|
||||
delete sprite1;
|
||||
delete sprite2;
|
||||
delete eventHandler;
|
||||
JA_DeleteMusic(loadingSound1);
|
||||
@@ -74,17 +100,34 @@ void Intro::checkEventHandler()
|
||||
// Gestiona el contador de carga
|
||||
void Intro::updateLoad()
|
||||
{
|
||||
if (load1)
|
||||
// Primera parte de la carga, la parte en blanco ynegro
|
||||
if (loadingFirstPart)
|
||||
{
|
||||
loadCounter = counter / 20;
|
||||
if (loadCounter == 25)
|
||||
// Cada 5 pasos el loadCounter se incrementa en uno
|
||||
const int numSteps = 5;
|
||||
loadCounter = counter / numSteps;
|
||||
|
||||
if (loadCounter < 192)
|
||||
{
|
||||
load1 = false;
|
||||
load2 = true;
|
||||
const int step = 256 / numSteps;
|
||||
lines[lineIndex[loadCounter]].x1 = step * (counter % numSteps);
|
||||
|
||||
// Elimina por completo la linea anterior
|
||||
if (loadCounter > 0)
|
||||
{
|
||||
lines[lineIndex[loadCounter - 1]].x1 = 256;
|
||||
}
|
||||
}
|
||||
|
||||
// Una vez actualizadas las 192 lineas, pasa a la segunda fase de la carga
|
||||
else if (loadCounter == 192)
|
||||
{
|
||||
loadingFirstPart = false;
|
||||
loadCounter = 0;
|
||||
JA_PlayMusic(loadingSound3);
|
||||
}
|
||||
}
|
||||
// Segunda parte de la carga, la parte de los bloques en color
|
||||
else
|
||||
{
|
||||
loadCounter += 2;
|
||||
@@ -96,7 +139,7 @@ void Intro::updateLoad()
|
||||
void Intro::updateCounter()
|
||||
{
|
||||
if (preCounter >= 50)
|
||||
{
|
||||
{ // Si el contador previo ha llegado a 50, empieza a contar el contador normal
|
||||
if (counter == 0)
|
||||
{
|
||||
JA_PlayMusic(loadingSound2);
|
||||
@@ -104,7 +147,7 @@ void Intro::updateCounter()
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
{ // Actualiza el precontador
|
||||
preCounter++;
|
||||
}
|
||||
}
|
||||
@@ -113,58 +156,22 @@ void Intro::updateCounter()
|
||||
void Intro::renderLoad()
|
||||
{
|
||||
// Carga 1 - Blanco y negro
|
||||
if (load1)
|
||||
if (loadingFirstPart)
|
||||
{
|
||||
sprite->render();
|
||||
// Dibuja la textura de pantalla de carga en blanco y negro en pantalla
|
||||
sprite1->render();
|
||||
|
||||
// Dibuja las 192 lineas negras sobre la textura
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
|
||||
// Muestra las lineas 0..63
|
||||
if (loadCounter < 8)
|
||||
for (int i = 0; i < 192; ++i)
|
||||
{
|
||||
SDL_Rect rect = {0, 0 + loadCounter, 256, 8 - loadCounter};
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
SDL_RenderDrawLine(renderer, lines[i].x1, lines[i].y, lines[i].x2, lines[i].y);
|
||||
}
|
||||
}
|
||||
else
|
||||
// Carga 2 - Color
|
||||
{
|
||||
sprite->render();
|
||||
sprite1->render();
|
||||
SDL_Rect rect = {0, 0, 8, 8};
|
||||
for (int i = 0; i < loadCounter; ++i)
|
||||
{
|
||||
@@ -216,8 +223,6 @@ void Intro::render()
|
||||
|
||||
// Dibuja la pantalla de carga
|
||||
renderLoad();
|
||||
// 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();
|
||||
|
||||
Reference in New Issue
Block a user