Trabajando en las animaciones de las notificaciones
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,3 +11,4 @@ thumbs.db
|
|||||||
*.app
|
*.app
|
||||||
*config.bin
|
*config.bin
|
||||||
*score.bin
|
*score.bin
|
||||||
|
coffee_crisis_debug*
|
||||||
@@ -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
|
|
||||||
@@ -43,19 +43,22 @@ void Notify::update()
|
|||||||
{
|
{
|
||||||
notifications.at(i).counter++;
|
notifications.at(i).counter++;
|
||||||
|
|
||||||
|
const int height = notifications.at(i).texture->getHeight();
|
||||||
|
const int halfDesp = text->getCharacterSize() / 2;
|
||||||
|
|
||||||
// Comprueba los estados
|
// Comprueba los estados
|
||||||
if (notifications.at(i).state == ns_rising)
|
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;
|
const int alpha = 255 * step;
|
||||||
|
|
||||||
notifications.at(i).rect.y++;
|
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).state = ns_stay;
|
||||||
//notifications.at(i).texture->setAlpha(255);
|
notifications.at(i).texture->setAlpha(255);
|
||||||
notifications.at(i).counter = 0;
|
notifications.at(i).counter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,13 +74,13 @@ void Notify::update()
|
|||||||
else if (notifications.at(i).state == ns_vanishing)
|
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;
|
const int alpha = 255 * step;
|
||||||
|
|
||||||
notifications.at(i).rect.y--;
|
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;
|
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 width = this->text->lenght(text) + (this->text->getCharacterSize() * 2);
|
||||||
const int height = this->text->getCharacterSize() * 2;
|
const int height = this->text->getCharacterSize() * 2;
|
||||||
const int desp = this->text->getCharacterSize();
|
const int desp = this->text->getCharacterSize();
|
||||||
|
const int halfDesp = desp / 2;
|
||||||
|
|
||||||
// Crea la notificacion
|
// Crea la notificacion
|
||||||
notification_t n;
|
notification_t n;
|
||||||
@@ -118,7 +122,7 @@ void Notify::showText(std::string text)
|
|||||||
n.counter = 0;
|
n.counter = 0;
|
||||||
n.state = ns_rising;
|
n.state = ns_rising;
|
||||||
n.text = text;
|
n.text = text;
|
||||||
n.rect = {0, -height, width, height};
|
n.rect = {halfDesp, -height, width, height};
|
||||||
|
|
||||||
// Crea la textura
|
// Crea la textura
|
||||||
n.texture = new Texture(renderer);
|
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_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
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
|
// Crea el sprite
|
||||||
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
||||||
|
|||||||
@@ -21,11 +21,24 @@ private:
|
|||||||
ns_finished
|
ns_finished
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum notification_position_e
|
||||||
|
{
|
||||||
|
upperLeft,
|
||||||
|
upperCenter,
|
||||||
|
upperRight,
|
||||||
|
middleLeft,
|
||||||
|
middleRight,
|
||||||
|
bottomLeft,
|
||||||
|
bottomCenter,
|
||||||
|
bottomRight
|
||||||
|
};
|
||||||
|
|
||||||
struct notification_t
|
struct notification_t
|
||||||
{
|
{
|
||||||
std::string text;
|
std::string text;
|
||||||
int counter;
|
int counter;
|
||||||
notification_state_e state;
|
notification_state_e state;
|
||||||
|
notification_position_e position;
|
||||||
Texture *texture;
|
Texture *texture;
|
||||||
Sprite *sprite;
|
Sprite *sprite;
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
|
|
||||||
// Crea los objetos
|
// 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;
|
gameCanvasWidth = gameInternalResX;
|
||||||
gameCanvasHeight = gameInternalResY;
|
gameCanvasHeight = gameInternalResY;
|
||||||
|
|||||||
Reference in New Issue
Block a user