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 // Inicializa variables
this->renderer = renderer; this->renderer = renderer;
bgColor = {32, 32, 32}; bgColor = {64, 64, 64};
waitTime = 300;
// Crea objetos // Crea objetos
text = new Text(bitmapFile, textFile, renderer); text = new Text(bitmapFile, textFile, renderer);
@@ -41,6 +42,48 @@ void Notify::update()
for (int i = 0; i < (int)notifications.size(); ++i) for (int i = 0; i < (int)notifications.size(); ++i)
{ {
notifications.at(i).counter++; 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(); clearFinishedNotifications();
@@ -51,7 +94,7 @@ void Notify::clearFinishedNotifications()
{ {
for (int i = (int)notifications.size() - 1; i >= 0; --i) 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).sprite;
delete notifications.at(i).texture; delete notifications.at(i).texture;
@@ -75,6 +118,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};
// Crea la textura // Crea la textura
n.texture = new Texture(renderer); 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}); this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, desp / 2, text, 1, {255, 255, 255}, 1, {0, 0, 0});
// Crea el sprite // 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 // Añade la notificación a la lista
notifications.push_back(n); notifications.push_back(n);

View File

@@ -17,7 +17,8 @@ private:
{ {
ns_rising, ns_rising,
ns_stay, ns_stay,
ns_vanishing ns_vanishing,
ns_finished
}; };
struct notification_t struct notification_t
@@ -27,6 +28,7 @@ private:
notification_state_e state; notification_state_e state;
Texture *texture; Texture *texture;
Sprite *sprite; Sprite *sprite;
SDL_Rect rect;
}; };
// Objetos y punteros // Objetos y punteros
@@ -35,6 +37,7 @@ private:
// Variables // Variables
color_t bgColor; // Color de fondo de las notificaciones 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 std::vector<notification_t> notifications; // La lista de notificaciones activas
// Elimina las notificaciones finalizadas // Elimina las notificaciones finalizadas

View File

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

View File

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

View File

@@ -60,8 +60,42 @@ void Logo::checkEventHandler()
// Cualquier tecla pulsada // Cualquier tecla pulsada
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{ {
section.name = PROG_SECTION_TITLE; switch (eventHandler->key.keysym.scancode)
section.subsection = TITLE_SECTION_1; {
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 // Comprueba si ha terminado el logo
checkLogoEnd(); checkLogoEnd();
// Actualiza las notificaciones
screen->updateNotifier();
} }
} }

View File

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