- Actualitzem tots els gamestate per a usar els nous mòduls.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user