#include "gamestates.h" #include "jgame.h" #include #define POSTFASE_INITIAL 0 #define POSTFASE_VICTORIA 1 #define POSTFASE_PASSWORD 2 namespace gamestate { namespace postfase { // Variables del gamestate static int sub_state = POSTFASE_INITIAL; void init_victoria(); void init_password(); bool loop(); void drawText(const int x, const int y, const uint8_t color, std::string text); char *ObtenerPasswordDeFase(); void init() { sub_state = POSTFASE_INITIAL; if (game::getConfig("fase") == 30) { gamestate::sequence::init(); return; } else { audio::loadMusic("mus3.mp3"); audio::playMusic(); } if (game::getConfig("fase") % 5 == 0) { gamestate::postfase::init_victoria(); } else { gamestate::postfase::init_password(); } } void init_victoria() { sub_state = POSTFASE_VICTORIA; draw::surface *fondo = nullptr; switch (game::getConfig("fase")) { case 5: fondo = draw::loadSurface("final01.GIF", true); break; case 10: fondo = draw::loadSurface("final02.GIF", true); break; case 15: fondo = draw::loadSurface("final03.GIF", true); break; case 20: fondo = draw::loadSurface("final04.GIF", true); break; case 25: fondo = draw::loadSurface("final05.GIF", true); break; } draw::setSource(fondo); draw::draw(0,0,320,200,0,0); draw::freeSurface(fondo); draw::fadein(); game::setState(gamestate::postfase::loop); } void init_password() { sub_state = POSTFASE_PASSWORD; draw::surface *fondo = draw::loadSurface("postfase.gif", true); char *password = ObtenerPasswordDeFase(); draw::setSource(fondo); draw::draw(0,0,320,200,0,0); draw::freeSurface(fondo); drawText(175, 166, 1, password); free(password); draw::fadein(); game::setState(gamestate::postfase::loop); } bool loop() { static bool salir = false; draw::render(); if (draw::isfading()) return true; if (salir) { salir = false; if (sub_state == POSTFASE_VICTORIA) { gamestate::postfase::init_password(); } else { gamestate::sequence::init(); } return true; } if (input::anyKeyPressed() || input::mouseBtn(1)) { draw::fadeout(); salir = true; return true; } return true; } void drawText(const int x, const int y, const uint8_t color, std::string text) { draw::surface *pic = draw::loadSurface("fuente2.gif"); draw::setSource(pic); draw::setTrans(0); switch (color) { case 0: draw::setPaletteEntry(63, 255, 255, 255); break; case 1: draw::setPaletteEntry(63, 255, 0, 0); break; case 2: draw::setPaletteEntry(63, 0, 255, 0); break; case 3: draw::setPaletteEntry(63, 0, 0, 255); break; } const int len = text.length(); for (int i=0;i