afegit el fade RANDOM_SQAURE2
canviat els timings del fade a milisegons
This commit is contained in:
@@ -17,11 +17,10 @@ game.hit_stop_ms 500 # Cantidad de milisegundos que dura el
|
|||||||
|
|
||||||
# --- FADE ---
|
# --- FADE ---
|
||||||
fade.color 1F2B30 # Color hexadecimal para el efecto de fundido
|
fade.color 1F2B30 # Color hexadecimal para el efecto de fundido
|
||||||
fade.num_squares_width 160 # Número de cuadrados en el eje X para el fundido
|
fade.num_squares_width 64 # Número de cuadrados en el eje X para el fundido
|
||||||
fade.num_squares_height 120 # Número de cuadrados en el eje Y para el fundido
|
fade.num_squares_height 48 # Número de cuadrados en el eje Y para el fundido
|
||||||
fade.random_squares_delay 1 # Delay entre aparición de cuadrados aleatorios (frames)
|
fade.random_squares_duration_ms 1000 # Duración del fade en milisegundos
|
||||||
fade.random_squares_mult 500 # Multiplicador para la velocidad de aparición aleatoria
|
fade.post_duration_ms 500 # Duración tras el fundido en milisegundos
|
||||||
fade.post_duration 80 # Duración tras el fundido (frames)
|
|
||||||
fade.venetian_size 12 # Tamaño de las bandas para el efecto veneciano (en píxeles)
|
fade.venetian_size 12 # Tamaño de las bandas para el efecto veneciano (en píxeles)
|
||||||
|
|
||||||
# --- SCOREBOARD ---
|
# --- SCOREBOARD ---
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ game.hit_stop_ms 500 # Cantidad de milisegundos que dura el
|
|||||||
|
|
||||||
# --- FADE ---
|
# --- FADE ---
|
||||||
fade.color 1F2B30 # Color hexadecimal para el efecto de fundido
|
fade.color 1F2B30 # Color hexadecimal para el efecto de fundido
|
||||||
fade.num_squares_width 160 # Número de cuadrados en el eje X para el fundido
|
fade.num_squares_width 64 # Número de cuadrados en el eje X para el fundido
|
||||||
fade.num_squares_height 128 # Número de cuadrados en el eje Y para el fundido
|
fade.num_squares_height 48 # Número de cuadrados en el eje Y para el fundido
|
||||||
fade.random_squares_delay 1 # Delay entre aparición de cuadrados aleatorios (frames)
|
fade.random_squares_duration_ms 1000 # Duración del fade en milisegundos
|
||||||
fade.random_squares_mult 500 # Multiplicador para la velocidad de aparición aleatoria
|
fade.post_duration_ms 500 # Duración tras el fundido en milisegundos
|
||||||
fade.post_duration 80 # Duración tras el fundido (frames)
|
|
||||||
fade.venetian_size 12 # Tamaño de las bandas para el efecto veneciano (en píxeles)
|
fade.venetian_size 12 # Tamaño de las bandas para el efecto veneciano (en píxeles)
|
||||||
|
|
||||||
# --- SCOREBOARD ---
|
# --- SCOREBOARD ---
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ namespace Fade {
|
|||||||
constexpr const char* COLOR = "1F2B30";
|
constexpr const char* COLOR = "1F2B30";
|
||||||
constexpr float NUM_SQUARES_WIDTH = 160.0F;
|
constexpr float NUM_SQUARES_WIDTH = 160.0F;
|
||||||
constexpr float NUM_SQUARES_HEIGHT = 128.0F;
|
constexpr float NUM_SQUARES_HEIGHT = 128.0F;
|
||||||
constexpr int RANDOM_SQUARES_DELAY = 1;
|
constexpr int RANDOM_SQUARES_DURATION_MS = 1;
|
||||||
constexpr int RANDOM_SQUARES_MULT = 500;
|
constexpr int POST_DURATION_MS = 80;
|
||||||
constexpr int POST_DURATION = 80;
|
|
||||||
constexpr float VENETIAN_SIZE = 12.0F;
|
constexpr float VENETIAN_SIZE = 12.0F;
|
||||||
} // namespace Fade
|
} // namespace Fade
|
||||||
|
|
||||||
@@ -76,7 +75,8 @@ namespace Balloon {
|
|||||||
struct BalloonSettings {
|
struct BalloonSettings {
|
||||||
float vel;
|
float vel;
|
||||||
float grav;
|
float grav;
|
||||||
constexpr BalloonSettings(float v, float g) : vel(v), grav(g) {}
|
constexpr BalloonSettings(float v, float g)
|
||||||
|
: vel(v), grav(g) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr std::array<BalloonSettings, 4> SETTINGS = {{
|
constexpr std::array<BalloonSettings, 4> SETTINGS = {{
|
||||||
@@ -87,7 +87,10 @@ constexpr std::array<BalloonSettings, 4> SETTINGS = {{
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
constexpr std::array<const char*, 4> COLORS = {
|
constexpr std::array<const char*, 4> COLORS = {
|
||||||
"blue", "orange", "red", "green"};
|
"blue",
|
||||||
|
"orange",
|
||||||
|
"red",
|
||||||
|
"green"};
|
||||||
|
|
||||||
constexpr bool BOUNCING_SOUND = false;
|
constexpr bool BOUNCING_SOUND = false;
|
||||||
} // namespace Balloon
|
} // namespace Balloon
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
|||||||
Section::name = Section::Name::GAME;
|
Section::name = Section::Name::GAME;
|
||||||
Section::options = Section::Options::GAME_PLAY_1P;
|
Section::options = Section::Options::GAME_PLAY_1P;
|
||||||
#elif _DEBUG
|
#elif _DEBUG
|
||||||
Section::name = Section::Name::GAME;
|
Section::name = Section::Name::TITLE;
|
||||||
Section::options = Section::Options::GAME_PLAY_1P;
|
Section::options = Section::Options::GAME_PLAY_1P;
|
||||||
#else // NORMAL GAME
|
#else // NORMAL GAME
|
||||||
Section::name = Section::Name::LOGO;
|
Section::name = Section::Name::LOGO;
|
||||||
|
|||||||
244
source/fade.cpp
244
source/fade.cpp
@@ -35,19 +35,22 @@ void Fade::init() {
|
|||||||
b_ = 0;
|
b_ = 0;
|
||||||
a_ = 0;
|
a_ = 0;
|
||||||
post_duration_ = 0;
|
post_duration_ = 0;
|
||||||
post_counter_ = 0;
|
post_start_time_ = 0;
|
||||||
pre_duration_ = 0;
|
pre_duration_ = 0;
|
||||||
pre_counter_ = 0;
|
pre_start_time_ = 0;
|
||||||
num_squares_width_ = param.fade.num_squares_width;
|
num_squares_width_ = param.fade.num_squares_width;
|
||||||
num_squares_height_ = param.fade.num_squares_height;
|
num_squares_height_ = param.fade.num_squares_height;
|
||||||
fade_random_squares_delay_ = param.fade.random_squares_delay;
|
random_squares_duration_ = param.fade.random_squares_duration_ms; // Usar como duración en ms
|
||||||
fade_random_squares_mult_ = param.fade.random_squares_mult;
|
square_transition_duration_ = random_squares_duration_ / 4; // 25% del tiempo total para la transición individual
|
||||||
|
random_squares_start_time_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resetea algunas variables para volver a hacer el fade sin perder ciertos parametros
|
// Resetea algunas variables para volver a hacer el fade sin perder ciertos parametros
|
||||||
void Fade::reset() {
|
void Fade::reset() {
|
||||||
state_ = State::NOT_ENABLED;
|
state_ = State::NOT_ENABLED;
|
||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
|
post_start_time_ = 0;
|
||||||
|
pre_start_time_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta una transición en pantalla
|
// Pinta una transición en pantalla
|
||||||
@@ -75,10 +78,11 @@ void Fade::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Fade::updatePreState() {
|
void Fade::updatePreState() {
|
||||||
if (pre_counter_ == pre_duration_) {
|
// Sistema basado en tiempo únicamente
|
||||||
|
Uint32 elapsed_time = SDL_GetTicks() - pre_start_time_;
|
||||||
|
|
||||||
|
if (elapsed_time >= static_cast<Uint32>(pre_duration_)) {
|
||||||
state_ = State::FADING;
|
state_ = State::FADING;
|
||||||
} else {
|
|
||||||
pre_counter_++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +97,9 @@ void Fade::updateFadingState() {
|
|||||||
case Type::RANDOM_SQUARE:
|
case Type::RANDOM_SQUARE:
|
||||||
updateRandomSquareFade();
|
updateRandomSquareFade();
|
||||||
break;
|
break;
|
||||||
|
case Type::RANDOM_SQUARE2:
|
||||||
|
updateRandomSquare2Fade();
|
||||||
|
break;
|
||||||
case Type::VENETIAN:
|
case Type::VENETIAN:
|
||||||
updateVenetianFade();
|
updateVenetianFade();
|
||||||
break;
|
break;
|
||||||
@@ -102,13 +109,26 @@ void Fade::updateFadingState() {
|
|||||||
counter_++;
|
counter_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Fade::changeToPostState() {
|
||||||
|
state_ = State::POST;
|
||||||
|
post_start_time_ = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
|
||||||
void Fade::updatePostState() {
|
void Fade::updatePostState() {
|
||||||
if (post_counter_ == post_duration_) {
|
// Sistema basado en tiempo únicamente
|
||||||
|
Uint32 elapsed_time = SDL_GetTicks() - post_start_time_;
|
||||||
|
|
||||||
|
if (elapsed_time >= static_cast<Uint32>(post_duration_)) {
|
||||||
state_ = State::FINISHED;
|
state_ = State::FINISHED;
|
||||||
} else {
|
|
||||||
post_counter_++;
|
|
||||||
}
|
}
|
||||||
cleanBackbuffer(r_, g_, b_, a_);
|
|
||||||
|
// Mantener el alpha final correcto para cada tipo de fade
|
||||||
|
Uint8 post_alpha = a_;
|
||||||
|
if (type_ == Type::RANDOM_SQUARE2) {
|
||||||
|
post_alpha = (mode_ == Mode::OUT) ? 255 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanBackbuffer(r_, g_, b_, post_alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fade::updateFullscreenFade() {
|
void Fade::updateFullscreenFade() {
|
||||||
@@ -118,7 +138,7 @@ void Fade::updateFullscreenFade() {
|
|||||||
|
|
||||||
// Comprueba si ha terminado
|
// Comprueba si ha terminado
|
||||||
if (counter_ >= 255 / 4) {
|
if (counter_ >= 255 / 4) {
|
||||||
state_ = State::POST;
|
changeToPostState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,8 +147,8 @@ void Fade::updateCenterFade() {
|
|||||||
|
|
||||||
// Comprueba si ha terminado
|
// Comprueba si ha terminado
|
||||||
if ((counter_ * 4) > param.game.height) {
|
if ((counter_ * 4) > param.game.height) {
|
||||||
state_ = State::POST;
|
|
||||||
a_ = 255;
|
a_ = 255;
|
||||||
|
changeToPostState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,20 +171,99 @@ void Fade::drawCenterFadeRectangles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Fade::updateRandomSquareFade() {
|
void Fade::updateRandomSquareFade() {
|
||||||
if (counter_ % fade_random_squares_delay_ == 0) {
|
Uint32 elapsed_time = SDL_GetTicks() - random_squares_start_time_;
|
||||||
drawRandomSquares();
|
float progress = static_cast<float>(elapsed_time) / random_squares_duration_;
|
||||||
}
|
|
||||||
|
|
||||||
value_ = calculateValue(0, (num_squares_width_ * num_squares_height_), (counter_ * fade_random_squares_mult_ / fade_random_squares_delay_));
|
// Calcula cuántos cuadrados deberían estar activos
|
||||||
|
int total_squares = num_squares_width_ * num_squares_height_;
|
||||||
|
int active_squares = static_cast<int>(progress * total_squares);
|
||||||
|
active_squares = std::min(active_squares, total_squares);
|
||||||
|
|
||||||
|
// Dibuja los cuadrados activos
|
||||||
|
drawRandomSquares(active_squares);
|
||||||
|
|
||||||
|
value_ = calculateValue(0, total_squares, active_squares);
|
||||||
|
|
||||||
// Comprueba si ha terminado
|
// Comprueba si ha terminado
|
||||||
if (counter_ * fade_random_squares_mult_ / fade_random_squares_delay_ >=
|
if (elapsed_time >= static_cast<Uint32>(random_squares_duration_)) {
|
||||||
num_squares_width_ * num_squares_height_) {
|
changeToPostState();
|
||||||
state_ = State::POST;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fade::drawRandomSquares() {
|
void Fade::updateRandomSquare2Fade() {
|
||||||
|
Uint32 elapsed_time = SDL_GetTicks() - random_squares_start_time_;
|
||||||
|
|
||||||
|
int total_squares = num_squares_width_ * num_squares_height_;
|
||||||
|
|
||||||
|
// Calcula el tiempo de activación: total - tiempo que necesitan los últimos cuadrados
|
||||||
|
int activation_time = random_squares_duration_ - square_transition_duration_;
|
||||||
|
activation_time = std::max(activation_time, square_transition_duration_); // Mínimo igual a la duración de transición
|
||||||
|
|
||||||
|
// Lógica diferente según el modo
|
||||||
|
int squares_to_activate = 0;
|
||||||
|
|
||||||
|
if (mode_ == Mode::OUT) {
|
||||||
|
// OUT: Activa cuadrados gradualmente
|
||||||
|
if (elapsed_time < static_cast<Uint32>(activation_time)) {
|
||||||
|
float activation_progress = static_cast<float>(elapsed_time) / activation_time;
|
||||||
|
squares_to_activate = static_cast<int>(activation_progress * total_squares);
|
||||||
|
} else {
|
||||||
|
squares_to_activate = total_squares; // Activar todos
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activa nuevos cuadrados y guarda su tiempo de activación
|
||||||
|
for (int i = 0; i < squares_to_activate && i < total_squares; ++i) {
|
||||||
|
if (square_age_[i] == -1) {
|
||||||
|
square_age_[i] = elapsed_time; // Guarda el tiempo de activación
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// IN: Todos los cuadrados empiezan activos desde el inicio
|
||||||
|
squares_to_activate = total_squares;
|
||||||
|
|
||||||
|
// Activa cuadrados gradualmente con tiempo de inicio escalonado
|
||||||
|
float activation_progress = static_cast<float>(elapsed_time) / activation_time;
|
||||||
|
int squares_starting_transition = static_cast<int>(activation_progress * total_squares);
|
||||||
|
|
||||||
|
// Asegurar que al menos 1 cuadrado se active desde el primer frame
|
||||||
|
squares_starting_transition = std::max(squares_starting_transition, 1);
|
||||||
|
squares_starting_transition = std::min(squares_starting_transition, total_squares);
|
||||||
|
|
||||||
|
for (int i = 0; i < squares_starting_transition; ++i) {
|
||||||
|
if (square_age_[i] == -1) {
|
||||||
|
square_age_[i] = elapsed_time; // Empieza la transición a transparente
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drawRandomSquares2();
|
||||||
|
|
||||||
|
value_ = calculateValue(0, total_squares, squares_to_activate);
|
||||||
|
|
||||||
|
// Comprueba si ha terminado - todos los cuadrados han completado su transición
|
||||||
|
bool all_completed = (squares_to_activate >= total_squares);
|
||||||
|
if (all_completed) {
|
||||||
|
// Verificar que todos han completado su transición individual
|
||||||
|
for (int i = 0; i < total_squares; ++i) {
|
||||||
|
if (square_age_[i] >= 0) { // Cuadrado activado
|
||||||
|
Uint32 square_elapsed = elapsed_time - square_age_[i];
|
||||||
|
if (square_elapsed < static_cast<Uint32>(square_transition_duration_)) {
|
||||||
|
all_completed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (all_completed) {
|
||||||
|
// Pintar textura final: OUT opaca, IN transparente
|
||||||
|
Uint8 final_alpha = (mode_ == Mode::OUT) ? 255 : 0;
|
||||||
|
cleanBackbuffer(r_, g_, b_, final_alpha);
|
||||||
|
changeToPostState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Fade::drawRandomSquares(int active_count) {
|
||||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||||
SDL_SetRenderTarget(renderer_, backbuffer_);
|
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||||
|
|
||||||
@@ -173,13 +272,56 @@ void Fade::drawRandomSquares() {
|
|||||||
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE);
|
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_NONE);
|
||||||
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
|
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, a_);
|
||||||
|
|
||||||
const int INDEX = std::min(counter_ / fade_random_squares_delay_,
|
// Dibuja solo los cuadrados activos
|
||||||
(num_squares_width_ * num_squares_height_) - 1);
|
for (int i = 0; i < active_count && i < static_cast<int>(square_.size()); ++i) {
|
||||||
|
SDL_RenderFillRect(renderer_, &square_[i]);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < fade_random_squares_mult_; ++i) {
|
SDL_SetRenderDrawBlendMode(renderer_, blend_mode);
|
||||||
const int INDEX2 = std::min((INDEX * fade_random_squares_mult_) + i,
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
static_cast<int>(square_.size()) - 1);
|
}
|
||||||
SDL_RenderFillRect(renderer_, &square_[INDEX2]);
|
|
||||||
|
void Fade::drawRandomSquares2() {
|
||||||
|
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||||
|
SDL_SetRenderTarget(renderer_, backbuffer_);
|
||||||
|
|
||||||
|
// CRÍTICO: Limpiar la textura antes de dibujar
|
||||||
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||||
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
|
SDL_BlendMode blend_mode;
|
||||||
|
SDL_GetRenderDrawBlendMode(renderer_, &blend_mode);
|
||||||
|
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND); // Usar BLEND para alpha
|
||||||
|
|
||||||
|
Uint32 current_time = SDL_GetTicks() - random_squares_start_time_;
|
||||||
|
|
||||||
|
// Lógica unificada: sobre textura transparente, pintar cuadrados según su estado
|
||||||
|
for (size_t i = 0; i < square_.size(); ++i) {
|
||||||
|
Uint8 current_alpha = 0;
|
||||||
|
|
||||||
|
if (square_age_[i] == -1) {
|
||||||
|
// Cuadrado no activado
|
||||||
|
if (mode_ == Mode::OUT) {
|
||||||
|
current_alpha = 0; // OUT: transparente si no activado
|
||||||
|
} else {
|
||||||
|
current_alpha = a_; // IN: opaco si no activado
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Cuadrado activado - calculamos progreso
|
||||||
|
Uint32 square_elapsed = current_time - square_age_[i];
|
||||||
|
float progress = std::min(static_cast<float>(square_elapsed) / square_transition_duration_, 1.0f);
|
||||||
|
|
||||||
|
if (mode_ == Mode::OUT) {
|
||||||
|
current_alpha = static_cast<Uint8>(progress * a_); // 0 → 255
|
||||||
|
} else {
|
||||||
|
current_alpha = static_cast<Uint8>((1.0f - progress) * a_); // 255 → 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_alpha > 0) {
|
||||||
|
SDL_SetRenderDrawColor(renderer_, r_, g_, b_, current_alpha);
|
||||||
|
SDL_RenderFillRect(renderer_, &square_[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer_, blend_mode);
|
SDL_SetRenderDrawBlendMode(renderer_, blend_mode);
|
||||||
@@ -192,7 +334,7 @@ void Fade::updateVenetianFade() {
|
|||||||
updateVenetianRectangles();
|
updateVenetianRectangles();
|
||||||
calculateVenetianProgress();
|
calculateVenetianProgress();
|
||||||
} else {
|
} else {
|
||||||
state_ = State::POST;
|
changeToPostState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,8 +381,7 @@ void Fade::activate() {
|
|||||||
|
|
||||||
state_ = State::PRE;
|
state_ = State::PRE;
|
||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
post_counter_ = 0;
|
pre_start_time_ = SDL_GetTicks();
|
||||||
pre_counter_ = 0;
|
|
||||||
|
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case Type::FULLSCREEN: {
|
case Type::FULLSCREEN: {
|
||||||
@@ -284,6 +425,49 @@ void Fade::activate() {
|
|||||||
// Deja el color listo para usar
|
// Deja el color listo para usar
|
||||||
a_ = mode_ == Mode::OUT ? 255 : 0;
|
a_ = mode_ == Mode::OUT ? 255 : 0;
|
||||||
|
|
||||||
|
// Inicializa el tiempo de inicio
|
||||||
|
random_squares_start_time_ = SDL_GetTicks();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Type::RANDOM_SQUARE2: {
|
||||||
|
rect1_ = {.x = 0, .y = 0, .w = static_cast<float>(param.game.width / num_squares_width_), .h = static_cast<float>(param.game.height / num_squares_height_)};
|
||||||
|
square_.clear();
|
||||||
|
square_age_.clear();
|
||||||
|
|
||||||
|
// Añade los cuadrados al vector
|
||||||
|
for (int i = 0; i < num_squares_width_ * num_squares_height_; ++i) {
|
||||||
|
rect1_.x = (i % num_squares_width_) * rect1_.w;
|
||||||
|
rect1_.y = (i / num_squares_width_) * rect1_.h;
|
||||||
|
square_.push_back(rect1_);
|
||||||
|
square_age_.push_back(-1); // -1 indica cuadrado no activado aún
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desordena el vector de cuadrados y edades
|
||||||
|
auto num = num_squares_width_ * num_squares_height_;
|
||||||
|
while (num > 1) {
|
||||||
|
auto num_arreu = rand() % num;
|
||||||
|
SDL_FRect temp_rect = square_[num_arreu];
|
||||||
|
int temp_age = square_age_[num_arreu];
|
||||||
|
square_[num_arreu] = square_[num - 1];
|
||||||
|
square_age_[num_arreu] = square_age_[num - 1];
|
||||||
|
square_[num - 1] = temp_rect;
|
||||||
|
square_age_[num - 1] = temp_age;
|
||||||
|
num--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Textura inicial: OUT transparente, IN opaca
|
||||||
|
Uint8 initial_alpha = (mode_ == Mode::OUT) ? 0 : 255;
|
||||||
|
cleanBackbuffer(r_, g_, b_, initial_alpha);
|
||||||
|
|
||||||
|
// Deja el color listo para usar (alpha target para los cuadrados)
|
||||||
|
a_ = 255; // Siempre usar 255 como alpha target
|
||||||
|
|
||||||
|
// Inicializa el tiempo de inicio y recalcula la duración de transición
|
||||||
|
random_squares_start_time_ = SDL_GetTicks();
|
||||||
|
square_transition_duration_ = std::max(random_squares_duration_ / 4, 100); // Mínimo 100ms
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ class Fade {
|
|||||||
FULLSCREEN = 0, // Fundido de pantalla completa
|
FULLSCREEN = 0, // Fundido de pantalla completa
|
||||||
CENTER = 1, // Fundido desde el centro
|
CENTER = 1, // Fundido desde el centro
|
||||||
RANDOM_SQUARE = 2, // Fundido con cuadrados aleatorios
|
RANDOM_SQUARE = 2, // Fundido con cuadrados aleatorios
|
||||||
VENETIAN = 3, // Fundido tipo persiana veneciana
|
RANDOM_SQUARE2 = 3, // Fundido con cuadrados aleatorios (variante 2)
|
||||||
|
VENETIAN = 4, // Fundido tipo persiana veneciana
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Mode : Uint8 {
|
enum class Mode : Uint8 {
|
||||||
@@ -45,8 +46,8 @@ class Fade {
|
|||||||
void setColor(Color color); // Establece el color del fade
|
void setColor(Color color); // Establece el color del fade
|
||||||
void setType(Type type) { type_ = type; } // Establece el tipo de fade
|
void setType(Type type) { type_ = type; } // Establece el tipo de fade
|
||||||
void setMode(Mode mode) { mode_ = mode; } // Establece el modo de fade
|
void setMode(Mode mode) { mode_ = mode; } // Establece el modo de fade
|
||||||
void setPostDuration(int value) { post_duration_ = value; } // Duración posterior al fade
|
void setPostDuration(int value) { post_duration_ = value; } // Duración posterior al fade en milisegundos
|
||||||
void setPreDuration(int value) { pre_duration_ = value; } // Duración previa al fade
|
void setPreDuration(int value) { pre_duration_ = value; } // Duración previa al fade en milisegundos
|
||||||
|
|
||||||
// --- Getters ---
|
// --- Getters ---
|
||||||
[[nodiscard]] auto getValue() const -> int { return value_; }
|
[[nodiscard]] auto getValue() const -> int { return value_; }
|
||||||
@@ -60,6 +61,7 @@ class Fade {
|
|||||||
|
|
||||||
// --- Variables de estado ---
|
// --- Variables de estado ---
|
||||||
std::vector<SDL_FRect> square_; // Vector de cuadrados
|
std::vector<SDL_FRect> square_; // Vector de cuadrados
|
||||||
|
std::vector<int> square_age_; // Edad de cada cuadrado (para RANDOM_SQUARE2)
|
||||||
SDL_FRect rect1_, rect2_; // Rectángulos para efectos
|
SDL_FRect rect1_, rect2_; // Rectángulos para efectos
|
||||||
Type type_; // Tipo de fade
|
Type type_; // Tipo de fade
|
||||||
Mode mode_; // Modo de fade
|
Mode mode_; // Modo de fade
|
||||||
@@ -68,12 +70,13 @@ class Fade {
|
|||||||
Uint8 r_, g_, b_, a_; // Color del fade (RGBA)
|
Uint8 r_, g_, b_, a_; // Color del fade (RGBA)
|
||||||
int num_squares_width_; // Cuadrados en horizontal
|
int num_squares_width_; // Cuadrados en horizontal
|
||||||
int num_squares_height_; // Cuadrados en vertical
|
int num_squares_height_; // Cuadrados en vertical
|
||||||
int fade_random_squares_delay_; // Delay entre cuadrados
|
Uint32 random_squares_start_time_; // Tiempo de inicio del fade de cuadrados
|
||||||
int fade_random_squares_mult_; // Cuadrados por paso
|
int random_squares_duration_; // Duración total en milisegundos
|
||||||
int post_duration_ = 0; // Duración posterior
|
int square_transition_duration_; // Duración de transición de cada cuadrado en ms
|
||||||
int post_counter_ = 0; // Contador posterior
|
int post_duration_ = 0; // Duración posterior en milisegundos
|
||||||
int pre_duration_ = 0; // Duración previa
|
Uint32 post_start_time_ = 0; // Tiempo de inicio del estado POST
|
||||||
int pre_counter_ = 0; // Contador previo
|
int pre_duration_ = 0; // Duración previa en milisegundos
|
||||||
|
Uint32 pre_start_time_ = 0; // Tiempo de inicio del estado PRE
|
||||||
int value_ = 0; // Estado del fade (0-100)
|
int value_ = 0; // Estado del fade (0-100)
|
||||||
|
|
||||||
// --- Inicialización y limpieza ---
|
// --- Inicialización y limpieza ---
|
||||||
@@ -87,17 +90,20 @@ class Fade {
|
|||||||
void updatePreState(); // Actualiza el estado previo al fade
|
void updatePreState(); // Actualiza el estado previo al fade
|
||||||
void updateFadingState(); // Actualiza el estado durante el fade
|
void updateFadingState(); // Actualiza el estado durante el fade
|
||||||
void updatePostState(); // Actualiza el estado posterior al fade
|
void updatePostState(); // Actualiza el estado posterior al fade
|
||||||
|
void changeToPostState(); // Cambia al estado POST e inicializa el tiempo
|
||||||
|
|
||||||
// --- Efectos de fundido (fade) ---
|
// --- Efectos de fundido (fade) ---
|
||||||
void updateFullscreenFade(); // Actualiza el fundido de pantalla completa
|
void updateFullscreenFade(); // Actualiza el fundido de pantalla completa
|
||||||
void updateCenterFade(); // Actualiza el fundido desde el centro
|
void updateCenterFade(); // Actualiza el fundido desde el centro
|
||||||
void updateRandomSquareFade(); // Actualiza el fundido con cuadrados aleatorios
|
void updateRandomSquareFade(); // Actualiza el fundido con cuadrados aleatorios
|
||||||
|
void updateRandomSquare2Fade(); // Actualiza el fundido con cuadrados aleatorios (variante 2)
|
||||||
void updateVenetianFade(); // Actualiza el fundido tipo persiana veneciana
|
void updateVenetianFade(); // Actualiza el fundido tipo persiana veneciana
|
||||||
void updateVenetianRectangles(); // Actualiza los rectángulos del efecto veneciano
|
void updateVenetianRectangles(); // Actualiza los rectángulos del efecto veneciano
|
||||||
void calculateVenetianProgress(); // Calcula el progreso del efecto veneciano
|
void calculateVenetianProgress(); // Calcula el progreso del efecto veneciano
|
||||||
|
|
||||||
// --- Dibujo de efectos visuales ---
|
// --- Dibujo de efectos visuales ---
|
||||||
void drawCenterFadeRectangles(); // Dibuja los rectángulos del fundido central
|
void drawCenterFadeRectangles(); // Dibuja los rectángulos del fundido central
|
||||||
void drawRandomSquares(); // Dibuja los cuadrados aleatorios del fundido
|
void drawRandomSquares(int active_count = -1); // Dibuja los cuadrados aleatorios del fundido
|
||||||
|
void drawRandomSquares2(); // Dibuja los cuadrados con transición de color (RANDOM_SQUARE2)
|
||||||
void drawVenetianBlinds(); // Dibuja las persianas venecianas del fundido
|
void drawVenetianBlinds(); // Dibuja las persianas venecianas del fundido
|
||||||
};
|
};
|
||||||
@@ -97,9 +97,8 @@ auto setParams(const std::string& var, const std::string& value) -> bool {
|
|||||||
{"game.hit_stop_ms", [](const std::string& v) { param.game.hit_stop_ms = std::stoi(v); }},
|
{"game.hit_stop_ms", [](const std::string& v) { param.game.hit_stop_ms = std::stoi(v); }},
|
||||||
{"fade.num_squares_width", [](const std::string& v) { param.fade.num_squares_width = std::stoi(v); }},
|
{"fade.num_squares_width", [](const std::string& v) { param.fade.num_squares_width = std::stoi(v); }},
|
||||||
{"fade.num_squares_height", [](const std::string& v) { param.fade.num_squares_height = std::stoi(v); }},
|
{"fade.num_squares_height", [](const std::string& v) { param.fade.num_squares_height = std::stoi(v); }},
|
||||||
{"fade.random_squares_delay", [](const std::string& v) { param.fade.random_squares_delay = std::stoi(v); }},
|
{"fade.random_squares_duration_ms", [](const std::string& v) { param.fade.random_squares_duration_ms = std::stoi(v); }},
|
||||||
{"fade.random_squares_mult", [](const std::string& v) { param.fade.random_squares_mult = std::stoi(v); }},
|
{"fade.post_duration_ms", [](const std::string& v) { param.fade.post_duration_ms = std::stoi(v); }},
|
||||||
{"fade.post_duration", [](const std::string& v) { param.fade.post_duration = std::stoi(v); }},
|
|
||||||
{"fade.venetian_size", [](const std::string& v) { param.fade.venetian_size = std::stoi(v); }},
|
{"fade.venetian_size", [](const std::string& v) { param.fade.venetian_size = std::stoi(v); }},
|
||||||
{"scoreboard.rect.x", [](const std::string& v) { param.scoreboard.rect.x = std::stoi(v); }},
|
{"scoreboard.rect.x", [](const std::string& v) { param.scoreboard.rect.x = std::stoi(v); }},
|
||||||
{"scoreboard.rect.y", [](const std::string& v) { param.scoreboard.rect.y = std::stoi(v); }},
|
{"scoreboard.rect.y", [](const std::string& v) { param.scoreboard.rect.y = std::stoi(v); }},
|
||||||
|
|||||||
@@ -30,9 +30,8 @@ struct ParamFade {
|
|||||||
Color color = Color::fromHex(GameDefaults::Fade::COLOR);
|
Color color = Color::fromHex(GameDefaults::Fade::COLOR);
|
||||||
float num_squares_width = GameDefaults::Fade::NUM_SQUARES_WIDTH;
|
float num_squares_width = GameDefaults::Fade::NUM_SQUARES_WIDTH;
|
||||||
float num_squares_height = GameDefaults::Fade::NUM_SQUARES_HEIGHT;
|
float num_squares_height = GameDefaults::Fade::NUM_SQUARES_HEIGHT;
|
||||||
int random_squares_delay = GameDefaults::Fade::RANDOM_SQUARES_DELAY;
|
int random_squares_duration_ms = GameDefaults::Fade::RANDOM_SQUARES_DURATION_MS;
|
||||||
int random_squares_mult = GameDefaults::Fade::RANDOM_SQUARES_MULT;
|
int post_duration_ms = GameDefaults::Fade::POST_DURATION_MS;
|
||||||
int post_duration = GameDefaults::Fade::POST_DURATION;
|
|
||||||
float venetian_size = GameDefaults::Fade::VENETIAN_SIZE;
|
float venetian_size = GameDefaults::Fade::VENETIAN_SIZE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -68,14 +68,14 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
|||||||
scoreboard_ = Scoreboard::get();
|
scoreboard_ = Scoreboard::get();
|
||||||
|
|
||||||
fade_in_->setColor(param.fade.color);
|
fade_in_->setColor(param.fade.color);
|
||||||
fade_in_->setPreDuration(demo_.enabled ? 80 : 0);
|
fade_in_->setPreDuration(demo_.enabled ? 500 : 0);
|
||||||
fade_in_->setPostDuration(0);
|
fade_in_->setPostDuration(0);
|
||||||
fade_in_->setType(Fade::Type::RANDOM_SQUARE);
|
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_in_->setMode(Fade::Mode::IN);
|
fade_in_->setMode(Fade::Mode::IN);
|
||||||
fade_in_->activate();
|
fade_in_->activate();
|
||||||
|
|
||||||
fade_out_->setColor(param.fade.color);
|
fade_out_->setColor(param.fade.color);
|
||||||
fade_out_->setPostDuration(param.fade.post_duration);
|
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
||||||
fade_out_->setType(Fade::Type::VENETIAN);
|
fade_out_->setType(Fade::Type::VENETIAN);
|
||||||
|
|
||||||
background_->setPos(param.game.play_area.rect);
|
background_->setPos(param.game.play_area.rect);
|
||||||
@@ -219,7 +219,8 @@ void Game::updatePlayers() {
|
|||||||
handlePlayerCollision(player, balloon);
|
handlePlayerCollision(player, balloon);
|
||||||
|
|
||||||
if (demo_.enabled && allPlayersAreNotPlaying()) {
|
if (demo_.enabled && allPlayersAreNotPlaying()) {
|
||||||
fade_out_->setType(Fade::Type::RANDOM_SQUARE);
|
fade_out_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
|
fade_out_->setPostDuration(500);
|
||||||
fade_out_->activate();
|
fade_out_->activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1651,7 +1652,7 @@ void Game::updateDemo() {
|
|||||||
|
|
||||||
// Activa el fundido antes de acabar con los datos de la demo
|
// Activa el fundido antes de acabar con los datos de la demo
|
||||||
if (demo_.counter == TOTAL_DEMO_DATA - 200) {
|
if (demo_.counter == TOTAL_DEMO_DATA - 200) {
|
||||||
fade_out_->setType(Fade::Type::RANDOM_SQUARE);
|
fade_out_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_out_->activate();
|
fade_out_->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -264,8 +264,8 @@ void HiScoreTable::updateSprites() {
|
|||||||
// Inicializa el fade
|
// Inicializa el fade
|
||||||
void HiScoreTable::initFade() {
|
void HiScoreTable::initFade() {
|
||||||
fade_->setColor(param.fade.color);
|
fade_->setColor(param.fade.color);
|
||||||
fade_->setType(Fade::Type::RANDOM_SQUARE);
|
fade_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_->setPostDuration(param.fade.post_duration);
|
fade_->setPostDuration(param.fade.post_duration_ms);
|
||||||
fade_->setMode(fade_mode_);
|
fade_->setMode(fade_mode_);
|
||||||
fade_->activate();
|
fade_->activate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Instructions::Instructions()
|
|||||||
tiled_bg_->setColor(param.title.bg_color);
|
tiled_bg_->setColor(param.title.bg_color);
|
||||||
fade_->setColor(param.fade.color);
|
fade_->setColor(param.fade.color);
|
||||||
fade_->setType(Fade::Type::FULLSCREEN);
|
fade_->setType(Fade::Type::FULLSCREEN);
|
||||||
fade_->setPostDuration(param.fade.post_duration);
|
fade_->setPostDuration(param.fade.post_duration_ms);
|
||||||
fade_->setMode(Fade::Mode::IN);
|
fade_->setMode(Fade::Mode::IN);
|
||||||
fade_->activate();
|
fade_->activate();
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ Title::Title()
|
|||||||
game_logo_->enable();
|
game_logo_->enable();
|
||||||
mini_logo_sprite_->setX(param.game.game_area.center_x - (mini_logo_sprite_->getWidth() / 2));
|
mini_logo_sprite_->setX(param.game.game_area.center_x - (mini_logo_sprite_->getWidth() / 2));
|
||||||
fade_->setColor(param.fade.color);
|
fade_->setColor(param.fade.color);
|
||||||
fade_->setType(Fade::Type::RANDOM_SQUARE);
|
fade_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_->setPostDuration(param.fade.post_duration);
|
fade_->setPostDuration(param.fade.post_duration_ms);
|
||||||
initPlayers();
|
initPlayers();
|
||||||
|
|
||||||
// Asigna valores a otras variables
|
// Asigna valores a otras variables
|
||||||
|
|||||||
Reference in New Issue
Block a user