#include "ending2.h" // Constructor Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options) { // Copia los punteros this->renderer = renderer; this->screen = screen; this->resource = resource; this->asset = asset; this->options = options; // Reserva memoria para los punteros a objetos eventHandler = new SDL_Event(); text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer); music = JA_LoadMusic(asset->get("ending2.ogg").c_str()); // Inicializa variables counter = -1; preCounter = 0; section.name = SECTION_PROG_ENDING2; section.subsection = 0; ticks = 0; ticksSpeed = 15; // Cambia el color del borde screen->setBorderColor(stringToColor(options->palette, "black")); } // Destructor Ending2::~Ending2() { // Libera la memoria de los objetos delete eventHandler; delete text; JA_DeleteMusic(music); } // Actualiza el objeto void Ending2::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(); // Actualiza los contadores updateCounters(); if (counter > 400) { section.name = SECTION_PROG_LOGO; } } } // Dibuja el final en pantalla void Ending2::render() { // Prepara para empezar a dibujar en la textura de juego screen->start(); // Limpia la pantalla screen->clean(stringToColor(options->palette, "black")); text->write(0,0,std::to_string(counter)); // Vuelca el contenido del renderizador en pantalla screen->blit(); } // Comprueba el manejador de eventos void Ending2::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_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { 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: break; } } } } // Bucle principal section_t Ending2::run() { JA_PlayMusic(music); while (section.name == SECTION_PROG_ENDING2) { update(); render(); } JA_StopMusic(); return section; } // Actualiza los contadores void Ending2::updateCounters() { // Incrementa el contador if (preCounter < 200) { preCounter++; } else { counter++; } }