- Actualitzem tots els gamestate per a usar els nous mòduls.
This commit is contained in:
@@ -11,7 +11,6 @@ namespace gamestate
|
||||
|
||||
bool loop();
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
exit = 0;
|
||||
@@ -22,8 +21,6 @@ namespace gamestate
|
||||
audio::playMusic(audio::loadMusic("mus3.ogg"));
|
||||
}
|
||||
|
||||
draw::setSource(fondo);
|
||||
draw::draw(0,0,320,200,0,0);
|
||||
draw::fadein();
|
||||
|
||||
game::setState(&gamestate::menu::loop);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "gamestates.h"
|
||||
#include "jgame.h"
|
||||
#include <string>
|
||||
#include "aux_font.h"
|
||||
#include "proc_mapa.h"
|
||||
|
||||
namespace gamestate
|
||||
{
|
||||
@@ -9,30 +11,35 @@ namespace gamestate
|
||||
// Variables del gamestate
|
||||
draw::surface *fondo = nullptr;
|
||||
draw::surface *cursor = nullptr;
|
||||
draw::surface *font = nullptr;
|
||||
|
||||
uint8_t num_arounders = 0;
|
||||
uint8_t arounders_necessaris = 0;
|
||||
|
||||
// Mètodes del gamestate
|
||||
void carregarMapa();
|
||||
std::string formatejar(const int numero);
|
||||
void drawText(const int x, const int y, std::string text);
|
||||
bool loop();
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
// Carrega el gif del fondo
|
||||
fondo = draw::loadSurface("prefase.gif", true);
|
||||
cursor = draw::loadSurface("cursor.gif");
|
||||
font = draw::loadSurface("fuente1.gif");
|
||||
|
||||
//int size=0;
|
||||
//uint32_t *font_pal = draw::loadPalette("fuente1.gif", &size);
|
||||
//draw::setPalette(font_pal+1, 5, 80);
|
||||
// Carrega el mapa
|
||||
mapa::carregar();
|
||||
|
||||
carregarMapa();
|
||||
// Pinta el text en el fondo
|
||||
draw::setDestination(fondo);
|
||||
font::selectFont(font::type::normal);
|
||||
|
||||
font::print(130, 60, "NIVELL");
|
||||
font::print(179, 60, game::getConfig("fase")+1);
|
||||
|
||||
font::print(80, 100, mapa::arounders::totals);
|
||||
font::print(101, 100, "AROUNDERS DISPONIBLES");
|
||||
|
||||
font::print(80, 110, mapa::arounders::necessaris);
|
||||
font::print(101, 110, "AROUNDERS NECESSARIS");
|
||||
|
||||
draw::setDestination(nullptr);
|
||||
|
||||
// Comencem el bucle
|
||||
draw::fadein();
|
||||
game::setState(gamestate::prefase::loop);
|
||||
}
|
||||
@@ -41,27 +48,12 @@ namespace gamestate
|
||||
{
|
||||
static bool salir = false;
|
||||
|
||||
const int x = input::mouseX();
|
||||
const int y = input::mouseY();
|
||||
|
||||
draw::setTrans(255);
|
||||
draw::setSource(fondo);
|
||||
draw::draw(0, 0, 320, 200, 0, 0);
|
||||
|
||||
draw::setTrans(0);
|
||||
draw::setSource(font);
|
||||
|
||||
drawText(130, 60, "NIVELL");
|
||||
drawText(179, 60, formatejar(game::getConfig("fase")+1));
|
||||
|
||||
drawText(80, 100, formatejar(num_arounders));
|
||||
drawText(101, 100, "AROUNDERS DISPONIBLES");
|
||||
|
||||
drawText(80, 110, formatejar(arounders_necessaris));
|
||||
drawText(101, 110, "AROUNDERS NECESSARIS");
|
||||
|
||||
draw::setSource(cursor);
|
||||
draw::draw(x, y, cursor->w, cursor->h, 0, 0);
|
||||
draw::draw(input::mouseX(), input::mouseY(), cursor->w, cursor->h, 0, 0);
|
||||
|
||||
draw::render();
|
||||
|
||||
@@ -83,49 +75,5 @@ namespace gamestate
|
||||
return true;
|
||||
}
|
||||
|
||||
void carregarMapa()
|
||||
{
|
||||
int filesize = 0;
|
||||
char *buffer = file::getFileBuffer("MAPES.BAL", &filesize);
|
||||
|
||||
char *punter = buffer + (game::getConfig("fase") * 212) + 3;
|
||||
|
||||
num_arounders = *(punter++);
|
||||
arounders_necessaris = *punter;
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
std::string formatejar(const int numero)
|
||||
{
|
||||
char resultat[3];
|
||||
|
||||
if (numero > 9) {
|
||||
resultat[0] = (numero / 10) + 48;
|
||||
resultat[1] = (numero % 10) + 48;
|
||||
} else {
|
||||
resultat[0] = 48;
|
||||
resultat[1] = (numero % 10) + 48;
|
||||
}
|
||||
|
||||
resultat[2] = '\0';
|
||||
|
||||
return std::string(resultat);
|
||||
}
|
||||
|
||||
void drawText(const int x, const int y, std::string text)
|
||||
{
|
||||
draw::setSource(font);
|
||||
draw::setTrans(0);
|
||||
//for (int i=1;i<=5;++i) draw::swapcol(i, 79+i);
|
||||
const int len = text.length();
|
||||
for (int i=0;i<len;++i)
|
||||
{
|
||||
char chr = text[i];
|
||||
draw::draw(x+i*7, y, 5, 5, (int(chr)-32)*7, 0);
|
||||
}
|
||||
//for (int i=1;i<=5;++i) draw::restorecol(i);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,7 @@
|
||||
#include "jgame.h"
|
||||
#include <string>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#define DIAPO_ESPERAR 0
|
||||
#define DIAPO_FADEIN 1
|
||||
#define DIAPO_SHOW 2
|
||||
#define DIAPO_PRINT 3
|
||||
#define DIAPO_MUSICA 4
|
||||
#define DIAPO_FADEOUT 5
|
||||
#define DIAPO_FADEMUSIC 6
|
||||
#include "aux_font.h"
|
||||
|
||||
namespace gamestate
|
||||
{
|
||||
@@ -19,17 +12,16 @@ namespace gamestate
|
||||
uint32_t wait_until = 0;
|
||||
|
||||
void drawPic(std::string filename);
|
||||
void drawText(const int x, const int y, const uint8_t color, std::string text);
|
||||
bool loop();
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
draw::setTrans(255);
|
||||
const int fase = game::getConfig("fase");
|
||||
font::selectFont(font::type::colored);
|
||||
|
||||
std::string filename;
|
||||
|
||||
switch (fase)
|
||||
switch (game::getConfig("fase"))
|
||||
{
|
||||
case -1: filename = "seqIN.txt"; break;
|
||||
case 0: filename = "seq00.txt"; break;
|
||||
@@ -39,11 +31,10 @@ namespace gamestate
|
||||
case 20: filename = "seq20.txt"; break;
|
||||
case 25: filename = "seq25.txt"; break;
|
||||
case 30: filename = "seq30.txt"; break;
|
||||
default: gamestate::prefase::init();
|
||||
default: gamestate::prefase::init(); return; break;
|
||||
}
|
||||
|
||||
int filesize;
|
||||
sequence_file = file::getFilePointer(filename, &filesize);
|
||||
sequence_file = file::getFilePointer(filename);
|
||||
|
||||
game::setState(&gamestate::sequence::loop);
|
||||
}
|
||||
@@ -54,6 +45,7 @@ namespace gamestate
|
||||
draw::render();
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( (wait_until > 0) && (SDL_GetTicks() < wait_until) )
|
||||
{
|
||||
if (input::anyKeyPressed() || input::mouseBtn(1)) {
|
||||
@@ -87,30 +79,26 @@ namespace gamestate
|
||||
std::string command(text);
|
||||
|
||||
if (command=="ESPERAR") {
|
||||
//int res =
|
||||
fscanf(sequence_file, "%i", &val);
|
||||
printf("ESPERAR %i\n", val);
|
||||
wait_until = SDL_GetTicks() + val;
|
||||
|
||||
} else if (command=="FADEIN") {
|
||||
//int res =
|
||||
fscanf(sequence_file, " '%[^']'", text);
|
||||
drawPic(text);
|
||||
draw::fadein();
|
||||
|
||||
} else if (command=="SHOW") {
|
||||
//int res =
|
||||
fscanf(sequence_file, " '%[^']'", text);
|
||||
drawPic(text);
|
||||
draw::render();
|
||||
|
||||
} else if (command=="PRINT") {
|
||||
//int res =
|
||||
fscanf(sequence_file, " %i %i %i '%[^']'", &x, &y, &val, text);
|
||||
drawText(x, y, val, text);
|
||||
font::setColor(val);
|
||||
font::print(x, y, text);
|
||||
|
||||
} else if (command=="PLAYMUSIC") {
|
||||
//int res =
|
||||
fscanf(sequence_file, " '%[^']'", text);
|
||||
audio::loadMusic(text);
|
||||
audio::playMusic();
|
||||
@@ -135,27 +123,5 @@ namespace gamestate
|
||||
draw::freeSurface(pic);
|
||||
}
|
||||
|
||||
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<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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "jgame.h"
|
||||
#include "gamestates.h"
|
||||
#include "aux_font.h"
|
||||
|
||||
void game::init()
|
||||
{
|
||||
@@ -7,6 +8,8 @@ void game::init()
|
||||
input::init(3);
|
||||
audio::init();
|
||||
|
||||
font::init();
|
||||
|
||||
game::setUpdateTicks(16);
|
||||
game::setConfig("fase", -1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user