Afegit efecte de fundit a negre per a la paleta principal i per a la secundaria. Implementat en Title

This commit is contained in:
2025-03-07 14:32:35 +01:00
parent 529bfb5e3a
commit 09ac952404
4 changed files with 40 additions and 8 deletions

View File

@@ -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
@@ -529,4 +531,27 @@ 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];
}