- gamestate_postfase implementat.
This commit is contained in:
160
source/gamestate_postfase.cpp
Normal file
160
source/gamestate_postfase.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "gamestates.h"
|
||||
#include "jgame.h"
|
||||
#include <string>
|
||||
|
||||
#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<len;++i)
|
||||
{
|
||||
char chr = text[i];
|
||||
draw::draw(x+i*7, y, 6, 6, (int(chr)-32)*7, 0);
|
||||
}
|
||||
draw::setTrans(255);
|
||||
draw::restorecol(1);
|
||||
draw::restorecol(2);
|
||||
draw::freeSurface(pic);
|
||||
draw::render();
|
||||
}
|
||||
|
||||
char *ObtenerPasswordDeFase()
|
||||
{
|
||||
int filesize = 0;
|
||||
const char *buffer = file::getFileBuffer("offsets.bal", filesize);
|
||||
|
||||
int punter = (game::getConfig("fase")-1)*11;
|
||||
|
||||
char *passFile = (char*)malloc(11);
|
||||
|
||||
for (int i=0;i<10;i++) {
|
||||
punter++;
|
||||
passFile[i] = uint8_t(buffer[punter]) - (101+i);
|
||||
}
|
||||
|
||||
return passFile;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ namespace gamestate
|
||||
case 20: filename = "seq20.txt"; break;
|
||||
case 25: filename = "seq25.txt"; break;
|
||||
case 30: filename = "seq30.txt"; break;
|
||||
default: gamestate::prefase::init();
|
||||
}
|
||||
|
||||
int filesize;
|
||||
|
||||
@@ -5,4 +5,5 @@ namespace gamestate
|
||||
namespace sequence { void init(); }
|
||||
namespace menu { void init(); }
|
||||
namespace prefase { void init(); }
|
||||
namespace postfase { void init(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user