From 4133dfd7c96d1adc12d918d868a43346f6b2f5b3 Mon Sep 17 00:00:00 2001 From: Sergio Valor Martinez Date: Thu, 27 Oct 2022 11:49:47 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20el=20cambio=20de=20borde,=20tama?= =?UTF-8?q?=C3=B1o=20de=20ventana=20y=20paleta=20a=20todas=20las=20seccion?= =?UTF-8?q?es=20del=20juego?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/credits.cpp | 112 ++++++++++++++++++++++++++++++------------ source/credits.h | 3 ++ source/demo.cpp | 45 ++++++++++++++--- source/demo.h | 3 ++ source/director.cpp | 2 +- source/game.cpp | 7 ++- source/intro.cpp | 17 ++++--- source/logo.cpp | 6 ++- source/scoreboard.cpp | 4 ++ source/scoreboard.h | 5 +- source/title.cpp | 15 +++--- 11 files changed, 162 insertions(+), 57 deletions(-) diff --git a/source/credits.cpp b/source/credits.cpp index 00b649a..4d8ab3d 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -29,35 +29,6 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass // Cambia el color del borde screen->setBorderColor(stringToColor(options->palette, "black")); - // Inicializa los textos - texts.push_back({"", stringToColor(options->palette, "white")}); - texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - texts.push_back({"HELP JAILDOC TO GET BACK ALL HIS", stringToColor(options->palette, "white")}); - texts.push_back({"PROJECTS AND GO TO THE JAIL TO", stringToColor(options->palette, "white")}); - texts.push_back({"FINISH THEM", stringToColor(options->palette, "white")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - - texts.push_back({"KEYS:", stringToColor(options->palette, "yellow")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - texts.push_back({"USE 'CURSORS' TO MOVE AND JUMP", stringToColor(options->palette, "white")}); - texts.push_back({"'F1-F4' TO CHANGE WINDOWS SIZE", stringToColor(options->palette, "white")}); - texts.push_back({"'F' TO SWITCH TO FULLSCREEN", stringToColor(options->palette, "white")}); - texts.push_back({"'B' TO SWITCH THE BORDER SCREEN", stringToColor(options->palette, "white")}); - texts.push_back({"'M' TO TURN ON/OFF THE MUSIC", stringToColor(options->palette, "white")}); - texts.push_back({"'ESC' TO LEAVE THE GAME", stringToColor(options->palette, "white")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - - texts.push_back({"A GAME BY JAILDESIGNER", stringToColor(options->palette, "yellow")}); - texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options->palette, "yellow")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - - texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")}); - texts.push_back({"", stringToColor(options->palette, "white")}); - // Crea la textura para el texto que se escribe en pantalla textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); if (textTexture == nullptr) @@ -101,8 +72,8 @@ void Credits::checkEventHandler() break; } - // Comprueba si se ha pulsado alguna tecla - else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) + // Comprueba las teclas que se han pulsado + if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { switch (eventHandler->key.keysym.scancode) { @@ -110,6 +81,40 @@ void Credits::checkEventHandler() section.name = SECTION_PROG_QUIT; break; + case SDL_SCANCODE_B: + screen->switchBorder(); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F: + screen->switchVideoMode(); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F1: + screen->setWindowSize(1); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F2: + screen->setWindowSize(2); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F3: + screen->setWindowSize(3); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F4: + screen->setWindowSize(4); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F5: + switchPalette(); + break; + default: section.name = SECTION_PROG_TITLE; section.subsection = 0; @@ -122,6 +127,36 @@ void Credits::checkEventHandler() // Escribe el texto en la textura void Credits::fillTexture() { + // Inicializa los textos + texts.clear(); + texts.push_back({"", stringToColor(options->palette, "white")}); + texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + texts.push_back({"HELP JAILDOC TO GET BACK ALL HIS", stringToColor(options->palette, "white")}); + texts.push_back({"PROJECTS AND GO TO THE JAIL TO", stringToColor(options->palette, "white")}); + texts.push_back({"FINISH THEM", stringToColor(options->palette, "white")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + + texts.push_back({"KEYS:", stringToColor(options->palette, "yellow")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + texts.push_back({"USE 'CURSORS' TO MOVE AND JUMP", stringToColor(options->palette, "white")}); + texts.push_back({"'F1-F4' TO CHANGE WINDOWS SIZE", stringToColor(options->palette, "white")}); + texts.push_back({"'F' TO SWITCH TO FULLSCREEN", stringToColor(options->palette, "white")}); + texts.push_back({"'B' TO SWITCH THE BORDER SCREEN", stringToColor(options->palette, "white")}); + texts.push_back({"'M' TO TURN ON/OFF THE MUSIC", stringToColor(options->palette, "white")}); + texts.push_back({"'ESC' TO LEAVE THE GAME", stringToColor(options->palette, "white")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + + texts.push_back({"A GAME BY JAILDESIGNER", stringToColor(options->palette, "yellow")}); + texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options->palette, "yellow")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + + texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")}); + texts.push_back({"", stringToColor(options->palette, "white")}); + // Rellena la textura de texto SDL_SetRenderTarget(renderer, textTexture); const color_t c = stringToColor(options->palette, "black"); @@ -266,4 +301,19 @@ section_t Credits::run() } return section; +} + +// Cambia la paleta +void Credits::switchPalette() +{ + if (options->palette == p_zxspectrum) + { + options->palette = p_zxarne; + } + else + { + options->palette = p_zxspectrum; + } + + fillTexture(); } \ No newline at end of file diff --git a/source/credits.h b/source/credits.h index b675b69..d12ecc7 100644 --- a/source/credits.h +++ b/source/credits.h @@ -62,6 +62,9 @@ private: // Escribe el texto en la textura void fillTexture(); + // Cambia la paleta + void switchPalette(); + public: // Constructor Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); diff --git a/source/demo.cpp b/source/demo.cpp index a0a49c8..81af86f 100644 --- a/source/demo.cpp +++ b/source/demo.cpp @@ -68,42 +68,53 @@ void Demo::checkEventHandler() screen->setBorderColor(stringToColor(options->palette, "black")); break; } - else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) + + // Comprueba las teclas que se han pulsado + if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { switch (eventHandler->key.keysym.scancode) { + case SDL_SCANCODE_ESCAPE: + section.name = SECTION_PROG_QUIT; + break; + case SDL_SCANCODE_B: screen->switchBorder(); - reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F: screen->switchVideoMode(); - reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F1: screen->setWindowSize(1); - reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F2: screen->setWindowSize(2); - reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F3: screen->setWindowSize(3); - reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F4: screen->setWindowSize(4); - reLoadTextures(); + resource->reLoadTextures(); + break; + + case SDL_SCANCODE_F5: + switchPalette(); break; default: section.name = SECTION_PROG_TITLE; + section.subsection = 0; break; } } @@ -180,6 +191,26 @@ void Demo::reLoadTextures() text->reLoadTexture(); } +// Cambia la paleta +void Demo::switchPalette() +{ + // Modifica la variable + if (options->palette == p_zxspectrum) + { + options->palette = p_zxarne; + } + else + { + options->palette = p_zxspectrum; + } + + room->reLoadPalette(); + scoreboard->reLoadPalette(); + + const color_t c = room->getBorderColor(); + board.color = (c.r + c.g + c.b == 0) ? stringToColor(options->palette, "white") : c; // Si el color es negro lo cambia a blanco +} + // Cambia de habitación bool Demo::changeRoom(std::string file) { diff --git a/source/demo.h b/source/demo.h index 70d9e65..a835730 100644 --- a/source/demo.h +++ b/source/demo.h @@ -60,6 +60,9 @@ private: // Recarga todas las texturas void reLoadTextures(); + // Cambia la paleta + void switchPalette(); + // Cambia de habitación bool changeRoom(std::string file); diff --git a/source/director.cpp b/source/director.cpp index 945009f..981e91e 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -9,7 +9,7 @@ Director::Director(std::string path) section.name = SECTION_PROG_LOGO; section.subsection = SUBSECTION_LOGO_TO_INTRO; - section.name = SECTION_PROG_TITLE; + section.name = SECTION_PROG_LOGO; // Crea el objeto que controla los ficheros de recursos asset = new Asset(path.substr(0, path.find_last_of("\\/"))); diff --git a/source/game.cpp b/source/game.cpp index baedbb9..41f81ad 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -87,7 +87,8 @@ void Game::checkEventHandler() screen->setBorderColor(stringToColor(options->palette, "black")); break; } - else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) + + if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) { switch (eventHandler->key.keysym.scancode) { @@ -420,6 +421,10 @@ void Game::switchPalette() room->reLoadPalette(); player->reLoadPalette(); + scoreboard->reLoadPalette(); + + const color_t c = room->getBorderColor(); + board.color = (c.r + c.g + c.b == 0) ? stringToColor(options->palette, "white") : c; // Si el color es negro lo cambia a blanco } // Establece la pantalla en negro diff --git a/source/intro.cpp b/source/intro.cpp index f73ee45..a1396a4 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -94,11 +94,15 @@ void Intro::checkEventHandler() break; } - // Cualquier tecla pulsada - if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) + // Comprueba las teclas que se han pulsado + if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { switch (eventHandler->key.keysym.scancode) { + case SDL_SCANCODE_ESCAPE: + section.name = SECTION_PROG_QUIT; + break; + case SDL_SCANCODE_B: screen->switchBorder(); resource->reLoadTextures(); @@ -135,6 +139,7 @@ void Intro::checkEventHandler() default: section.name = SECTION_PROG_TITLE; + section.subsection = 0; break; } } @@ -293,13 +298,13 @@ void Intro::switchPalette() if (options->palette == p_zxspectrum) { options->palette = p_zxarne; - loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png"); - loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png"); + sprite1->setTexture(resource->getTexture("loading_screen_bn_zxarne.png")); + sprite2->setTexture(resource->getTexture("loading_screen_color_zxarne.png")); } else { options->palette = p_zxspectrum; - loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png"); - loadingScreenTexture2 = resource->getTexture("loading_screen_color.png"); + sprite1->setTexture(resource->getTexture("loading_screen_bn.png")); + sprite2->setTexture(resource->getTexture("loading_screen_color.png")); } } \ No newline at end of file diff --git a/source/logo.cpp b/source/logo.cpp index 35a075a..ce78c9f 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,4 +1,5 @@ #include "logo.h" +#include // Constructor Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection) @@ -78,12 +79,13 @@ void Logo::checkEventHandler() break; } - // Cualquier tecla pulsada - if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) + // Comprueba las teclas que se han pulsado + if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { switch (eventHandler->key.keysym.scancode) { case SDL_SCANCODE_ESCAPE: + std::cout << "PULSADO ESCAPE" << std::endl; section.name = SECTION_PROG_QUIT; break; diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 6692940..0f2670c 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -120,7 +120,11 @@ void ScoreBoard::reLoadTexture() playerTexture->reLoad(); itemTexture->reLoad(); text->reLoadTexture(); +} +// Recarga la paleta +void ScoreBoard::reLoadPalette() +{ // Reinicia el vector de colores const std::vector vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"}; color.clear(); diff --git a/source/scoreboard.h b/source/scoreboard.h index 1eef3f5..604e300 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -37,7 +37,7 @@ private: Texture *playerTexture; // Textura con los graficos para las vidas AnimatedSprite *sprite; // Sprite para mostrar las vidas en el marcador SDL_Renderer *renderer; // El renderizador de la ventana - Resource *resource; // Objeto con los recursos + Resource *resource; // Objeto con los recursos Asset *asset; // Objeto con la ruta a todos los ficheros de recursos Text *text; // Objeto para escribir texto Texture *itemTexture; // Textura con los graficos para las vidas @@ -72,6 +72,9 @@ public: // Recarga la textura void reLoadTexture(); + // Recarga la paleta + void reLoadPalette(); + // Pone el marcador en modo pausa void pause(); diff --git a/source/title.cpp b/source/title.cpp index 238f6e7..4708b7e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -66,8 +66,8 @@ void Title::checkEventHandler() break; } - // Comprueba si se ha pulsado alguna tecla - else if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0)) + // Comprueba las teclas que se han pulsado + if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { switch (eventHandler->key.keysym.scancode) { @@ -82,32 +82,31 @@ void Title::checkEventHandler() case SDL_SCANCODE_F: screen->switchVideoMode(); - //reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F1: screen->setWindowSize(1); - //reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F2: screen->setWindowSize(2); - //reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F3: screen->setWindowSize(3); - //reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F4: screen->setWindowSize(4); - //reLoadTextures(); + resource->reLoadTextures(); break; case SDL_SCANCODE_F5: switchPalette(); - // reLoadTextures(); break; default: