Afegit efecte de fundit a negre per a la paleta principal i per a la secundaria. Implementat en Title
This commit is contained in:
@@ -21,7 +21,7 @@ Logo::Logo()
|
||||
{
|
||||
since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight());
|
||||
since_1998_color_ = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
jailgames_color_ = static_cast<Uint8>(PaletteColor::WHITE);
|
||||
jailgames_color_ = static_cast<Uint8>(PaletteColor::BRIGHT_WHITE);
|
||||
|
||||
// Crea los sprites de cada linea
|
||||
for (int i = 0; i < jailgames_surface_->getHeight(); ++i)
|
||||
|
||||
@@ -104,13 +104,15 @@ Palette readPalFile(const std::string &file_path)
|
||||
// Constructor
|
||||
Surface::Surface(int w, int h)
|
||||
: surface_data_(std::make_shared<SurfaceData>(w, h)),
|
||||
transparent_color_(static_cast<Uint8>(PaletteColor::TRANSPARENT)) {}
|
||||
transparent_color_(static_cast<Uint8>(PaletteColor::TRANSPARENT)) { initializeSubPalette(sub_palette_); }
|
||||
|
||||
Surface::Surface(const std::string &file_path)
|
||||
: transparent_color_(static_cast<Uint8>(PaletteColor::TRANSPARENT))
|
||||
{
|
||||
SurfaceData loadedData = loadSurface(file_path);
|
||||
surface_data_ = std::make_shared<SurfaceData>(std::move(loadedData));
|
||||
|
||||
initializeSubPalette(sub_palette_);
|
||||
}
|
||||
|
||||
// Carga una superficie desde un archivo
|
||||
@@ -307,7 +309,7 @@ void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
||||
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
|
||||
if (color != transparent_color_)
|
||||
{
|
||||
surface_data->data[dest_x + dest_y * surface_data->width] = color;
|
||||
surface_data->data[dest_x + dest_y * surface_data->width] = sub_palette_[color];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,7 +356,7 @@ void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
|
||||
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
|
||||
if (color != transparent_color_)
|
||||
{
|
||||
surface_data_dest->data[dest_x + dest_y * surface_data_dest->width] = color;
|
||||
surface_data_dest->data[dest_x + dest_y * surface_data_dest->width] = sub_palette_[color];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -411,7 +413,7 @@ void Surface::render(SDL_Rect *srcRect, SDL_Rect *dstRect, SDL_RendererFlip flip
|
||||
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
|
||||
if (color != transparent_color_)
|
||||
{
|
||||
surface_data->data[dest_x + dest_y * surface_data->width] = color;
|
||||
surface_data->data[dest_x + dest_y * surface_data->width] = sub_palette_[color];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -508,7 +510,7 @@ void Surface::copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
}
|
||||
}
|
||||
|
||||
// Realiza un efecto de fundido en la paleta
|
||||
// Realiza un efecto de fundido en la paleta principal
|
||||
bool Surface::fadePalette()
|
||||
{
|
||||
// Verificar que el tamaño mínimo de palette_ sea adecuado
|
||||
@@ -530,3 +532,26 @@ bool Surface::fadePalette()
|
||||
// Devolver si el índice 15 coincide con el índice 0
|
||||
return palette_[15] == palette_[0];
|
||||
}
|
||||
|
||||
// Realiza un efecto de fundido en la paleta secundaria
|
||||
bool Surface::fadeSubPalette()
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
throw std::runtime_error("Palette size is insufficient for fadePalette operation.");
|
||||
}
|
||||
|
||||
// Desplazar colores (pares e impares)
|
||||
for (int i = 18; i > 1; --i)
|
||||
{
|
||||
sub_palette_[i] = sub_palette_[i - 2];
|
||||
}
|
||||
|
||||
// Ajustar el primer color
|
||||
sub_palette_[1] = sub_palette_[0];
|
||||
|
||||
// Devolver si el índice 15 coincide con el índice 0
|
||||
return sub_palette_[15] == sub_palette_[0];
|
||||
}
|
||||
@@ -3,11 +3,13 @@
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// Alias
|
||||
using Palette = std::array<Uint32, 256>;
|
||||
using SubPalette = std::array<Uint8, 256>;
|
||||
|
||||
// Carga una paleta desde un archivo .gif
|
||||
Palette loadPalette(const std::string &file_path);
|
||||
@@ -71,6 +73,7 @@ class Surface
|
||||
private:
|
||||
std::shared_ptr<SurfaceData> surface_data_; // Datos a dibujar
|
||||
Palette palette_; // Paleta para volcar la SurfaceData a una Textura
|
||||
SubPalette sub_palette_; // Paleta para reindexar colores
|
||||
int transparent_color_; // Indice de la paleta que se omite en la copia de datos
|
||||
|
||||
public:
|
||||
@@ -105,8 +108,9 @@ public:
|
||||
// Vuelca la SurfaceData a una textura
|
||||
void copyToTexture(SDL_Renderer *renderer, SDL_Texture *texture);
|
||||
|
||||
// Realiza un efecto de fundido en la paleta
|
||||
// Realiza un efecto de fundido en las paletas
|
||||
bool fadePalette();
|
||||
bool fadeSubPalette();
|
||||
|
||||
// Pone un pixel en la SurfaceData
|
||||
void putPixel(int x, int y, Uint8 color);
|
||||
@@ -137,4 +141,7 @@ public:
|
||||
|
||||
// Paleta
|
||||
void setPalette(const std::array<Uint32, 256> &palette) { palette_ = palette; }
|
||||
|
||||
// Inicializa la sub paleta
|
||||
void initializeSubPalette(SubPalette &palette) { std::iota(palette.begin(), palette.end(), 0); }
|
||||
};
|
||||
|
||||
@@ -202,7 +202,7 @@ void Title::update()
|
||||
case TitleState::FADE_LOADING_SCREEN:
|
||||
if (counter_ % 4 == 0)
|
||||
{
|
||||
if (true) // poner aqui la condicion de "fin de fade = true"
|
||||
if (loading_screen_surface_->fadeSubPalette())
|
||||
{
|
||||
counter_ = 0;
|
||||
state_ = TitleState::SHOW_MENU;
|
||||
|
||||
Reference in New Issue
Block a user