Compare commits
2 Commits
f9d2ac66e8
...
98138344e6
| Author | SHA1 | Date | |
|---|---|---|---|
| 98138344e6 | |||
| 6472845333 |
@@ -9,6 +9,13 @@ namespace gamestate
|
||||
{
|
||||
namespace play
|
||||
{
|
||||
namespace eixir
|
||||
{
|
||||
const int no = 0;
|
||||
const int postfase = 1;
|
||||
const int mort = 2;
|
||||
}
|
||||
|
||||
draw::surface *faded = nullptr;
|
||||
draw::surface *fondo = nullptr;
|
||||
draw::surface *cursor = nullptr;
|
||||
@@ -39,61 +46,77 @@ namespace gamestate
|
||||
|
||||
void init()
|
||||
{
|
||||
play::exit = 0;
|
||||
// Ara comença tot, per tant no volem eixir
|
||||
play::exit = play::eixir::no;
|
||||
|
||||
const int fase = game::getConfig("fase");
|
||||
// Carregar el fondo que toque i la seua paleta (que nomes usa els colors del 128 al 255)
|
||||
char arxiuFondo[10] = "BKG00.GIF";
|
||||
arxiuFondo[4] = (fase % 10) + 48;
|
||||
arxiuFondo[4] = (game::getConfig("fase") % 10) + 48;
|
||||
play::fondo = draw::loadSurface(arxiuFondo, true);
|
||||
|
||||
// Carregar la paleta estandar
|
||||
// Carregar la paleta estandar (colors del 0 al 128)
|
||||
uint32_t *pal = draw::loadPalette("tiles.gif");
|
||||
draw::setPalette(pal, 128);
|
||||
free(pal);
|
||||
|
||||
// Carregar els gifs auxiliars i crear la superficie per al fondo de la pausa i el menu
|
||||
play::cursor = draw::loadSurface("cursor.gif");
|
||||
play::aigua = draw::loadSurface("aigua.gif");
|
||||
play::faded = draw::createSurface(320, 200);
|
||||
|
||||
// [TODO] CREAR MARCADOR PROCESSOR
|
||||
|
||||
// [TODO] Crear el primer Arounder
|
||||
mapa::arounders::eixits++;
|
||||
// REALMENT NO. PREFEREIXC QUE PASEN UNS SEGONS ABANS QUE ARRIBE EL PRIMER
|
||||
// mapa::arounders::eixits++;
|
||||
// arounder_seleccionat = primerArounders
|
||||
|
||||
audio::loadMusic((fase+1) % 5 == 0 ? "mus6.ogg" : "mus4.ogg");
|
||||
// Enxufa el arradio
|
||||
audio::loadMusic((game::getConfig("fase")+1) % 5 == 0 ? "mus6.ogg" : "mus4.ogg");
|
||||
audio::playMusic();
|
||||
|
||||
// Fiquem a contar el cronómetre de arounders
|
||||
play::arounderCount = play::startTicks = game::getTicks();
|
||||
|
||||
// Fade in i anem al bucle principal
|
||||
draw::fadein();
|
||||
game::setState(gamestate::play::loop);
|
||||
}
|
||||
|
||||
bool loop()
|
||||
{
|
||||
// Si ja s'ha demanat l'eixida...
|
||||
if (play::exit) {
|
||||
// I si ja s'ha acabat el fadeout...
|
||||
if (!draw::isfading()) {
|
||||
// Alliberem memòria
|
||||
play::finalize();
|
||||
if (exit==1) gamestate::postfase::init();
|
||||
// [TODO] if (exit==2) gamestate::mort::init();
|
||||
|
||||
// I anem on toque
|
||||
if (play::exit==play::eixir::postfase) gamestate::postfase::init();
|
||||
// [TODO] else if (play::exit==play::eixir::mort) gamestate::mort::init();
|
||||
}
|
||||
// En qualsevol cas, renderitzem i eixim ja del bucle (fins que acabe el fadeout)
|
||||
draw::render();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Pintar tot menys el cursor
|
||||
play::draw();
|
||||
|
||||
// Si se pulsa 'P', o el botó del mig del ratolí, o si la finestra perd el foco...
|
||||
if (input::keyPressed(SDL_SCANCODE_P) || input::mouseClk(input::mouse::button::middle) || !game::windowHasFocus)
|
||||
{
|
||||
arounderCount = game::getTicks() - arounderCount;
|
||||
// Parem el cronòmetre d'arounders
|
||||
play::arounderCount = game::getTicks() - play::arounderCount;
|
||||
|
||||
// Pintem el que hi ha a la pantalla en la surface "faded", li afegim el text "PAUSA" i aixó es tot el que pintarem fins eixir de la pausa
|
||||
draw::setSource(nullptr);
|
||||
draw::setDestination(play::faded);
|
||||
draw::draw();
|
||||
font::selectFont(font::type::fade);
|
||||
font::print(136, 80, "PAUSA");
|
||||
draw::setDestination(nullptr);
|
||||
|
||||
// Reduïm tots els colors de la paleta (menys els epecials) a la meitat del seu color
|
||||
play::original_palette = draw::getPalette();
|
||||
for (int i=0; i<256; ++i) if ( i!=61 && i!= 62 && (i<68 || i >75) )
|
||||
{
|
||||
@@ -103,25 +126,34 @@ namespace gamestate
|
||||
uint8_t b = p & 0xff;
|
||||
draw::setPaletteEntry(i, r >> 1, g >> 1, b >> 1);
|
||||
}
|
||||
|
||||
// Canviem el bucle principal a "loop_pausa()"
|
||||
game::setState(gamestate::play::loop_pause);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Si se pulsa ESC...
|
||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
|
||||
{
|
||||
arounderCount = game::getTicks() - arounderCount;
|
||||
// Parem el cronòmetre d'arounders
|
||||
play::arounderCount = game::getTicks() - play::arounderCount;
|
||||
|
||||
// Pintem el que hi ha a la pantalla en la surface "faded", li afegim el menú i aixó es tot el que pintarem fins eixir del menú
|
||||
draw::setSource(nullptr);
|
||||
draw::setDestination(play::faded);
|
||||
draw::draw();
|
||||
draw::surface *menu = draw::loadSurface("menu.gif");
|
||||
draw::setSource(menu);
|
||||
draw::draw(97, 52);
|
||||
draw::freeSurface(menu);
|
||||
font::selectFont(font::type::fade);
|
||||
font::print(129, 60, "CONTINUAR");
|
||||
font::print(129, 71, "REINICIAR");
|
||||
font::print(112, 82, "MENU PRINCIPAL");
|
||||
font::print(143, 93, "EIXIR");
|
||||
draw::setDestination(nullptr);
|
||||
|
||||
// Reduïm tots els colors de la paleta (menys els epecials) a la meitat del seu color
|
||||
play::original_palette = draw::getPalette();
|
||||
for (int i=0; i<256; ++i) if ( i!=61 && i!= 62 && (i<68 || i >75) )
|
||||
{
|
||||
@@ -131,14 +163,19 @@ namespace gamestate
|
||||
uint8_t b = p & 0xff;
|
||||
draw::setPaletteEntry(i, r >> 1, g >> 1, b >> 1);
|
||||
}
|
||||
|
||||
// Canviem el bucle principal a "loop_menu()"
|
||||
game::setState(gamestate::play::loop_menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Ara ja, pintem el cursor i enviem tot a pantalla
|
||||
// No ho havem fet abans perque en el fondo de la pausa o el menú no volem que aparega el cursor
|
||||
draw::setSource(cursor);
|
||||
draw::draw(input::mouseX(), input::mouseY());
|
||||
draw::render();
|
||||
|
||||
// Si pulsem el botó de la dreta, el arounder seleccionat deixa de fer l'acció que està fent
|
||||
if (input::mouseClk(input::mouse::button::right))
|
||||
{
|
||||
// [TODO] arounders::abortarAccio();
|
||||
|
||||
@@ -225,8 +225,7 @@ namespace file
|
||||
// Si no trobem el recurs, petem el mame
|
||||
if (!found)
|
||||
{
|
||||
// [TODO] Donar mes informació de quin recurs no havem trobat
|
||||
perror("El recurs no s'ha trobat en l'arxiu de recursos");
|
||||
printf("ERROR FATAL: No s'ha trobat el recurs '%s' a l'arxiu de recursos '%s'\n", resourcename.c_str(), resource_filename.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -237,8 +236,7 @@ namespace file
|
||||
f.open(resource_filename.c_str(), binary ? std::ios::binary : std::ios::in);
|
||||
if (!f.is_open()) // En el raruno cas de que a este altures pete al obrir el arxiu de recursos, petem el mame
|
||||
{
|
||||
// [TODO] Donar mes informació de quin recurs no havem trobat
|
||||
perror("No s'ha pogut obrir l'arxiu de recursos");
|
||||
printf("ERROR FATAL: No s'ha pogut obrir l'arxiu de recursos '%s'\n", resource_filename.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -251,6 +249,11 @@ namespace file
|
||||
{
|
||||
// Si estem pillant els recursos de carpeta, simplement obrim el arxiu en questió i tornem el FILE* associat.
|
||||
f.open((resource_folder + resourcename), binary ? std::ios::binary : std::ios::in);
|
||||
if (f.rdstate() & std::ios_base::failbit)
|
||||
{
|
||||
printf("ERROR FATAL: No s'ha pogut obrir l'arxiu '%s/%s'\n", resource_folder.c_str(), resourcename.c_str());
|
||||
exit(1);
|
||||
}
|
||||
f.seekg(0, std::ios_base::end);
|
||||
if (filesize) *filesize = f.tellg();
|
||||
f.seekg(0, std::ios_base::beg);
|
||||
@@ -293,8 +296,7 @@ namespace file
|
||||
// Si no trobem el recurs, petem el mame
|
||||
if (!found)
|
||||
{
|
||||
// [TODO] Donar mes informació de quin recurs no havem trobat
|
||||
perror("El recurs no s'ha trobat en l'arxiu de recursos");
|
||||
printf("ERROR FATAL: No s'ha trobat el recurs '%s' a l'arxiu de recursos '%s'\n", resourcename.c_str(), resource_filename.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -305,8 +307,7 @@ namespace file
|
||||
f = fopen(resource_filename.c_str(), binary ? "rb" : "r");
|
||||
if (!f) // En el raruno cas de que a este altures pete al obrir el arxiu de recursos, petem el mame
|
||||
{
|
||||
// [TODO] Donar mes informació de quin recurs no havem trobat
|
||||
perror("No s'ha pogut obrir l'arxiu de recursos");
|
||||
printf("ERROR FATAL: No s'ha pogut obrir l'arxiu de recursos '%s'\n", resource_filename.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -319,6 +320,12 @@ namespace file
|
||||
{
|
||||
// Si estem pillant els recursos de carpeta, simplement obrim el arxiu en questió i tornem el FILE* associat.
|
||||
f = fopen((resource_folder + resourcename).c_str(), binary ? "rb" : "r");
|
||||
if(!f)
|
||||
{
|
||||
printf("ERROR FATAL: No s'ha pogut obrir l'arxiu '%s/%s'\n", resource_folder.c_str(), resourcename.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
if (filesize) *filesize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
Reference in New Issue
Block a user