Afegits estats al fade
Afegida opció de prefade El modo demo ja comença a meitat del "meollo"
This commit is contained in:
@@ -30,15 +30,15 @@ void Fade::init()
|
||||
{
|
||||
type_ = FadeType::CENTER;
|
||||
mode_ = FadeMode::OUT;
|
||||
enabled_ = false;
|
||||
finished_ = false;
|
||||
counter_ = 0;
|
||||
r_ = 0;
|
||||
g_ = 0;
|
||||
b_ = 0;
|
||||
a_ = 0;
|
||||
post_duration_ = 20;
|
||||
post_duration_ = 0;
|
||||
post_counter_ = 0;
|
||||
pre_duration_ = 0;
|
||||
pre_counter_ = 0;
|
||||
num_squares_width_ = param.fade.num_squares_width;
|
||||
num_squares_height_ = param.fade.num_squares_height;
|
||||
fade_random_squares_delay_ = param.fade.random_squares_delay;
|
||||
@@ -48,15 +48,14 @@ void Fade::init()
|
||||
// Resetea algunas variables para volver a hacer el fade sin perder ciertos parametros
|
||||
void Fade::reset()
|
||||
{
|
||||
enabled_ = false;
|
||||
finished_ = false;
|
||||
state_ = FadeState::NOT_ENABLED;
|
||||
counter_ = 0;
|
||||
}
|
||||
|
||||
// Pinta una transición en pantalla
|
||||
void Fade::render()
|
||||
{
|
||||
if (enabled_ || finished_)
|
||||
//if (state_ != FadeState::NOT_ENABLED)
|
||||
{
|
||||
SDL_RenderCopy(renderer_, backbuffer_, nullptr, nullptr);
|
||||
}
|
||||
@@ -65,7 +64,20 @@ void Fade::render()
|
||||
// Actualiza las variables internas
|
||||
void Fade::update()
|
||||
{
|
||||
if (enabled_)
|
||||
if (state_ == FadeState::PRE)
|
||||
{
|
||||
// Actualiza el contador
|
||||
if (pre_counter_ == pre_duration_)
|
||||
{
|
||||
state_ = FadeState::FADING;
|
||||
}
|
||||
else
|
||||
{
|
||||
pre_counter_++;
|
||||
}
|
||||
}
|
||||
|
||||
if (state_ == FadeState::FADING)
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
@@ -79,7 +91,7 @@ void Fade::update()
|
||||
// Comprueba si ha terminado
|
||||
if (counter_ >= 255 / 4)
|
||||
{
|
||||
finished_ = true;
|
||||
state_ = FadeState::POST;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -110,7 +122,7 @@ void Fade::update()
|
||||
// Comprueba si ha terminado
|
||||
if ((counter_ * 4) > param.game.height)
|
||||
{
|
||||
finished_ = true;
|
||||
state_ = FadeState::POST;
|
||||
a_ = 255;
|
||||
}
|
||||
break;
|
||||
@@ -143,7 +155,7 @@ void Fade::update()
|
||||
// Comprueba si ha terminado
|
||||
if (counter_ * fade_random_squares_mult_ / fade_random_squares_delay_ >= num_squares_width_ * num_squares_height_)
|
||||
{
|
||||
finished_ = true;
|
||||
state_ = FadeState::POST;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -189,39 +201,47 @@ void Fade::update()
|
||||
}
|
||||
else
|
||||
{
|
||||
finished_ = true;
|
||||
state_ = FadeState::POST;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (finished_)
|
||||
{
|
||||
// Actualiza el contador
|
||||
post_counter_ == post_duration_ ? enabled_ = false : post_counter_++;
|
||||
|
||||
// Deja el backbuffer_ todo del mismo color
|
||||
cleanBackbuffer(r_, g_, b_, a_);
|
||||
}
|
||||
|
||||
counter_++;
|
||||
}
|
||||
|
||||
if (state_ == FadeState::POST)
|
||||
{
|
||||
// Actualiza el contador
|
||||
if (post_counter_ == post_duration_)
|
||||
{
|
||||
state_ = FadeState::FINISHED;
|
||||
}
|
||||
else
|
||||
{
|
||||
post_counter_++;
|
||||
}
|
||||
|
||||
// Deja el backbuffer_ todo del mismo color
|
||||
cleanBackbuffer(r_, g_, b_, a_);
|
||||
}
|
||||
}
|
||||
|
||||
// Activa el fade
|
||||
void Fade::activate()
|
||||
{
|
||||
// Si ya está habilitado, no hay que volverlo a activar
|
||||
if (enabled_)
|
||||
if (state_ != FadeState::NOT_ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
enabled_ = true;
|
||||
finished_ = false;
|
||||
state_ = FadeState::PRE;
|
||||
counter_ = 0;
|
||||
post_counter_ = 0;
|
||||
pre_counter_ = 0;
|
||||
|
||||
switch (type_)
|
||||
{
|
||||
@@ -326,8 +346,14 @@ void Fade::cleanBackbuffer(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
int Fade::calculateValue(int min, int max, int current)
|
||||
{
|
||||
if (current < min)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (current > max)
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
|
||||
return static_cast<int>(100.0 * (current - min) / (max - min));
|
||||
}
|
||||
Reference in New Issue
Block a user