Afegit delay opcional al flash de la classe Screen
This commit is contained in:
@@ -9,8 +9,11 @@
|
|||||||
#include "smart_sprite.h" // Para SmartSprite
|
#include "smart_sprite.h" // Para SmartSprite
|
||||||
#include "sprite.h" // Para Sprite
|
#include "sprite.h" // Para Sprite
|
||||||
#include "texture.h" // Para Texture
|
#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
|
// Constructor
|
||||||
GameLogo::GameLogo(int x, int y)
|
GameLogo::GameLogo(int x, int y)
|
||||||
@@ -121,6 +124,8 @@ void GameLogo::update()
|
|||||||
|
|
||||||
// Reproduce el efecto sonoro
|
// Reproduce el efecto sonoro
|
||||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||||
|
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGHT, FLASH_DELAY);
|
||||||
|
Screen::get()->shake();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -183,6 +188,8 @@ void GameLogo::update()
|
|||||||
arcade_edition_sprite_->setZoom(zoom_);
|
arcade_edition_sprite_->setZoom(zoom_);
|
||||||
shake_.init(1, 2, 8, arcade_edition_sprite_->getX());
|
shake_.init(1, 2, 8, arcade_edition_sprite_->getX());
|
||||||
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
JA_PlaySound(Resource::get()->getSound("title.wav"));
|
||||||
|
Screen::get()->flash(Color(0xFF, 0xFF, 0xFF), FLASH_LENGHT, FLASH_DELAY);
|
||||||
|
Screen::get()->shake();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ private:
|
|||||||
int x_; // Posición donde dibujar el logo
|
int x_; // Posición donde dibujar el logo
|
||||||
int y_; // Posición donde dibujar el logo
|
int y_; // Posición donde dibujar el logo
|
||||||
float zoom_; // Zoom aplicado al texto "ARCADE EDITION"
|
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 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"
|
Status arcade_edition_status_ = Status::DISABLED; // Estado en el que se encuentra el texto "ARCADE_EDITION"
|
||||||
|
|||||||
@@ -308,15 +308,15 @@ void Screen::updateShakeEffect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pone la pantalla de color
|
// 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
|
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||||
void Screen::renderFlash()
|
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_SetRenderDrawColor(renderer_, flash_effect_.color.r, flash_effect_.color.g, flash_effect_.color.b, 0xFF);
|
||||||
SDL_RenderClear(renderer_);
|
SDL_RenderClear(renderer_);
|
||||||
@@ -326,10 +326,7 @@ void Screen::renderFlash()
|
|||||||
// Actualiza el efecto de flash
|
// Actualiza el efecto de flash
|
||||||
void Screen::updateFlash()
|
void Screen::updateFlash()
|
||||||
{
|
{
|
||||||
if (flash_effect_.enabled)
|
flash_effect_.update();
|
||||||
{
|
|
||||||
flash_effect_.counter > 0 ? flash_effect_.counter-- : flash_effect_.enabled = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atenua la pantalla
|
// Atenua la pantalla
|
||||||
|
|||||||
@@ -51,12 +51,20 @@ private:
|
|||||||
struct FlashEffect
|
struct FlashEffect
|
||||||
{
|
{
|
||||||
bool enabled; // Indica si el efecto está activo
|
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
|
int counter; // Contador para el efecto
|
||||||
Color color; // Color del efecto
|
Color color; // Color del efecto
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit FlashEffect(bool en = false, int cnt = 0, Color col = Color(0xFF, 0xFF, 0xFF))
|
explicit FlashEffect(bool enabled = false, int lenght = 0, int delay = 0, Color color = Color(0xFF, 0xFF, 0xFF))
|
||||||
: enabled(en), counter(cnt), color(col) {}
|
: 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
|
struct ShakeEffect
|
||||||
@@ -155,7 +163,7 @@ public:
|
|||||||
void shake();
|
void shake();
|
||||||
|
|
||||||
// Pone la pantalla de color
|
// Pone la pantalla de color
|
||||||
void flash(Color color, int lenght);
|
void flash(Color color, int lenght, int delay = 0);
|
||||||
|
|
||||||
// Activa / desactiva los shaders
|
// Activa / desactiva los shaders
|
||||||
void toggleShaders();
|
void toggleShaders();
|
||||||
|
|||||||
Reference in New Issue
Block a user