From 5d89a3057e39f8f472f4355b8754de4004faf1ad Mon Sep 17 00:00:00 2001 From: Sergio Valor Martinez Date: Wed, 30 Nov 2022 13:43:47 +0100 Subject: [PATCH] Optimizado un poco el title.cpp --- source/common/sprite.cpp | 8 ++++---- source/director.cpp | 2 +- source/title.cpp | 25 ++++++++++++++++++------- source/title.h | 4 ++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/source/common/sprite.cpp b/source/common/sprite.cpp index 8888074..5654a5a 100644 --- a/source/common/sprite.cpp +++ b/source/common/sprite.cpp @@ -27,12 +27,12 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *rende Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer) { // Establece la posición X,Y del sprite - x = rect.x; - y = rect.y; + this->x = rect.x; + this->y = rect.y; // Establece el alto y el ancho del sprite - w = rect.w; - h = rect.h; + this->w = rect.w; + this->h = rect.h; // Establece el puntero al renderizador de la ventana this->renderer = renderer; diff --git a/source/director.cpp b/source/director.cpp index 0c62e77..ec497de 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -18,7 +18,7 @@ Director::Director(int argc, char *argv[]) section.subsection = SUBSECTION_LOGO_TO_INTRO; #ifdef DEBUG - section.name = SECTION_PROG_INTRO; + section.name = SECTION_PROG_LOGO; #endif // Crea e inicializa las opciones del programa diff --git a/source/title.cpp b/source/title.cpp index 3de7a57..64851b5 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -30,7 +30,6 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset * ticks = 0; ticksSpeed = 15; longText = "HEY JAILERS!! IT'S 2022 AND WE'RE STILL ROCKING LIKE IT'S 1998!!! HAVE YOU HEARD IT? JAILGAMES ARE BACK!! YEEESSS BACK!! MORE THAN 10 TITLES ON JAILDOC'S KITCHEN!! THATS A LOOOOOOT OF JAILGAMES, BUT WHICH ONE WILL STRIKE FIRST? THERE IS ALSO A NEW DEVICE TO COME THAT WILL BLOW YOUR MIND WITH JAILGAMES ON THE GO: P.A.C.O. BUT WAIT! WHAT'S THAT BEAUTY I'M SEEING RIGHT OVER THERE?? OOOH THAT TINY MINIASCII IS PURE LOVE!! I WANT TO LICK EVERY BYTE OF IT!! OH SHIT! AND DON'T FORGET TO BRING BACK THOSE OLD AND FAT MS-DOS JAILGAMES TO GITHUB TO KEEP THEM ALIVE!! WHAT WILL BE THE NEXT JAILDOC RELEASE? WHAT WILL BE THE NEXT PROJECT TO COME ALIVE?? OH BABY WE DON'T KNOW BUT HERE YOU CAN FIND THE ANSWER, YOU JUST HAVE TO COMPLETE JAILDOCTOR'S DILEMMA ... COULD YOU?"; - // longText = "HEY JAILERS!! IT'S 2022 AND WE'RE STILL ROCKING LIKE IT'S 1998!!!"; for (int i = 0; i < (int)longText.length(); ++i) { letter_t l; @@ -42,6 +41,21 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset * letters[0].enabled = true; marqueeSpeed = 3; + // Crea el cartel de PRESS ENTER + const std::string caption = "PRESS ENTER TO PLAY"; + const color_t textColor = stringToColor(options->palette, "white"); + const color_t strokeColor = stringToColor(options->palette, "bright_blue"); + + // Crea la textura + pressEnterTexture = new Texture(renderer); + pressEnterTexture->createBlank(renderer, text->lenght(caption) + 2, text->getCharacterSize() + 2, SDL_TEXTUREACCESS_TARGET); + pressEnterTexture->setAsRenderTarget(renderer); + pressEnterTexture->setBlendMode(SDL_BLENDMODE_BLEND); + text->writeDX(TXT_COLOR | TXT_STROKE, 1, 1, caption, 1, textColor, 1, strokeColor); + + // Crea el sprite + pressEnterSprite = new Sprite(128 - (pressEnterTexture->getWidth() / 2), 192 / 5 * 4, pressEnterTexture->getWidth(), pressEnterTexture->getHeight(), pressEnterTexture, renderer); + // Cambia el color del borde screen->setBorderColor(stringToColor(options->palette, "bright_blue")); } @@ -51,6 +65,8 @@ Title::~Title() { delete eventHandler; delete sprite; + delete pressEnterSprite; + delete pressEnterTexture; delete text; } @@ -206,18 +222,13 @@ void Title::render() // Prepara para empezar a dibujar en la textura de juego screen->start(); - // Limpia la pantalla - screen->clean(); - // Dibuja el fondo del titulo sprite->render(); // Dibuja el texto de PRESS ENTER TO PLAY if (counter % 80 < 60) { - const color_t textColor = stringToColor(options->palette, "white"); - const color_t strokeColor = stringToColor(options->palette, "bright_blue"); - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE, 256 / 2, 192 / 5 * 4, "PRESS ENTER TO PLAY", 1, textColor, 1, strokeColor); + pressEnterSprite->render(); } // Dibuja la marquesina diff --git a/source/title.h b/source/title.h index 615faa4..6d891c5 100644 --- a/source/title.h +++ b/source/title.h @@ -34,8 +34,8 @@ private: Sprite *sprite; // Sprite para manejar la textura Text *text; // Objeto para escribir texto en pantalla options_t *options; // Puntero a las opciones del juego - //Texture *pressEnterTexture; // Textura con los graficos de PRESS ENTER - //Sprite *pressEnterSprite; // Sprite para manejar la textura de PRESS ENTER + Texture *pressEnterTexture; // Textura con los graficos de PRESS ENTER + Sprite *pressEnterSprite; // Sprite para manejar la textura de PRESS ENTER // Variables int counter; // Contador