From bc84968b238684d746070fd11affdc0f64d15cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sat, 19 Nov 2022 10:28:15 +0100 Subject: [PATCH] Ya funcionan las notificaciones --- source/common/notify.cpp | 9 ++------- source/common/screen.cpp | 12 ++++++------ source/common/sprite.cpp | 14 ++++++++++---- source/common/sprite.h | 3 +++ source/game.cpp | 6 +++--- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/source/common/notify.cpp b/source/common/notify.cpp index a60b3af..4be6665 100644 --- a/source/common/notify.cpp +++ b/source/common/notify.cpp @@ -136,18 +136,13 @@ void Notify::showText(std::string text) SDL_RenderClear(renderer); n.texture->setBlendMode(SDL_BLENDMODE_BLEND); this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, despV, text, 1, {255, 255, 255}, 1, {0, 0, 0}); + SDL_SetRenderTarget(renderer, nullptr); // Crea el sprite n.sprite = new Sprite(n.rect, n.texture, renderer); // Añade la notificación a la lista notifications.push_back(n); - - //std::cout << "Notification " << notifications.size() << std::endl; - //std::cout << "width " << width << std::endl; - //std::cout << "height " << height << std::endl; - //std::cout << "offset " << offset << std::endl; - //std::cout << "desp " << despH << std::endl; } // Indica si hay notificaciones activas @@ -157,6 +152,6 @@ bool Notify::active() { return true; } - + return false; } \ No newline at end of file diff --git a/source/common/screen.cpp b/source/common/screen.cpp index 1ae37c5..4bdc562 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -356,12 +356,12 @@ void Screen::showText(std::string text) // Dibuja las notificaciones void Screen::renderNotifications() { - //if (!notifyActive) - //{ - // return; - //} + if (!notifyActive) + { + return; + } - //SDL_RenderSetLogicalSize(renderer, windowWidth * options->windowSize, windowHeight * options->windowSize); + SDL_RenderSetLogicalSize(renderer, windowWidth * 2, windowHeight * 2); notify->render(); - //SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); + SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight); } \ No newline at end of file diff --git a/source/common/sprite.cpp b/source/common/sprite.cpp index 1a49a41..8888074 100644 --- a/source/common/sprite.cpp +++ b/source/common/sprite.cpp @@ -18,7 +18,7 @@ Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *rende this->texture = texture; // Establece el rectangulo de donde coger la imagen - spriteClip = {x, y, w, h}; + spriteClip = {0, 0, w, h}; // Inicializa variables enabled = true; @@ -41,7 +41,7 @@ Sprite::Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer) this->texture = texture; // Establece el rectangulo de donde coger la imagen - spriteClip = {x, y, w, h}; + spriteClip = {0, 0, w, h}; // Inicializa variables enabled = true; @@ -83,8 +83,8 @@ int Sprite::getHeight() // Establece la posición del objeto void Sprite::setPos(SDL_Rect rect) { - x = rect.x; - y = rect.y; + this->x = rect.x; + this->y = rect.y; } // Establece el valor de la variable @@ -166,6 +166,12 @@ void Sprite::setRenderer(SDL_Renderer *renderer) this->renderer = renderer; } +// Obten el valor de la variable +SDL_Renderer *Sprite::getRenderer() +{ + return renderer; +} + // Establece el valor de la variable void Sprite::setEnabled(bool value) { diff --git a/source/common/sprite.h b/source/common/sprite.h index 99d8292..0e0c407 100644 --- a/source/common/sprite.h +++ b/source/common/sprite.h @@ -81,6 +81,9 @@ public: // Establece el valor de la variable void setRenderer(SDL_Renderer *renderer); + // Obten el valor de la variable + SDL_Renderer *getRenderer(); + // Establece el valor de la variable void setEnabled(bool value); diff --git a/source/game.cpp b/source/game.cpp index beb7ee3..48db125 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -21,9 +21,9 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as this->options = options; #ifdef DEBUG - currentRoom = "02.room"; - const int x1 = 20; - const int y1 = 6; + currentRoom = "01.room"; + const int x1 = 25; + const int y1 = 13; spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; #endif