arreglada la logica d'estats en Ending2

This commit is contained in:
2025-03-21 13:24:32 +01:00
parent 0f8de0d8b5
commit 428fe664bd
5 changed files with 155 additions and 82 deletions

View File

@@ -1,7 +1,8 @@
// IWYU pragma: no_include <bits/std_abs.h>
#include "surface.h"
#include <SDL2/SDL_error.h> // Para SDL_GetError
#include <bits/std_abs.h> // Para abs
#include <stdlib.h> // Para abs
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
#include <cmath> // Para abs
#include <algorithm> // Para min, max, copy_n, fill
#include <cstdint> // Para uint32_t
#include <cstring> // Para memcpy, size_t
@@ -179,7 +180,7 @@ void Surface::setColor(int index, Uint32 color)
void Surface::clear(Uint8 color)
{
const size_t total_pixels = surface_data_->width * surface_data_->height;
Uint8* data_ptr = surface_data_->data.get();
Uint8 *data_ptr = surface_data_->data.get();
std::fill(data_ptr, data_ptr + total_pixels, color);
}
@@ -566,7 +567,6 @@ void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Re
}
}
// Realiza un efecto de fundido en la paleta principal
bool Surface::fadePalette()
{
@@ -591,8 +591,23 @@ bool Surface::fadePalette()
}
// Realiza un efecto de fundido en la paleta secundaria
bool Surface::fadeSubPalette()
bool Surface::fadeSubPalette(Uint32 delay)
{
// Variable estática para almacenar el último tick
static Uint32 last_tick = 0;
// Obtener el tiempo actual
Uint32 current_tick = SDL_GetTicks();
// Verificar si ha pasado el tiempo de retardo
if (current_tick - last_tick < delay)
{
return false; // No se realiza el fade
}
// Actualizar el último tick
last_tick = current_tick;
// Verificar que el tamaño mínimo de sub_palette_ sea adecuado
static constexpr int sub_palette_size = 19;
if (sizeof(sub_palette_) / sizeof(sub_palette_[0]) < sub_palette_size)
@@ -611,4 +626,4 @@ bool Surface::fadeSubPalette()
// Devolver si el índice 15 coincide con el índice 0
return sub_palette_[15] == sub_palette_[0];
}
}