From 860c35992b1477bd0626a6c62ce3bf21ae3fe67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Tue, 15 Nov 2022 16:22:40 +0100 Subject: [PATCH] Trabajando en las animaciones de las notificaciones --- .gitignore | 3 ++- source/common/Makefile | 15 --------------- source/common/notify.cpp | 22 +++++++++++++--------- source/common/notify.h | 13 +++++++++++++ source/common/screen.cpp | 2 +- 5 files changed, 29 insertions(+), 26 deletions(-) delete mode 100644 source/common/Makefile diff --git a/.gitignore b/.gitignore index 7bae937..ab2af45 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ thumbs.db *.zip *.app *config.bin -*score.bin \ No newline at end of file +*score.bin +coffee_crisis_debug* \ No newline at end of file diff --git a/source/common/Makefile b/source/common/Makefile deleted file mode 100644 index fc85bf8..0000000 --- a/source/common/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -executable = jaildoctors_dilemma -source = source/*.cpp source/common/*.cpp - -windows: - @echo off - if not exist bin\ (mkdir bin) - g++ $(source) -std=c++11 -Wall -O2 -lmingw32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o bin/$(executable).exe - strip -s -R .comment -R .gnu.version bin/$(executable).exe --strip-unneeded -macos: - mkdir -p bin - g++ $(source) -std=c++11 -Wall -O2 -lSDL2 -ffunction-sections -fdata-sections -o bin/$(executable)_macos -linux: - mkdir -p bin - g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o bin/$(executable)_linux - strip -s -R .comment -R .gnu.version bin/$(executable)_linux --strip-unneeded \ No newline at end of file diff --git a/source/common/notify.cpp b/source/common/notify.cpp index fa6cfc6..d6bdbb5 100644 --- a/source/common/notify.cpp +++ b/source/common/notify.cpp @@ -43,19 +43,22 @@ void Notify::update() { notifications.at(i).counter++; + const int height = notifications.at(i).texture->getHeight(); + const int halfDesp = text->getCharacterSize() / 2; + // Comprueba los estados if (notifications.at(i).state == ns_rising) { - const float step = (notifications.at(i).counter / (float)notifications.at(i).texture->getHeight()); + const float step = ((float)notifications.at(i).counter / (height + halfDesp)); const int alpha = 255 * step; notifications.at(i).rect.y++; - //notifications.at(i).texture->setAlpha(alpha); + notifications.at(i).texture->setAlpha(alpha); - if (notifications.at(i).rect.y == 0) + if (notifications.at(i).rect.y == 0 + halfDesp) { notifications.at(i).state = ns_stay; - //notifications.at(i).texture->setAlpha(255); + notifications.at(i).texture->setAlpha(255); notifications.at(i).counter = 0; } } @@ -71,13 +74,13 @@ void Notify::update() else if (notifications.at(i).state == ns_vanishing) { - const float step = (notifications.at(i).counter / (float)notifications.at(i).texture->getHeight()); + const float step = (notifications.at(i).counter / (float)height); const int alpha = 255 * step; notifications.at(i).rect.y--; - //notifications.at(i).texture->setAlpha(alpha); + notifications.at(i).texture->setAlpha(alpha); - if (notifications.at(i).rect.y == -notifications.at(i).texture->getHeight()) + if (notifications.at(i).rect.y == -height) { notifications.at(i).state = ns_finished; } @@ -110,6 +113,7 @@ void Notify::showText(std::string text) const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2); const int height = this->text->getCharacterSize() * 2; const int desp = this->text->getCharacterSize(); + const int halfDesp = desp / 2; // Crea la notificacion notification_t n; @@ -118,7 +122,7 @@ void Notify::showText(std::string text) n.counter = 0; n.state = ns_rising; n.text = text; - n.rect = {0, -height, width, height}; + n.rect = {halfDesp, -height, width, height}; // Crea la textura n.texture = new Texture(renderer); @@ -127,7 +131,7 @@ void Notify::showText(std::string text) 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, width / 2, desp / 2, text, 1, {255, 255, 255}, 1, {0, 0, 0}); + this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, halfDesp, text, 1, {255, 255, 255}, 1, {0, 0, 0}); // Crea el sprite n.sprite = new Sprite(n.rect, n.texture, renderer); diff --git a/source/common/notify.h b/source/common/notify.h index 3b14bde..b9c7429 100644 --- a/source/common/notify.h +++ b/source/common/notify.h @@ -21,11 +21,24 @@ private: ns_finished }; + enum notification_position_e + { + upperLeft, + upperCenter, + upperRight, + middleLeft, + middleRight, + bottomLeft, + bottomCenter, + bottomRight + }; + struct notification_t { std::string text; int counter; notification_state_e state; + notification_position_e position; Texture *texture; Sprite *sprite; SDL_Rect rect; diff --git a/source/common/screen.cpp b/source/common/screen.cpp index f3b6ac2..3f97aaf 100644 --- a/source/common/screen.cpp +++ b/source/common/screen.cpp @@ -12,7 +12,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options this->asset = asset; // Crea los objetos - notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt")); + notify = new Notify(renderer, asset->get("smb2_big.png"), asset->get("smb2_big.txt")); gameCanvasWidth = gameInternalResX; gameCanvasHeight = gameInternalResY;