From 98138344e62a32def6acdf6dc72d08b1c2b9cacd Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Fri, 20 Oct 2023 14:52:06 +0200 Subject: [PATCH] - Millors comentaris --- source/gamestate_play.cpp | 61 +++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/source/gamestate_play.cpp b/source/gamestate_play.cpp index db64a61..bd64755 100644 --- a/source/gamestate_play.cpp +++ b/source/gamestate_play.cpp @@ -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();