From 2650a64c800498a90755eb40601dba2c9b97b7f0 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 27 Jun 2024 13:24:18 +0200 Subject: [PATCH] Modificado el fondo de hiscore_table --- source/const.h | 3 ++- source/hiscore_table.cpp | 56 +++++++++++++++++++++++++--------------- source/hiscore_table.h | 8 +++++- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/source/const.h b/source/const.h index b31cf4c..0e24933 100644 --- a/source/const.h +++ b/source/const.h @@ -49,7 +49,8 @@ const int GAMECANVAS_THIRD_QUARTER_Y = (HEIGHT / 4) * 3; #define SECTION_PROG_INTRO 1 #define SECTION_PROG_TITLE 2 #define SECTION_PROG_GAME 3 -#define SECTION_PROG_QUIT 4 +#define SECTION_PROG_HI_SCORE_TABLE 4 +#define SECTION_PROG_QUIT 5 // Subsecciones #define SUBSECTION_GAME_PLAY_1P 0 diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index ec93341..e3be4de 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -1,8 +1,6 @@ #include "hiscore_table.h" #include -const Uint8 SELF = 0; - // Constructor HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section) { @@ -19,25 +17,40 @@ HiScoreTable::HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, // Reserva memoria para los punteros eventHandler = new SDL_Event(); + // Fuente de texto para escribir text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); // Crea un backbuffer para el renderizador backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param->gameWidth, param->gameHeight); + SDL_SetTextureBlendMode(backbuffer, SDL_BLENDMODE_BLEND); + + // Crea el objeto para dibujar el fondo + background = new Background(renderer, screen, asset, param); + background->setSrcDest(windowArea); + background->setDstDest(windowArea); + background->setCloudsSpeed(-0.5f); + background->setGradientNumber(1); + background->setTransition(0.8f); // Inicializa variables - section->name = SELF; + section->name = SECTION_PROG_HI_SCORE_TABLE; ticks = 0; ticksSpeed = 15; manualQuit = false; counter = 0; counterEnd = 600; + viewArea = {0, 0, param->gameWidth, param->gameHeight}; + + // Crea el contenido de la textura con la lista de puntuaciones + fillTexture(); } // Destructor HiScoreTable::~HiScoreTable() { - delete eventHandler; delete text; + delete eventHandler; + delete background; SDL_DestroyTexture(backbuffer); } @@ -57,6 +70,9 @@ void HiScoreTable::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); + // Actualiza el fondo + background->update(); + if (mode == mhst_auto) { // Modo automático counter++; @@ -80,20 +96,18 @@ void HiScoreTable::update() } } -// Pinta en pantalla -void HiScoreTable::render() +// Crea el contenido de la textura con la lista de puntuaciones +void HiScoreTable::fillTexture() { - // Pinta en pantalla - SDL_Rect window = {0, 0, param->gameWidth, param->gameHeight}; - const color_t orangeColor = {0xFF, 0x7A, 0x00}; // hay 27 letras - 7 de puntos quedan 20 caracteres 20 - nameLenght 0 numDots const int spaceBetweenHeader = 32; const int spaceBetweenLines = text->getCharacterSize() * 1.8f; // Pinta en el backbuffer el texto y los sprites + SDL_Texture *temp = SDL_GetRenderTarget(renderer); SDL_SetRenderTarget(renderer, backbuffer); - SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); // Escribe el texto: Mejores puntuaciones @@ -122,26 +136,26 @@ void HiScoreTable::render() } // Cambia el destino de renderizado - SDL_SetRenderTarget(renderer, nullptr); + SDL_SetRenderTarget(renderer, temp); +} +// Pinta en pantalla +void HiScoreTable::render() +{ // Prepara para empezar a dibujar en la textura de juego screen->start(); // Limpia la pantalla screen->clean(bgColor); + // Pinta el fondo + background->render(); + // Establece la ventana del backbuffer - if (mode == mhst_auto) - { - window.y = std::max(8, param->gameHeight - counter + 100); - } - else - { - window.y = 0; - } + viewArea.y = mode == mhst_auto ? std::max(8, param->gameHeight - counter + 100) : 0; // Copia el backbuffer al renderizador - SDL_RenderCopy(renderer, backbuffer, nullptr, &window); + SDL_RenderCopy(renderer, backbuffer, nullptr, &viewArea); // Vuelca el contenido del renderizador en pantalla screen->blit(); @@ -208,7 +222,7 @@ void HiScoreTable::run(mode_hiScoreTable_e mode) { this->mode = mode; - while (section->name == SELF) + while (section->name == SECTION_PROG_HI_SCORE_TABLE) { update(); render(); diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 5afcfcf..d6083fe 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -10,6 +10,7 @@ #include "common/utils.h" #include "const.h" #include "lang.h" +#include "background.h" #ifndef HISCORE_TABLE_H #define HISCORE_TABLE_H @@ -30,10 +31,12 @@ private: SDL_Texture *backbuffer; // Textura para usar como backbuffer Asset *asset; // Objeto que gestiona todos los ficheros de recursos Input *input; // Objeto pata gestionar la entrada + Background *background; // Objeto para dibujar el fondo del juego Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Text *text; // Objeto para escribir texto options_t *options; // Opciones y parametros del programa section_t *section; // Estado del bucle principal para saber si continua o se sale + param_t *param; // Puntero con todos los parametros del programa // Variables Uint16 counter; // Contador @@ -42,7 +45,7 @@ private: Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa bool manualQuit; // Indica si se quiere salir del modo manual mode_hiScoreTable_e mode; // Modo en el que se van a ejecutar las instrucciones - param_t *param; // Puntero con todos los parametros del programa + SDL_Rect viewArea; // Parte de la textura que se muestra en pantalla // Actualiza las variables void update(); @@ -59,6 +62,9 @@ private: // Transforma un valor numérico en una cadena de 6 cifras std::string scoreToString(Uint32 num); + // Crea el contenido de la textura con la lista de puntuaciones + void fillTexture(); + public: // Constructor HiScoreTable(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, param_t *param, options_t *options, section_t *section);