diff --git a/source/common/notify.cpp b/source/common/notify.cpp index b7801d0..67359c2 100644 --- a/source/common/notify.cpp +++ b/source/common/notify.cpp @@ -80,8 +80,10 @@ void Notify::showText(std::string text) n.texture = new Texture(renderer); n.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET); n.texture->setAsRenderTarget(renderer); + SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255); + SDL_RenderClear(renderer); n.texture->setBlendMode(SDL_BLENDMODE_BLEND); - this->text->writeDX(TXT_CENTER | TXT_STROKE, desp, desp / 2, text, 1, {255, 255, 255}, 1, {0, 0, 0}); + this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, desp / 2, text, 1, {255, 255, 255}, 1, {0, 0, 0}); // Crea el sprite n.sprite = new Sprite({0, 0, width, height}, n.texture, renderer); diff --git a/source/common/notify.h b/source/common/notify.h index 8c06751..d75fa02 100644 --- a/source/common/notify.h +++ b/source/common/notify.h @@ -37,16 +37,16 @@ private: color_t bgColor; // Color de fondo de las notificaciones std::vector notifications; // La lista de notificaciones activas + // Elimina las notificaciones finalizadas + void clearFinishedNotifications(); + +public: // Dibuja las notificaciones por pantalla void render(); // Actualiza el estado de las notificaiones void update(); - - // Elimina las notificaciones finalizadas - void clearFinishedNotifications(); - -public: + // Constructor Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile); diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 6308cf4..3eea34f 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -3,12 +3,16 @@ #include // Constructor -Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY) +Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options, int gameInternalResX, int gameInternalResY) { // Inicializa variables this->window = window; this->renderer = renderer; this->options = options; + this->asset = asset; + + // Crea los objetos + notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt")); gameCanvasWidth = gameInternalResX; gameCanvasHeight = gameInternalResY; @@ -41,7 +45,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, i // Destructor Screen::~Screen() { - renderer = nullptr; + delete notify; } // Limpia la pantalla @@ -70,6 +74,9 @@ void Screen::blit() // Copia la textura de juego en el renderizador en la posición adecuada SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest); + // Dibuja las notificaciones + notify->render(); + // Muestra por pantalla el renderizador SDL_RenderPresent(renderer); } @@ -362,4 +369,16 @@ void Screen::renderFX() { renderFade(); renderSpectrumFade(); +} + +// Actualiza el notificador +void Screen::updateNotifier() +{ + notify->update(); +} + +// Muestra una notificación de texto por pantalla; +void Screen::showText(std::string text) +{ + notify->showText(text); } \ No newline at end of file diff --git a/source/common/screen.h b/source/common/screen.h index 31fcedf..d3ce36f 100644 --- a/source/common/screen.h +++ b/source/common/screen.h @@ -1,6 +1,8 @@ #pragma once #include +#include "asset.h" +#include "notify.h" #include "utils.h" #include @@ -24,10 +26,13 @@ struct anchor_t class Screen { private: + // Objetos y variables SDL_Window *window; // Ventana de la aplicación SDL_Renderer *renderer; // El renderizador de la ventana + Asset *asset; // Objeto con el listado de recursos SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa options_t *options; // Variable con todas las opciones del programa + Notify *notify; // Dibuja notificaciones por pantalla int screenWidth; // Ancho de la pantalla o ventana int screenHeight; // Alto de la pantalla o ventana @@ -38,12 +43,12 @@ private: color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla // EFECTOS - bool fade; // Indica si esta activo el efecto de fade - int fadeCounter; // Temporizador para el efecto de fade - int fadeLenght; // Duración del fade - bool spectrumFade; // Indica si esta activo el efecto de fade spectrum - int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum - int spectrumFadeLenght; // Duración del fade spectrum + bool fade; // Indica si esta activo el efecto de fade + int fadeCounter; // Temporizador para el efecto de fade + int fadeLenght; // Duración del fade + bool spectrumFade; // Indica si esta activo el efecto de fade spectrum + int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum + int spectrumFadeLenght; // Duración del fade spectrum std::vector spectrumColor; // Colores para el fade spectrum // Inicializa las variables para el fade @@ -66,7 +71,7 @@ private: public: // Constructor - Screen(SDL_Window *window, SDL_Renderer *renderer, options_t *options, int gameInternalResX, int gameInternalResY); + Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options, int gameInternalResX, int gameInternalResY); // Destructor ~Screen(); @@ -121,6 +126,12 @@ public: // Dibuja los efectos void renderFX(); + + // Actualiza el notificador + void updateNotifier(); + + // Muestra una notificación de texto por pantalla; + void showText(std::string text); }; #endif diff --git a/source/director.cpp b/source/director.cpp index 14607db..b2d4cfd 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -36,7 +36,7 @@ Director::Director(std::string path) input = new Input(asset->get("controllerdb.txt")); initInput(); - screen = new Screen(window, renderer, options, GAME_WIDTH, GAME_HEIGHT); + screen = new Screen(window, renderer, asset, options, GAME_WIDTH, GAME_HEIGHT); } Director::~Director() diff --git a/source/intro.cpp b/source/intro.cpp index 119829d..f086079 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -187,10 +187,6 @@ void Intro::checkEventHandler() // Cualquier tecla pulsada if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) { - JA_StopMusic(); - section.name = PROG_SECTION_TITLE; - section.subsection = TITLE_SECTION_1; - switch (eventHandler->key.keysym.scancode) { case SDL_SCANCODE_F: @@ -218,7 +214,14 @@ void Intro::checkEventHandler() texture->reLoad(); break; + case SDL_SCANCODE_F5: + screen->showText("HOLA MAMA!"); + break; + default: + JA_StopMusic(); + section.name = PROG_SECTION_TITLE; + section.subsection = TITLE_SECTION_1; break; } } @@ -404,6 +407,8 @@ void Intro::update() // Actualiza las escenas de la intro updateScenes(); + + screen->updateNotifier(); } }