From 572dff8dbb0437830709c81a6a839c0dde74d21d Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 13 Oct 2023 16:23:24 +0200 Subject: [PATCH] - gamestate_postfase implementat. --- source/gamestate_postfase.cpp | 160 ++++++++++++++++++++++++++++++++++ source/gamestate_sequence.cpp | 1 + source/gamestates.h | 1 + 3 files changed, 162 insertions(+) create mode 100644 source/gamestate_postfase.cpp diff --git a/source/gamestate_postfase.cpp b/source/gamestate_postfase.cpp new file mode 100644 index 0000000..bbc462a --- /dev/null +++ b/source/gamestate_postfase.cpp @@ -0,0 +1,160 @@ +#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; + } + } + + 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); + draw::setPaletteEntry(64, 255, 255, 255); + draw::setPaletteEntry(65, 255, 0, 0); + draw::setPaletteEntry(66, 0, 255, 0); + draw::setPaletteEntry(67, 0, 0, 255); + draw::setPaletteEntry(68, 0, 0, 0); + draw::swapcol(1, color+64); + draw::swapcol(2, 68); + const int len = text.length(); + for (int i=0;i