Añadido efecto de flash a la clase Screen
This commit is contained in:
@@ -20,9 +20,14 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
borderHeight = options->video.border.height * 2;
|
||||
dest = {0, 0, 0, 0};
|
||||
borderColor = {0, 0, 0};
|
||||
fade = 0;
|
||||
fadeCounter = 0;
|
||||
fadeLenght = 0;
|
||||
fade.enabled = false;
|
||||
fade.counter = 0;
|
||||
fade.lenght = 0;
|
||||
fade.color = {0xFF, 0xFF, 0xFF};
|
||||
flash.enabled = false;
|
||||
flash.counter = 0;
|
||||
flash.lenght = 0;
|
||||
flash.color = {0xFF, 0xFF, 0xFF};
|
||||
shake.desp = 1;
|
||||
shake.delay = 3;
|
||||
shake.counter = 0;
|
||||
@@ -64,6 +69,9 @@ void Screen::start()
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void Screen::blit()
|
||||
{
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
doFlash();
|
||||
|
||||
// Vuelve a dejar el renderizador en modo normal
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
@@ -241,13 +249,13 @@ void Screen::switchBorder()
|
||||
// Activa el fade
|
||||
void Screen::setFade()
|
||||
{
|
||||
fade = true;
|
||||
fade.enabled = true;
|
||||
}
|
||||
|
||||
// Comprueba si ha terminado el fade
|
||||
bool Screen::fadeEnded()
|
||||
{
|
||||
if (fade || fadeCounter > 0)
|
||||
if (fade.enabled || fade.counter > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -258,21 +266,21 @@ bool Screen::fadeEnded()
|
||||
// Inicializa las variables para el fade
|
||||
void Screen::iniFade()
|
||||
{
|
||||
fade = false;
|
||||
fadeCounter = 0;
|
||||
fadeLenght = 200;
|
||||
fade.enabled = false;
|
||||
fade.counter = 0;
|
||||
fade.lenght = 200;
|
||||
}
|
||||
|
||||
// Actualiza el fade
|
||||
void Screen::updateFade()
|
||||
{
|
||||
if (!fade)
|
||||
if (!fade.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fadeCounter++;
|
||||
if (fadeCounter > fadeLenght)
|
||||
fade.counter++;
|
||||
if (fade.counter > fade.lenght)
|
||||
{
|
||||
iniFade();
|
||||
}
|
||||
@@ -281,14 +289,14 @@ void Screen::updateFade()
|
||||
// Dibuja el fade
|
||||
void Screen::renderFade()
|
||||
{
|
||||
if (!fade)
|
||||
if (!fade.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||
color_t color = {0, 0, 0};
|
||||
const float step = (float)fadeCounter / (float)fadeLenght;
|
||||
const float step = (float)fade.counter / (float)fade.lenght;
|
||||
const int alpha = 0 + (255 - 0) * step;
|
||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
@@ -310,10 +318,11 @@ void Screen::renderFX()
|
||||
void Screen::update()
|
||||
{
|
||||
updateShake();
|
||||
// updateFlash();
|
||||
}
|
||||
|
||||
// Agita la pantalla
|
||||
void Screen::startShake()
|
||||
void Screen::setShake()
|
||||
{
|
||||
shake.remaining = shake.lenght;
|
||||
shake.counter = shake.delay;
|
||||
@@ -341,4 +350,37 @@ void Screen::updateShake()
|
||||
{
|
||||
dest.x = shake.origin;
|
||||
}
|
||||
}
|
||||
|
||||
// Pone la pantalla de color
|
||||
void Screen::setFlash(color_t color, int lenght)
|
||||
{
|
||||
flash.enabled = true;
|
||||
flash.counter = 0;
|
||||
flash.lenght = lenght;
|
||||
flash.color = color;
|
||||
}
|
||||
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
void Screen::doFlash()
|
||||
{
|
||||
if (flash.enabled)
|
||||
{
|
||||
// Dibuja el color del flash en la textura
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer);
|
||||
SDL_SetRenderTarget(renderer, gameCanvas);
|
||||
SDL_SetRenderDrawColor(renderer, flash.color.r, flash.color.g, flash.color.b, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderTarget(renderer, temp);
|
||||
|
||||
// Actualiza la lógica del efecto
|
||||
if (flash.counter < flash.lenght)
|
||||
{
|
||||
flash.counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
flash.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,10 +32,17 @@ private:
|
||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||
|
||||
struct effect_t
|
||||
{
|
||||
bool enabled; // Indica si el efecto está activo
|
||||
int counter; // Contador para el efecto
|
||||
int lenght; // Duración del efecto
|
||||
color_t color; // Color del efecto
|
||||
};
|
||||
|
||||
// Variables - Efectos
|
||||
bool fade; // Indica si esta activo el efecto de fade
|
||||
int fadeCounter; // Temporizador para el efecto de fade
|
||||
int fadeLenght; // Duración del fade
|
||||
effect_t fade; // Variable para gestionar el efecto de fade
|
||||
effect_t flash; // Variable para gestionar el efecto de flash
|
||||
|
||||
struct shake_t
|
||||
{
|
||||
@@ -65,6 +72,9 @@ private:
|
||||
// Actualiza la logica para agitar la pantalla
|
||||
void updateShake();
|
||||
|
||||
// Actualiza y dibuja el efecto de flash en la pantalla
|
||||
void doFlash();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||
@@ -122,7 +132,10 @@ public:
|
||||
bool fadeEnded();
|
||||
|
||||
// Agita la pantalla
|
||||
void startShake();
|
||||
void setShake();
|
||||
|
||||
// Pone la pantalla de color
|
||||
void setFlash(color_t color, int lenght);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3057,7 +3057,7 @@ void Game::disableTimeStopItem()
|
||||
// Agita la pantalla
|
||||
void Game::shakeScreen()
|
||||
{
|
||||
screen->startShake();
|
||||
screen->setShake();
|
||||
}
|
||||
|
||||
// Bucle para el juego
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Constructor
|
||||
Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset, options_t *options, Lang *lang, section_t *section)
|
||||
{
|
||||
// Copia las direcciones de los punteros
|
||||
// Copia las direcciones de los punteros y objetos
|
||||
this->renderer = renderer;
|
||||
this->screen = screen;
|
||||
this->input = input;
|
||||
@@ -12,7 +12,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
|
||||
this->lang = lang;
|
||||
this->section = section;
|
||||
|
||||
// Reserva memoria para los punteros
|
||||
// Reserva memoria y crea los objetos
|
||||
eventHandler = new SDL_Event();
|
||||
fade = new Fade(renderer);
|
||||
|
||||
@@ -48,6 +48,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Input *input, Asset *asset,
|
||||
// Destructor
|
||||
Title::~Title()
|
||||
{
|
||||
// Destruye los objetos y libera la memoria
|
||||
delete eventHandler;
|
||||
delete fade;
|
||||
|
||||
@@ -76,7 +77,7 @@ Title::~Title()
|
||||
SDL_DestroyTexture(background);
|
||||
}
|
||||
|
||||
// Inicializa los valores
|
||||
// Inicializa los valores de las variables
|
||||
void Title::init()
|
||||
{
|
||||
// Inicializa variables
|
||||
@@ -122,7 +123,7 @@ void Title::init()
|
||||
options->input[1].deviceType = availableInputDevices[deviceIndex[1]].deviceType;
|
||||
}
|
||||
|
||||
// Inicializa el bitmap de Coffee
|
||||
// Inicializa el bitmap de 'Coffee'
|
||||
coffeeBitmap->init();
|
||||
coffeeBitmap->setPosX(45);
|
||||
coffeeBitmap->setPosY(11 - 200);
|
||||
@@ -138,7 +139,7 @@ void Title::init()
|
||||
coffeeBitmap->setDestX(45);
|
||||
coffeeBitmap->setDestY(11);
|
||||
|
||||
// Inicializa el bitmap de Crisis
|
||||
// Inicializa el bitmap de 'Crisis'
|
||||
crisisBitmap->init();
|
||||
crisisBitmap->setPosX(60);
|
||||
crisisBitmap->setPosY(57 + 200);
|
||||
@@ -154,7 +155,7 @@ void Title::init()
|
||||
crisisBitmap->setDestX(60);
|
||||
crisisBitmap->setDestY(57);
|
||||
|
||||
// Inicializa el bitmap de DustRight
|
||||
// Inicializa el bitmap de 'DustRight'
|
||||
dustBitmapR->resetAnimation();
|
||||
dustBitmapR->setPosX(218);
|
||||
dustBitmapR->setPosY(47);
|
||||
@@ -162,7 +163,7 @@ void Title::init()
|
||||
dustBitmapR->setHeight(16);
|
||||
dustBitmapR->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
|
||||
// Inicializa el bitmap de DustLeft
|
||||
// Inicializa el bitmap de 'DustLeft'
|
||||
dustBitmapL->resetAnimation();
|
||||
dustBitmapL->setPosX(33);
|
||||
dustBitmapL->setPosY(47);
|
||||
@@ -172,7 +173,8 @@ void Title::init()
|
||||
// Crea el mosaico de fondo del titulo
|
||||
createTiledBackground();
|
||||
|
||||
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida con el mosaico que hay pintado en el titulo al iniciar
|
||||
// Coloca la ventana que recorre el mosaico de fondo de manera que coincida
|
||||
// con el mosaico que hay pintado en el titulo al iniciar
|
||||
backgroundWindow.x = 128;
|
||||
backgroundWindow.y = 96;
|
||||
backgroundWindow.w = GAMECANVAS_WIDTH;
|
||||
@@ -198,6 +200,7 @@ void Title::update()
|
||||
ticks = SDL_GetTicks();
|
||||
|
||||
backgroundObj->update();
|
||||
//screen->update();
|
||||
counter++;
|
||||
|
||||
switch (section->subsection)
|
||||
@@ -215,10 +218,8 @@ void Title::update()
|
||||
section->subsection = SUBSECTION_TITLE_2;
|
||||
|
||||
// Pantallazo blanco
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
screen->setFlash({0xFF, 0xFF, 0xFF}, 5);
|
||||
|
||||
// Reproduce el efecto sonoro
|
||||
JA_PlaySound(crashSound);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ private:
|
||||
std::vector<input_t> availableInputDevices; // Vector con todos los metodos de control disponibles
|
||||
std::vector<int> deviceIndex; // Indice para el jugador [i] del vector de dispositivos de entrada disponibles
|
||||
|
||||
// Inicializa los valores
|
||||
// Inicializa los valores de las variables
|
||||
void init();
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
|
||||
Reference in New Issue
Block a user