Trabajando en las animaciones de las notificaciones

This commit is contained in:
2022-11-15 16:22:40 +01:00
parent b1c3e0d2af
commit 860c35992b
5 changed files with 29 additions and 26 deletions

3
.gitignore vendored
View File

@@ -10,4 +10,5 @@ thumbs.db
*.zip
*.app
*config.bin
*score.bin
*score.bin
coffee_crisis_debug*

View File

@@ -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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;