- Actualitzem tots els gamestate per a usar els nous mòduls.

This commit is contained in:
2023-10-17 18:49:41 +02:00
parent bcd38a5a06
commit 8918c25b4e
5 changed files with 68 additions and 189 deletions

View File

@@ -1,28 +1,34 @@
#include "gamestates.h"
#include "jgame.h"
#include <string>
#define POSTFASE_INITIAL 0
#define POSTFASE_VICTORIA 1
#define POSTFASE_PASSWORD 2
#include "aux_font.h"
namespace gamestate
{
namespace postfase
{
namespace state
{
const int initial = 0;
const int victoria = 1;
const int password = 2;
}
// Variables del gamestate
static int sub_state = POSTFASE_INITIAL;
static int sub_state = postfase::state::initial;
void init_victoria();
void init_password();
void initVictoria();
void initPassword();
bool loop();
void drawText(const int x, const int y, const uint8_t color, std::string text);
char *ObtenerPasswordDeFase();
std::string getPassword();
void init()
{
sub_state = POSTFASE_INITIAL;
sub_state = postfase::state::initial;
font::selectFont(font::type::colored);
font::setColor(font::color::red);
if (game::getConfig("fase") == 30) {
gamestate::sequence::init();
@@ -33,34 +39,21 @@ namespace gamestate
}
if (game::getConfig("fase") % 5 == 0) {
gamestate::postfase::init_victoria();
gamestate::postfase::initVictoria();
} else {
gamestate::postfase::init_password();
gamestate::postfase::initPassword();
}
}
void init_victoria()
void initVictoria()
{
sub_state = POSTFASE_VICTORIA;
sub_state = postfase::state::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;
}
char filename[12] = "final00.GIF";
filename[6]= game::getConfig("fase") / 5;
fondo = draw::loadSurface(filename, true);
draw::setSource(fondo);
draw::draw(0,0,320,200,0,0);
draw::freeSurface(fondo);
@@ -69,19 +62,18 @@ namespace gamestate
game::setState(gamestate::postfase::loop);
}
void init_password()
void initPassword()
{
sub_state = POSTFASE_PASSWORD;
sub_state = postfase::state::password;
draw::surface *fondo = draw::loadSurface("postfase.gif", true);
char *password = ObtenerPasswordDeFase();
std::string password = getPassword();
draw::setSource(fondo);
draw::draw(0,0,320,200,0,0);
draw::freeSurface(fondo);
drawText(175, 166, 1, password);
free(password);
font::print(175, 166, password);
draw::fadein();
game::setState(gamestate::postfase::loop);
@@ -98,8 +90,8 @@ namespace gamestate
if (salir)
{
salir = false;
if (sub_state == POSTFASE_VICTORIA) {
gamestate::postfase::init_password();
if (sub_state == postfase::state::victoria) {
gamestate::postfase::initPassword();
} else {
gamestate::sequence::init();
}
@@ -115,41 +107,14 @@ namespace gamestate
return true;
}
void drawText(const int x, const int y, const uint8_t color, std::string text)
std::string getPassword()
{
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<len;++i)
{
char chr = text[i];
draw::draw(x+i*7, y, 6, 6, (int(chr)-32)*7, 0);
}
draw::setTrans(255);
draw::freeSurface(pic);
draw::render();
}
char *ObtenerPasswordDeFase()
{
int filesize = 0;
const char *buffer = file::getFileBuffer("offsets.bal", &filesize);
char *buffer = file::getFileBuffer("offsets.bal");
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);
}
char passFile[11];
for (int i=0;i<10;i++) passFile[i] = uint8_t(buffer[++punter]) - (101+i);
free(buffer);
return passFile;
}