Afegit delay opcional al flash de la classe Screen

This commit is contained in:
2024-12-09 20:06:59 +01:00
parent 7016849587
commit 3367b70cd5
4 changed files with 24 additions and 12 deletions

View File

@@ -9,8 +9,11 @@
#include "smart_sprite.h" // Para SmartSprite
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
#include "screen.h"
constexpr int ZOOM_FACTOR = 4;
constexpr int ZOOM_FACTOR = 5;
constexpr int FLASH_DELAY = 3;
constexpr int FLASH_LENGHT = FLASH_DELAY + 3;
// Constructor
GameLogo::GameLogo(int x, int y)
@@ -121,6 +124,8 @@ void GameLogo::update()
// Reproduce el efecto sonoro
JA_PlaySound(Resource::get()->getSound("title.wav"));
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGHT, FLASH_DELAY);
Screen::get()->shake();
}
break;
@@ -183,6 +188,8 @@ void GameLogo::update()
arcade_edition_sprite_->setZoom(zoom_);
shake_.init(1, 2, 8, arcade_edition_sprite_->getX());
JA_PlaySound(Resource::get()->getSound("title.wav"));
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGHT, FLASH_DELAY);
Screen::get()->shake();
}
break;
}

View File

@@ -64,7 +64,7 @@ private:
int x_; // Posición donde dibujar el logo
int y_; // Posición donde dibujar el logo
float zoom_; // Zoom aplicado al texto "ARCADE EDITION"
int post_finished_counter_ = 30; // Contador final una vez terminada las animaciones de los logos
int post_finished_counter_ = 1; // Contador final una vez terminada las animaciones de los logos
Status coffee_crisis_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "COFFEE CRISIS"
Status arcade_edition_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "ARCADE_EDITION"

View File

@@ -308,15 +308,15 @@ void Screen::updateShakeEffect()
}
// Pone la pantalla de color
void Screen::flash(Color color, int lenght)
void Screen::flash(Color color, int lenght, int delay)
{
flash_effect_ = FlashEffect(true, lenght, color);
flash_effect_ = FlashEffect(true, lenght, delay, color);
}
// Actualiza y dibuja el efecto de flash en la pantalla
void Screen::renderFlash()
{
if (flash_effect_.enabled)
if (flash_effect_.isRendarable())
{
SDL_SetRenderDrawColor(renderer_, flash_effect_.color.r, flash_effect_.color.g, flash_effect_.color.b, 0xFF);
SDL_RenderClear(renderer_);
@@ -326,10 +326,7 @@ void Screen::renderFlash()
// Actualiza el efecto de flash
void Screen::updateFlash()
{
if (flash_effect_.enabled)
{
flash_effect_.counter > 0 ? flash_effect_.counter-- : flash_effect_.enabled = false;
}
flash_effect_.update();
}
// Atenua la pantalla

View File

@@ -51,12 +51,20 @@ private:
struct FlashEffect
{
bool enabled; // Indica si el efecto está activo
int lenght; // Duración del efecto
int delay; // Frames iniciales en los que no se aplica
int counter; // Contador para el efecto
Color color; // Color del efecto
// Constructor
explicit FlashEffect(bool en = false, int cnt = 0, Color col = Color(0xFF, 0xFF, 0xFF))
: enabled(en), counter(cnt), color(col) {}
explicit FlashEffect(bool enabled = false, int lenght = 0, int delay = 0, Color color = Color(0xFF, 0xFF, 0xFF))
: enabled(enabled), lenght(lenght), delay(delay), counter(lenght), color(color) {}
// Actualiza
void update() { (enabled && counter > 0) ? counter-- : enabled = false; }
// Indica si se pude dibujar
bool isRendarable() { return enabled && counter < lenght - delay; }
};
struct ShakeEffect
@@ -155,7 +163,7 @@ public:
void shake();
// Pone la pantalla de color
void flash(Color color, int lenght);
void flash(Color color, int lenght, int delay = 0);
// Activa / desactiva los shaders
void toggleShaders();