Trabajando en la animacion de las notificaciones

This commit is contained in:
2022-11-15 13:47:39 +01:00
parent 54cee20883
commit b1c3e0d2af
6 changed files with 104 additions and 7 deletions

View File

@@ -7,7 +7,8 @@ Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textF
{
// Inicializa variables
this->renderer = renderer;
bgColor = {32, 32, 32};
bgColor = {64, 64, 64};
waitTime = 300;
// Crea objetos
text = new Text(bitmapFile, textFile, renderer);
@@ -41,6 +42,48 @@ void Notify::update()
for (int i = 0; i < (int)notifications.size(); ++i)
{
notifications.at(i).counter++;
// Comprueba los estados
if (notifications.at(i).state == ns_rising)
{
const float step = (notifications.at(i).counter / (float)notifications.at(i).texture->getHeight());
const int alpha = 255 * step;
notifications.at(i).rect.y++;
//notifications.at(i).texture->setAlpha(alpha);
if (notifications.at(i).rect.y == 0)
{
notifications.at(i).state = ns_stay;
//notifications.at(i).texture->setAlpha(255);
notifications.at(i).counter = 0;
}
}
else if (notifications.at(i).state == ns_stay)
{
if (notifications.at(i).counter == waitTime)
{
notifications.at(i).state = ns_vanishing;
notifications.at(i).counter = 0;
}
}
else if (notifications.at(i).state == ns_vanishing)
{
const float step = (notifications.at(i).counter / (float)notifications.at(i).texture->getHeight());
const int alpha = 255 * step;
notifications.at(i).rect.y--;
//notifications.at(i).texture->setAlpha(alpha);
if (notifications.at(i).rect.y == -notifications.at(i).texture->getHeight())
{
notifications.at(i).state = ns_finished;
}
}
notifications.at(i).sprite->setRect(notifications.at(i).rect);
}
clearFinishedNotifications();
@@ -51,7 +94,7 @@ void Notify::clearFinishedNotifications()
{
for (int i = (int)notifications.size() - 1; i >= 0; --i)
{
if (notifications.at(i).counter >= 300)
if (notifications.at(i).state == ns_finished)
{
delete notifications.at(i).sprite;
delete notifications.at(i).texture;
@@ -75,6 +118,7 @@ void Notify::showText(std::string text)
n.counter = 0;
n.state = ns_rising;
n.text = text;
n.rect = {0, -height, width, height};
// Crea la textura
n.texture = new Texture(renderer);
@@ -86,7 +130,7 @@ void Notify::showText(std::string text)
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);
n.sprite = new Sprite(n.rect, n.texture, renderer);
// Añade la notificación a la lista
notifications.push_back(n);

View File

@@ -17,7 +17,8 @@ private:
{
ns_rising,
ns_stay,
ns_vanishing
ns_vanishing,
ns_finished
};
struct notification_t
@@ -27,6 +28,7 @@ private:
notification_state_e state;
Texture *texture;
Sprite *sprite;
SDL_Rect rect;
};
// Objetos y punteros
@@ -35,6 +37,7 @@ private:
// Variables
color_t bgColor; // Color de fondo de las notificaciones
int waitTime; // Tiempo que se ve la notificación
std::vector<notification_t> notifications; // La lista de notificaciones activas
// Elimina las notificaciones finalizadas
@@ -46,7 +49,7 @@ public:
// Actualiza el estado de las notificaiones
void update();
// Constructor
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile);

View File

@@ -2703,6 +2703,9 @@ void Game::update()
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza las notificaciones
screen->updateNotifier();
// Actualiza el contador de juego
counter++;
@@ -3286,6 +3289,9 @@ void Game::updatePausedGame()
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza las notificaciones
screen->updateNotifier();
if (leavingPauseMenu)
{
if (pauseCounter > 0)
@@ -3447,6 +3453,9 @@ void Game::updateGameOverScreen()
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza las notificaciones
screen->updateNotifier();
// Actualiza la lógica del menu
gameOverMenu->update();

View File

@@ -408,6 +408,7 @@ void Intro::update()
// Actualiza las escenas de la intro
updateScenes();
// Actualiza las notificaciones
screen->updateNotifier();
}
}

View File

@@ -60,8 +60,42 @@ void Logo::checkEventHandler()
// Cualquier tecla pulsada
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_F:
screen->switchVideoMode();
texture->reLoad();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
texture->reLoad();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
texture->reLoad();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
texture->reLoad();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
texture->reLoad();
break;
case SDL_SCANCODE_F5:
screen->showText("Conectado a Jailers.net");
break;
default:
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
break;
}
}
}
}
@@ -94,6 +128,9 @@ void Logo::update()
// Comprueba si ha terminado el logo
checkLogoEnd();
// Actualiza las notificaciones
screen->updateNotifier();
}
}

View File

@@ -210,6 +210,9 @@ void Title::update()
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza las notificaciones
screen->updateNotifier();
switch (section.subsection)
{
// Sección 1 - Titulo desplazandose