From e8a5c033bbd6ff0238812d6e76a6b6210cf29d65 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 12 Oct 2023 21:44:25 +0200 Subject: [PATCH] - Treballant en gamestate_prefase --- source/gamestate_menu.cpp | 3 +- source/gamestate_prefase.cpp | 111 ++++++++++++++++++++++++++++++++++ source/gamestate_sequence.cpp | 11 +++- source/gamestates.h | 12 +--- 4 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 source/gamestate_prefase.cpp diff --git a/source/gamestate_menu.cpp b/source/gamestate_menu.cpp index 9bcee3d..61fada7 100644 --- a/source/gamestate_menu.cpp +++ b/source/gamestate_menu.cpp @@ -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) { diff --git a/source/gamestate_prefase.cpp b/source/gamestate_prefase.cpp new file mode 100644 index 0000000..1759163 --- /dev/null +++ b/source/gamestate_prefase.cpp @@ -0,0 +1,111 @@ +#include "gamestates.h" +#include "jgame.h" +#include "jdraw.h" +#include "jaudio.h" +#include "jinput.h" +#include "jfile.h" +#include + +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;iw, 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); + } + } +} diff --git a/source/gamestate_sequence.cpp b/source/gamestate_sequence.cpp index 69175f6..6cb48e8 100644 --- a/source/gamestate_sequence.cpp +++ b/source/gamestate_sequence.cpp @@ -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; } diff --git a/source/gamestates.h b/source/gamestates.h index 894560a..bd10e23 100644 --- a/source/gamestates.h +++ b/source/gamestates.h @@ -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(); } }