Compare commits
3 Commits
183c095f6d
...
e8a5c033bb
| Author | SHA1 | Date | |
|---|---|---|---|
| e8a5c033bb | |||
| a1d3209dd3 | |||
| 1309e5d7d8 |
BIN
data/fuente1.gif
BIN
data/fuente1.gif
Binary file not shown.
|
Before Width: | Height: | Size: 397 B After Width: | Height: | Size: 405 B |
@@ -60,8 +60,7 @@ namespace gamestate
|
||||
void init()
|
||||
{
|
||||
exit = 0;
|
||||
fondo = draw::loadSurface("menuprin.gif");
|
||||
draw::loadPalette("menuprin.gif");
|
||||
fondo = draw::loadSurface("menuprin.gif", true);
|
||||
cursor = draw::loadSurface("cursor.gif");
|
||||
|
||||
if (audio::getMusicState() != audio::music_state::MUSIC_PLAYING) {
|
||||
|
||||
111
source/gamestate_prefase.cpp
Normal file
111
source/gamestate_prefase.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
#include "gamestates.h"
|
||||
#include "jgame.h"
|
||||
#include "jdraw.h"
|
||||
#include "jaudio.h"
|
||||
#include "jinput.h"
|
||||
#include "jfile.h"
|
||||
#include <string>
|
||||
|
||||
namespace gamestate
|
||||
{
|
||||
namespace prefase
|
||||
{
|
||||
draw::surface *fondo = nullptr;
|
||||
draw::surface *cursor = nullptr;
|
||||
draw::surface *font = nullptr;
|
||||
|
||||
uint8_t num_arounders = 0;
|
||||
uint8_t arounders_necessaris = 0;
|
||||
uint8_t fase = 0;
|
||||
|
||||
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;
|
||||
fase = game::getConfig("fase")+1;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,8 @@ namespace gamestate
|
||||
|
||||
void drawPic(std::string filename)
|
||||
{
|
||||
draw::surface *pic = draw::loadSurface(filename);
|
||||
draw::surface *pic = draw::loadSurface(filename, true);
|
||||
draw::setSource(pic);
|
||||
draw::loadPalette(filename);
|
||||
draw::draw(0, 0, 320, 200, 0, 0);
|
||||
draw::freeSurface(pic);
|
||||
}
|
||||
@@ -90,7 +89,13 @@ namespace gamestate
|
||||
}
|
||||
}
|
||||
if (num_diapositives==0) {
|
||||
gamestate::menu::init();
|
||||
const int fase = game::getConfig("fase");
|
||||
if ( fase == -1 || fase == 30) {
|
||||
gamestate::menu::init();
|
||||
} else {
|
||||
gamestate::prefase::init();
|
||||
}
|
||||
|
||||
free(sfpointer);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,7 @@
|
||||
|
||||
namespace gamestate
|
||||
{
|
||||
namespace sequence
|
||||
{
|
||||
void init();
|
||||
}
|
||||
|
||||
namespace menu
|
||||
{
|
||||
void init();
|
||||
}
|
||||
namespace sequence { void init(); }
|
||||
namespace menu { void init(); }
|
||||
namespace prefase { void init(); }
|
||||
}
|
||||
|
||||
@@ -334,7 +334,8 @@ unsigned char* process_image_descriptor( unsigned char* buffer,
|
||||
*/
|
||||
#define rb (*(buffer++))
|
||||
|
||||
uint32_t* LoadPalette(unsigned char *buffer) {
|
||||
uint32_t* LoadPalette(unsigned char *b, int *paletteSize = NULL) {
|
||||
unsigned char *buffer = b;
|
||||
unsigned char header[7];
|
||||
screen_descriptor_t screen_descriptor;
|
||||
//int color_resolution_bits;
|
||||
@@ -346,12 +347,12 @@ uint32_t* LoadPalette(unsigned char *buffer) {
|
||||
READ(&screen_descriptor, 7);
|
||||
|
||||
//color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
|
||||
global_color_table = (uint32_t *)calloc(1, 1024);
|
||||
//global_color_table = (uint32_t *)calloc(1, 1024);
|
||||
|
||||
if (screen_descriptor.fields & 0x80) {
|
||||
global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
|
||||
|
||||
//global_color_table = (rgb *)malloc(3 * global_color_table_size);
|
||||
if (paletteSize != NULL) *paletteSize = global_color_table_size;
|
||||
global_color_table = (uint32_t *)malloc(3 * global_color_table_size);
|
||||
//READ(global_color_table, 3 * global_color_table_size);
|
||||
for (int i=0; i<global_color_table_size;++i) {
|
||||
global_color_table[i] = (buffer[0]<<16) + (buffer[1]<<8) + buffer[2];
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace draw
|
||||
}
|
||||
|
||||
// Carrega un gràfic d'un arxiu (en format GIF) a una nova superficie, i torna un punter a ella
|
||||
surface *loadSurface(const std::string &filename)
|
||||
surface *loadSurface(const std::string &filename, const bool loadPalette)
|
||||
{
|
||||
// Agafem un buffer de bytes de l'arxiu especificat
|
||||
// getFileBuffer() simplement ens torna el arxiu sencer dins de un array de char
|
||||
@@ -131,6 +131,22 @@ namespace draw
|
||||
// però, ojo, sí que tindrem que alliberar-la.
|
||||
surf->pixels = LoadGif(buffer, &surf->w, &surf->h);
|
||||
|
||||
// Si li havem dit que carregue també la paleta...
|
||||
if (loadPalette)
|
||||
{
|
||||
// Li passem el array del arxiu a LoadPalette. Ell ens torna un array de uint32_t amb la paleta
|
||||
// Van a ser com a molt 256 entrades de 32 bits (pero no sempre), cada entrada es un color, amb el format 0xAARRGGBB
|
||||
int paletteSize;
|
||||
uint32_t *pal = LoadPalette(buffer, &paletteSize);
|
||||
|
||||
// Copiem eixe array al nostre array de la paleta de sistema. Ara ja tenim la paleta carregada.
|
||||
memset(palette, 0, 1024); // Fiquem tot a 0, que la paleta potser no es de 256 i quedaria basura
|
||||
memcpy(palette, pal, paletteSize*4); // 32 bits per entrada == 4 bytes x 'paletteSize' entrades
|
||||
|
||||
// Alliberem el array que ens habia tornat LoadPalette()
|
||||
free(pal);
|
||||
}
|
||||
|
||||
// Com ja no ens fa falta, alliberem la memòria del buffer del arxiu
|
||||
free(buffer);
|
||||
|
||||
@@ -205,8 +221,8 @@ namespace draw
|
||||
return y - viewport.y;
|
||||
}
|
||||
|
||||
// Estableix la paleta del sistema carregant-la d'un GIF
|
||||
void loadPalette(const std::string &filename)
|
||||
// Carrega la paleta d'un GIF i la torna en un array de uint32_t
|
||||
uint32_t *loadPalette(const std::string &filename, int *paletteSize)
|
||||
{
|
||||
// Agafem un buffer de bytes de l'arxiu especificat
|
||||
// getFileBuffer() simplement ens torna el arxiu sencer dins de un array de char
|
||||
@@ -217,14 +233,20 @@ namespace draw
|
||||
// Van a ser 256 entrades de 32 bits, cada entrada es un color, amb el format 0xAARRGGBB
|
||||
uint32_t *pal = LoadPalette(buffer);
|
||||
|
||||
// Copiem eixe array al nostre array de la paleta de sistema. Ara ja tenim la paleta carregada.
|
||||
memcpy(palette, pal, 1024); // 32 bits per entrada == 4 bytes x 256 entrades == 1024
|
||||
|
||||
// Alliberem el array que ens habia tornat LoadPalette()
|
||||
free(pal);
|
||||
|
||||
// I també el buffer del arxiu
|
||||
free(buffer);
|
||||
|
||||
if (paletteSize) *paletteSize = size;
|
||||
return pal;
|
||||
}
|
||||
|
||||
// Estableix la paleta del sistema, o part de ella, des d'un array especificat
|
||||
void setPalette(const uint32_t *pal, const int len, const int pos)
|
||||
{
|
||||
for (int i=0; i<len; ++i)
|
||||
{
|
||||
palette[i+pos] = pal[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Estableix una entrada de la paleta del sistema
|
||||
|
||||
@@ -39,8 +39,9 @@ namespace draw
|
||||
|
||||
/// @brief Carrega un gràfic d'un arxiu (en format GIF) a una nova superficie, i torna un punter a ella
|
||||
/// @param filename nom de l'arxiu GIF d'on carregar la superficie
|
||||
/// @param loadPalette si es true també se carrega la paleta del GIF
|
||||
/// @return un punter a una nova superficie
|
||||
surface *loadSurface(const std::string &filename);
|
||||
surface *loadSurface(const std::string &filename, const bool loadPalette = false);
|
||||
|
||||
/// @brief Allibera la memòria d'una superficie, els seus pixels inclosos
|
||||
/// @param surf punter a la superficie a alliberar
|
||||
@@ -63,9 +64,16 @@ namespace draw
|
||||
const int getLocalX(const int x);
|
||||
const int getLocalY(const int y);
|
||||
|
||||
/// @brief Estableix la paleta del sistema carregant-la d'un GIF
|
||||
/// @brief Carrega la paleta d'un GIF i la torna en un array de uint32_t
|
||||
/// @param filename nom de l'arxiu GIF d'on carregar la paleta
|
||||
void loadPalette(const std::string &filename);
|
||||
/// @param paletteSize si no es NULL ens torna el tamany de la paleta carregada
|
||||
uint32_t *loadPalette(const std::string &filename, int *paletteSize = nullptr);
|
||||
|
||||
/// @brief Estableix la paleta del sistema, o part de ella, des d'un array especificat
|
||||
/// @param pal un array de uint32_t
|
||||
/// @param len quantes entrades volem trasladar a la paleta de sistema (no superar el tamany de 'pal'!)
|
||||
/// @param pos des de quina posició de la paleta de sistema comencem a copiar
|
||||
void setPalette(const uint32_t *pal, const int len, const int pos=0);
|
||||
|
||||
/// @brief Estableix una entrada de la paleta del sistema
|
||||
/// @param index l'index de l'entrada de la paleta
|
||||
|
||||
Reference in New Issue
Block a user