#include "intro.h" // Constructor Intro::Intro(SDL_Renderer *renderer, Screen *screen, Asset *asset) { // Copia la dirección de los objetos this->renderer = renderer; this->screen = screen; this->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(), texture, renderer); // Inicializa variables counter = 0; section.name = SECTION_PROG_INTRO; section.subsection = 0; ticks = 0; ticksSpeed = 15; counterLoad1 = 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); } // Destructor Intro::~Intro() { delete texture; delete texture2; delete sprite; delete sprite2; delete eventHandler; } // Comprueba el manejador de eventos void Intro::checkEventHandler() { // Comprueba los eventos que hay en la cola while (SDL_PollEvent(eventHandler) != 0) { // Evento de salida de la aplicación if (eventHandler->type == SDL_QUIT) { section.name = SECTION_PROG_QUIT; break; } // Cualquier tecla pulsada if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { section.name = SECTION_PROG_TITLE; section.subsection = 0; } } } // Gestiona la primera parte de la carga void Intro::updateLoad1() { counterLoad1 = std::min(counter / 3, 64); } // Gestiona la segunda parte de la carga void Intro::updateLoad2() { } // Dibuja la pantalla de carga void Intro::renderLoad() { sprite->render(); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_Rect rect = {0, 0 + counterLoad1, 256, 64 - counterLoad1}; SDL_RenderFillRect(renderer, &rect); rect.y += 64; SDL_RenderFillRect(renderer, &rect); rect.y += 64; SDL_RenderFillRect(renderer, &rect); } // Actualiza las variables void Intro::update() { // Comprueba que la diferencia de ticks sea mayor a la velocidad del juego if (SDL_GetTicks() - ticks > ticksSpeed) { // Actualiza el contador de ticks ticks = SDL_GetTicks(); // Comprueba el manejador de eventos checkEventHandler(); // Incrementa el contador counter++; // Gestiona la primera parte de la carga updateLoad1(); // Gestiona la segunda parte de la carga updateLoad2(); // Comprueba si ha terminado el logo if (counter == 1000) { section.name = SECTION_PROG_TITLE; section.subsection = 0; } } } // Dibuja en pantalla void Intro::render() { // Prepara para empezar a dibujar en la textura de juego screen->start(); // Limpia la pantalla screen->clean(); // Dibuja la pantalla de carga renderLoad(); // Vuelca el contenido del renderizador en pantalla screen->blit(); } // Bucle para el logo del juego section_t Intro::run() { // Detiene la música JA_StopMusic(); while (section.name == SECTION_PROG_INTRO) { update(); render(); } return section; }