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