From db719245a3f66530a46e164be51dc2414e701d11 Mon Sep 17 00:00:00 2001 From: Sergio Valor Martinez Date: Mon, 24 Oct 2022 13:17:21 +0200 Subject: [PATCH] Ya escribe los creditos con colores --- source/credits.cpp | 50 +++++++++++++++++++++---------------------- source/credits.h | 9 ++++---- source/scoreboard.cpp | 7 +++--- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/source/credits.cpp b/source/credits.cpp index 7a069a7..ab3d2e0 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -23,30 +23,30 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Asset *asset) screen->setBorderColor(stringToColor("black")); // Inicializa los textos - texts.push_back(""); - texts.push_back("INSTRUCTIONS:"); - texts.push_back(""); - texts.push_back("HELP JAILDOC TO GET BACK ALL HIS"); - texts.push_back("PROJECTS AND GO TO THE JAIL TO"); - texts.push_back("FINISH THEM"); - texts.push_back(""); - texts.push_back(""); - texts.push_back("KEYS:"); - texts.push_back(""); - texts.push_back("USE CURSORS TO MOVE AND JUMP"); - texts.push_back("F1-F4 TO CHANGE WINDOWS SIZE"); - texts.push_back("F TO SWITCH TO FULLSCREEN"); - texts.push_back("B TO DE/ACTIVATE THE BORDER SC."); - texts.push_back("M TO TURN ON/OFF THE MUSIC"); - texts.push_back("ESC TO EXIT GAME"); - texts.push_back(""); - texts.push_back(""); - texts.push_back("A GAME BY JAILDESIGNER"); - texts.push_back("MADE ON SUMMER/FALL 2022"); - texts.push_back(""); - texts.push_back(""); - texts.push_back("LOVE JAILGAMES!}"); - texts.push_back(""); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"INSTRUCTIONS:", stringToColor("yellow")}); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"HELP JAILDOC TO GET BACK ALL HIS", stringToColor("white")}); + texts.push_back({"PROJECTS AND GO TO THE JAIL TO", stringToColor("white")}); + texts.push_back({"FINISH THEM", stringToColor("white")}); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"KEYS:", stringToColor("yellow")}); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"USE CURSORS TO MOVE AND JUMP", stringToColor("white")}); + texts.push_back({"F1-F4 TO CHANGE WINDOWS SIZE", stringToColor("white")}); + texts.push_back({"F TO SWITCH TO FULLSCREEN", stringToColor("white")}); + texts.push_back({"B TO DE/ACTIVATE THE BORDER SC.", stringToColor("white")}); + texts.push_back({"M TO TURN ON/OFF THE MUSIC", stringToColor("white")}); + texts.push_back({"ESC TO EXIT GAME", stringToColor("white")}); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"A GAME BY JAILDESIGNER", stringToColor("yellow")}); + texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor("yellow")}); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"", stringToColor("white")}); + texts.push_back({"LOVE JAILGAMES!}", stringToColor("white")}); + texts.push_back({"", stringToColor("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); @@ -125,7 +125,7 @@ void Credits::fillTexture() for (auto t : texts) { - text->write(0, i * size, t); + text->writeColored(0, i * size, t.label, t.color); i++; } diff --git a/source/credits.h b/source/credits.h index 47b7f68..a2a19c4 100644 --- a/source/credits.h +++ b/source/credits.h @@ -16,11 +16,10 @@ class Credits { private: - struct letter_t + struct captions_t { - std::string letter; // Letra a escribir - int x; // Posición en el eje x - bool enabled; // Solo se escriben y mueven si estan habilitadas + std::string label; // Texto a escribir + color_t color; // Color del texto }; // Objetos y punteros @@ -37,7 +36,7 @@ private: section_t section; // Estado del bucle principal para saber si continua o se sale Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa - std::vector texts; // Vector con las letras de la marquesina + std::vector texts; // Vector con las letras de la marquesina // Actualiza las variables void update(); diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index bdb88e4..a9b9286 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -53,17 +53,16 @@ void ScoreBoard::render() SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_RenderFillRect(renderer, &rect); + // Dibuja las vidas - sprite->setPosY(line2); - int index; const int desp = (counter / 40) % 8; const int frame = desp % 4; sprite->setCurrentFrame(frame); - + sprite->setPosY(line2); for (int i = 0; i < board->lives; ++i) { sprite->setPosX(8 + (16 * i) + desp); - index = i % color.size(); + const int index = i % color.size(); sprite->getTexture()->setColor(color[index].r, color[index].g, color[index].b); sprite->render(); }