- Reestructurat el codi dels gamestates per a que siga mes llegible
This commit is contained in:
@@ -12,6 +12,26 @@ namespace gamestate
|
|||||||
draw::surface *cursor = nullptr;
|
draw::surface *cursor = nullptr;
|
||||||
int exit = 0;
|
int exit = 0;
|
||||||
|
|
||||||
|
bool loop();
|
||||||
|
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
exit = 0;
|
||||||
|
fondo = draw::loadSurface("menuprin.gif", true);
|
||||||
|
cursor = draw::loadSurface("cursor.gif");
|
||||||
|
|
||||||
|
if (audio::getMusicState() != audio::music_state::MUSIC_PLAYING) {
|
||||||
|
audio::playMusic(audio::loadMusic("mus3.ogg"));
|
||||||
|
}
|
||||||
|
|
||||||
|
draw::setSource(fondo);
|
||||||
|
draw::draw(0,0,320,200,0,0);
|
||||||
|
draw::fadein();
|
||||||
|
|
||||||
|
game::setState(&gamestate::menu::loop);
|
||||||
|
}
|
||||||
|
|
||||||
bool loop()
|
bool loop()
|
||||||
{
|
{
|
||||||
if (exit) {
|
if (exit) {
|
||||||
@@ -57,21 +77,5 @@ namespace gamestate
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
exit = 0;
|
|
||||||
fondo = draw::loadSurface("menuprin.gif", true);
|
|
||||||
cursor = draw::loadSurface("cursor.gif");
|
|
||||||
|
|
||||||
if (audio::getMusicState() != audio::music_state::MUSIC_PLAYING) {
|
|
||||||
audio::playMusic(audio::loadMusic("mus3.ogg"));
|
|
||||||
}
|
|
||||||
|
|
||||||
draw::setSource(fondo);
|
|
||||||
draw::draw(0,0,320,200,0,0);
|
|
||||||
draw::fadein();
|
|
||||||
|
|
||||||
game::setState(&gamestate::menu::loop);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,13 +10,65 @@ namespace gamestate
|
|||||||
{
|
{
|
||||||
namespace prefase
|
namespace prefase
|
||||||
{
|
{
|
||||||
|
// Variables del gamestate
|
||||||
draw::surface *fondo = nullptr;
|
draw::surface *fondo = nullptr;
|
||||||
draw::surface *cursor = nullptr;
|
draw::surface *cursor = nullptr;
|
||||||
draw::surface *font = nullptr;
|
draw::surface *font = nullptr;
|
||||||
|
|
||||||
uint8_t num_arounders = 0;
|
uint8_t num_arounders = 0;
|
||||||
uint8_t arounders_necessaris = 0;
|
uint8_t arounders_necessaris = 0;
|
||||||
uint8_t fase = 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()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
carregarMapa();
|
||||||
|
|
||||||
|
draw::fadein();
|
||||||
|
game::setState(gamestate::prefase::loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool loop()
|
||||||
|
{
|
||||||
|
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::render();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void carregarMapa()
|
void carregarMapa()
|
||||||
{
|
{
|
||||||
@@ -27,7 +79,6 @@ namespace gamestate
|
|||||||
|
|
||||||
num_arounders = *(punter++);
|
num_arounders = *(punter++);
|
||||||
arounders_necessaris = *punter;
|
arounders_necessaris = *punter;
|
||||||
fase = game::getConfig("fase")+1;
|
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
@@ -63,49 +114,5 @@ namespace gamestate
|
|||||||
for (int i=1;i<=5;++i) draw::restorecol(i);
|
for (int i=1;i<=5;++i) draw::restorecol(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loop()
|
|
||||||
{
|
|
||||||
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(fase));
|
|
||||||
|
|
||||||
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::render();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void init()
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
carregarMapa();
|
|
||||||
|
|
||||||
draw::fadein();
|
|
||||||
game::setState(gamestate::prefase::loop);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,37 +22,33 @@ namespace gamestate
|
|||||||
FILE *sequence_file = nullptr;
|
FILE *sequence_file = nullptr;
|
||||||
uint32_t wait_until = 0;
|
uint32_t wait_until = 0;
|
||||||
|
|
||||||
void drawPic(std::string filename)
|
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::surface *pic = draw::loadSurface(filename, true);
|
draw::setTrans(255);
|
||||||
draw::setSource(pic);
|
const int fase = game::getConfig("fase");
|
||||||
draw::draw(0, 0, 320, 200, 0, 0);
|
std::string filename;
|
||||||
draw::freeSurface(pic);
|
|
||||||
|
switch (fase)
|
||||||
|
{
|
||||||
|
case -1: filename = "seqIN.txt"; break;
|
||||||
|
case 0: filename = "seq00.txt"; break;
|
||||||
|
case 5: filename = "seq05.txt"; break;
|
||||||
|
case 10: filename = "seq10.txt"; break;
|
||||||
|
case 15: filename = "seq15.txt"; break;
|
||||||
|
case 20: filename = "seq20.txt"; break;
|
||||||
|
case 25: filename = "seq25.txt"; break;
|
||||||
|
case 30: filename = "seq30.txt"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawText(const int x, const int y, const uint8_t color, std::string text)
|
int filesize;
|
||||||
{
|
sequence_file = file::getFilePointer(filename, filesize);
|
||||||
draw::surface *pic = draw::loadSurface("fuente2.gif");
|
|
||||||
draw::setSource(pic);
|
game::setState(&gamestate::sequence::loop);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loop()
|
bool loop()
|
||||||
@@ -128,28 +124,38 @@ namespace gamestate
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init()
|
void drawPic(std::string filename)
|
||||||
{
|
{
|
||||||
|
draw::surface *pic = draw::loadSurface(filename, true);
|
||||||
|
draw::setSource(pic);
|
||||||
|
draw::draw(0, 0, 320, 200, 0, 0);
|
||||||
|
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);
|
||||||
|
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::setTrans(255);
|
||||||
const int fase = game::getConfig("fase");
|
draw::restorecol(1);
|
||||||
std::string filename;
|
draw::restorecol(2);
|
||||||
|
draw::freeSurface(pic);
|
||||||
switch (fase)
|
draw::render();
|
||||||
{
|
|
||||||
case -1: filename = "seqIN.txt"; break;
|
|
||||||
case 0: filename = "seq00.txt"; break;
|
|
||||||
case 5: filename = "seq05.txt"; break;
|
|
||||||
case 10: filename = "seq10.txt"; break;
|
|
||||||
case 15: filename = "seq15.txt"; break;
|
|
||||||
case 20: filename = "seq20.txt"; break;
|
|
||||||
case 25: filename = "seq25.txt"; break;
|
|
||||||
case 30: filename = "seq30.txt"; break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int filesize;
|
|
||||||
sequence_file = file::getFilePointer(filename, filesize);
|
|
||||||
|
|
||||||
game::setState(&gamestate::sequence::loop);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user