From d391827fe1b7d897f5e8cf8d750c7f4ba9e5d203 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 19 Oct 2023 18:58:19 +0200 Subject: [PATCH] - Arreglat el pintat de l'aigua - Ja funciona la pausa i el menu de dins del joc --- source/gamestate_play.cpp | 163 +++++++++++++++++++++++++++++++++++--- 1 file changed, 152 insertions(+), 11 deletions(-) diff --git a/source/gamestate_play.cpp b/source/gamestate_play.cpp index 25097d5..7bcdd69 100644 --- a/source/gamestate_play.cpp +++ b/source/gamestate_play.cpp @@ -3,16 +3,19 @@ #include #include "aux_font.h" #include "proc_mapa.h" +#include namespace gamestate { namespace play { + draw::surface *faded = nullptr; draw::surface *fondo = nullptr; - draw::surface *mapa = nullptr; draw::surface *cursor = nullptr; draw::surface *aigua = nullptr; + uint32_t *original_palette = nullptr; + uint32_t arounderCount; uint32_t startTicks; uint32_t currentTicks; @@ -20,26 +23,36 @@ namespace gamestate int aigua_frame1 = 0; int aigua_frame2 = 5; + int exit = 0; + bool loop(); + + bool loop_pause(); + bool loop_menu(); + void draw(); void draw_aigua(); + void finalize(); + void init() { + play::exit = 0; + 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; - fondo = draw::loadSurface(arxiuFondo, true); + play::fondo = draw::loadSurface(arxiuFondo, true); // Carregar la paleta estandar uint32_t *pal = draw::loadPalette("tiles.gif"); draw::setPalette(pal, 128); + free(pal); - // [TODO] Carreagar la resta de gifs que facen falta - cursor = draw::loadSurface("cursor.gif"); - aigua = draw::loadSurface("aigua.gif"); - //menu = drawManager->LoadFont("menu.gif"); + play::cursor = draw::loadSurface("cursor.gif"); + play::aigua = draw::loadSurface("aigua.gif"); + play::faded = draw::createSurface(320, 200); // [TODO] CREAR AIGUA PROCESSOR // [TODO] CREAR MARCADOR PROCESSOR @@ -61,6 +74,59 @@ namespace gamestate { play::draw(); + if (input::keyPressed(SDL_SCANCODE_P) || input::mouseClk(2) || !game::windowHasFocus) + { + draw::setSource(nullptr); + draw::setDestination(play::faded); + draw::draw(); + font::selectFont(font::type::fade); + font::print(136, 80, "PAUSA"); + draw::setDestination(nullptr); + play::original_palette = draw::getPalette(); + for (int i=0; i<256; ++i) if ( i!=61 && i!= 62 && (i<68 || i >75) ) + { + uint32_t p = play::original_palette[i]; + uint8_t r = (p >> 16) & 0xff; + uint8_t g = (p >> 8) & 0xff; + uint8_t b = p & 0xff; + draw::setPaletteEntry(i, r >> 1, g >> 1, b >> 1); + } + game::setState(gamestate::play::loop_pause); + return true; + } + + if (input::keyPressed(SDL_SCANCODE_ESCAPE)) + { + draw::setSource(nullptr); + draw::setDestination(play::faded); + draw::draw(); + draw::surface *menu = draw::loadSurface("menu.gif"); + draw::setSource(menu); + draw::draw(97, 52); + 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); + play::original_palette = draw::getPalette(); + for (int i=0; i<256; ++i) if ( i!=61 && i!= 62 && (i<68 || i >75) ) + { + uint32_t p = play::original_palette[i]; + uint8_t r = (p >> 16) & 0xff; + uint8_t g = (p >> 8) & 0xff; + uint8_t b = p & 0xff; + draw::setPaletteEntry(i, r >> 1, g >> 1, b >> 1); + } + game::setState(gamestate::play::loop_menu); + return true; + } + + draw::setSource(cursor); + draw::draw(input::mouseX(), input::mouseY()); + + draw::render(); + currentTicks = game::getTicks() - startTicks; if( currentTicks >= mapa::velocitat ) { startTicks = game::getTicks(); @@ -71,6 +137,77 @@ namespace gamestate return true; } + bool loop_pause() + { + draw::draw(faded); + draw::setSource(cursor); + draw::draw(input::mouseX(), input::mouseY()); + + draw::render(); + + if (input::keyPressed(SDL_SCANCODE_P) || input::keyPressed(SDL_SCANCODE_ESCAPE)) + { + draw::setPalette(play::original_palette, 256); + free(play::original_palette); + game::setState(gamestate::play::loop); + } + return true; + } + + bool loop_menu() + { + if (play::exit) { + if (!draw::isfading()) { + play::finalize(); + if (exit==1) gamestate::play::init(); + if (exit==2) gamestate::menu::init(); + } + draw::render(); + return true; + } + + draw::draw(faded); + draw::setSource(cursor); + draw::draw(input::mouseX(), input::mouseY()); + + draw::render(); + + if (input::keyPressed(SDL_SCANCODE_ESCAPE)) + { + draw::setPalette(play::original_palette, 256); + free(play::original_palette); + game::setState(gamestate::play::loop); + } + + if (input::mouseClk(1)) + { + if (input::mouseX() >= 97 && input::mouseX() <= 223) { + if (input::mouseY() >= 60 && input::mouseY() <= 65) { + draw::setPalette(play::original_palette, 256); + free(play::original_palette); + game::setState(gamestate::play::loop); + } + if (input::mouseY() >= 71 && input::mouseY() <= 76) { + free(play::original_palette); + draw::fadeout(); + audio::fadeoutMusic(); + play::exit = 1; + } + if (input::mouseY() >= 82 && input::mouseY() <= 87) { + free(play::original_palette); + draw::fadeout(); + audio::fadeoutMusic(); + play::exit = 2; + } + if (input::mouseY() >= 93 && input::mouseY() <= 98) { + return false; + } + } + + } + return true; + } + void draw() { draw::draw(play::fondo); @@ -81,7 +218,7 @@ namespace gamestate // [QUESTION] Potser lo del seleccionat se deuria mirar dins de "mapa"? mapa::pintar(accio, prevista); // [TODO] if (arounders::seleccionat) existeix, pillar la accio i la prevista de ell - void draw_aigua(); + draw_aigua(); // [TODO] arounders::pintar(); // [TODO] de fet, pintar la marca en el modul "arounders" @@ -92,10 +229,6 @@ namespace gamestate } */ - draw::setSource(cursor); - draw::draw(input::mouseX(), input::mouseY()); - - draw::render(); } void draw_aigua() @@ -111,5 +244,13 @@ namespace gamestate draw::draw(16+i*32, 150, 16, 15, frames[aigua_frame2]*16, 0); } } + + void finalize() + { + draw::freeSurface(faded); + draw::freeSurface(fondo); + draw::freeSurface(cursor); + draw::freeSurface(aigua); + } } } \ No newline at end of file