#include "logo.h" #include // Constructor Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection) { // Copia la dirección de los objetos this->resource = resource; this->renderer = renderer; this->screen = screen; this->asset = asset; this->options = options; // Reserva memoria para los punteros eventHandler = new SDL_Event(); texture = resource->getTexture("jailgames.png"); texture2 = resource->getTexture("since_1998.png"); sprite2 = new Sprite((256 - texture2->getWidth()) / 2, 83 + texture->getHeight() + 5, texture2->getWidth(), texture2->getHeight(), texture2, renderer); sprite2->setSpriteClip(0, 0, texture2->getWidth(), texture2->getHeight()); texture2->setColor(0, 0, 0); // Crea los sprites de cada linea for (int i = 0; i < texture->getHeight(); ++i) { sprite.push_back(new Sprite(0, i, texture->getWidth(), 1, texture, renderer)); sprite.back()->setSpriteClip(0, i, texture->getWidth(), 1); if (i % 2 == 0) { sprite.at(i)->setPosX(256 + (i * 3)); } else { sprite.at(i)->setPosX(-181 - (i * 3)); } sprite.at(i)->setPosY(83 + i); } // Inicializa variables counter = 0; section.name = SECTION_PROG_LOGO; section.subsection = subsection; ticks = 0; ticksSpeed = 15; initFade = 300; endLogo = 400; postLogo = 20; // Inicializa el vector de colores const std::vector vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"}; for (auto v : vColors) { color.push_back(stringToColor(options->palette, v)); } // Cambia el color del borde screen->setBorderColor(stringToColor(options->palette, "black")); } // Destructor Logo::~Logo() { for (auto s : sprite) { delete s; } delete sprite2; delete eventHandler; } // Comprueba el manejador de eventos void Logo::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; } // Comprueba las teclas que se han pulsado if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP)) { switch (eventHandler->key.keysym.scancode) { case SDL_SCANCODE_ESCAPE: section.name = SECTION_PROG_QUIT; break; case SDL_SCANCODE_B: screen->switchBorder(); resource->reLoadTextures(); break; case SDL_SCANCODE_F: screen->switchVideoMode(); resource->reLoadTextures(); break; case SDL_SCANCODE_F1: screen->setWindowSize(1); resource->reLoadTextures(); break; case SDL_SCANCODE_F2: screen->setWindowSize(2); resource->reLoadTextures(); break; case SDL_SCANCODE_F3: screen->setWindowSize(3); resource->reLoadTextures(); break; case SDL_SCANCODE_F4: screen->setWindowSize(4); resource->reLoadTextures(); break; case SDL_SCANCODE_F5: switchPalette(); break; default: section.subsection = SUBSECTION_LOGO_TO_TITLE; endSection(); break; } } } } // Gestiona el logo de JAILGAME void Logo::updateJAILGAMES() { if (counter > 30) { for (int i = 1; i < (int)sprite.size(); ++i) { const int speed = 8; const int dest = 37; if (sprite.at(i)->getPosX() != 37) { if (i % 2 == 0) { sprite.at(i)->incPosX(-speed); if (sprite.at(i)->getPosX() < dest) { sprite.at(i)->setPosX(dest); } } else { sprite.at(i)->incPosX(speed); if (sprite.at(i)->getPosX() > dest) { sprite.at(i)->setPosX(dest); } } } } } } // Gestiona el color de las texturas void Logo::updateTextureColors() { const int ini = 70; const int inc = 4; if (counter == ini + inc * 0) { texture2->setColor(color.at(0).r, color.at(0).g, color.at(0).b); } else if (counter == ini + inc * 1) { texture2->setColor(color.at(1).r, color.at(1).g, color.at(1).b); } else if (counter == ini + inc * 2) { texture2->setColor(color.at(2).r, color.at(2).g, color.at(2).b); } else if (counter == ini + inc * 3) { texture2->setColor(color.at(3).r, color.at(3).g, color.at(3).b); } else if (counter == ini + inc * 4) { texture2->setColor(color.at(4).r, color.at(4).g, color.at(4).b); } else if (counter == ini + inc * 5) { texture2->setColor(color.at(5).r, color.at(5).g, color.at(5).b); } else if (counter == ini + inc * 6) { texture2->setColor(color.at(6).r, color.at(6).g, color.at(6).b); } else if (counter == ini + inc * 7) { texture2->setColor(color.at(7).r, color.at(7).g, color.at(7).b); } else if (counter == initFade + inc * 0) { texture->setColor(color.at(6).r, color.at(6).g, color.at(6).b); texture2->setColor(color.at(6).r, color.at(6).g, color.at(6).b); } else if (counter == initFade + inc * 1) { texture->setColor(color.at(5).r, color.at(5).g, color.at(5).b); texture2->setColor(color.at(5).r, color.at(5).g, color.at(5).b); } else if (counter == initFade + inc * 2) { texture->setColor(color.at(4).r, color.at(4).g, color.at(4).b); texture2->setColor(color.at(4).r, color.at(4).g, color.at(4).b); } else if (counter == initFade + inc * 3) { texture->setColor(color.at(3).r, color.at(3).g, color.at(3).b); texture2->setColor(color.at(3).r, color.at(3).g, color.at(3).b); } else if (counter == initFade + inc * 4) { texture->setColor(color.at(2).r, color.at(2).g, color.at(2).b); texture2->setColor(color.at(2).r, color.at(2).g, color.at(2).b); } else if (counter == initFade + inc * 5) { texture->setColor(color.at(1).r, color.at(1).g, color.at(1).b); texture2->setColor(color.at(1).r, color.at(1).g, color.at(1).b); } else if (counter == initFade + inc * 6) { texture->setColor(color.at(0).r, color.at(0).g, color.at(0).b); texture2->setColor(color.at(0).r, color.at(0).g, color.at(0).b); } } // Actualiza las variables void Logo::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 el logo de JAILGAME updateJAILGAMES(); // Gestiona el color de las texturas updateTextureColors(); // Actualiza las notificaciones screen->updateNotifier(); // Comprueba si ha terminado el logo if (counter == endLogo + postLogo) { endSection(); } } } // Dibuja en pantalla void Logo::render() { // Prepara para empezar a dibujar en la textura de juego screen->start(); // Limpia la pantalla screen->clean(); // Dibuja los objetos for (auto s : sprite) { s->render(); } sprite2->render(); // Vuelca el contenido del renderizador en pantalla screen->blit(); } // Bucle para el logo del juego section_t Logo::run() { // Detiene la música JA_StopMusic(); while (section.name == SECTION_PROG_LOGO) { update(); render(); } return section; } // Cambia la paleta void Logo::switchPalette() { options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum; } // Termina la sección void Logo::endSection() { section.name = SECTION_PROG_ENTER_ID; }