Canviades les paletes dels .gif

Ara es poden carregar paletes desde fitxers .pal
Reajustada la pleta general
fix: la pantalla de càrrega deixava un pixel per pintar, desde sempre
Ajustat el color del borde en el Logo i el Title per a ser igual al fondo amb les paletes de 16 colors (la del Spectrum es de 15)
This commit is contained in:
2025-03-06 20:04:53 +01:00
parent d0e06e30c9
commit d339fb13b0
46 changed files with 478 additions and 154 deletions

View File

@@ -26,7 +26,7 @@ Credits::Credits()
shining_sprite_->setPos({194, 174, 8, 8});
// Cambia el color del borde
Screen::get()->setBorderColor(stringToColor("black"));
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
// Crea la textura para el texto que se escribe en pantalla
text_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
@@ -76,62 +76,62 @@ void Credits::iniTexts()
}
texts_.clear();
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"INSTRUCTIONS:", stringToColor("yellow")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor("white")});
texts_.push_back({"HIS PROJECTS AND GO TO THE", stringToColor("white")});
texts_.push_back({"JAIL TO FINISH THEM", stringToColor("white")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"INSTRUCTIONS:", static_cast<Uint8>(PaletteColor::YELLOW)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"HELP JAILDOC TO GET BACK ALL", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"HIS PROJECTS AND GO TO THE", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"JAIL TO FINISH THEM", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"KEYS:", stringToColor("yellow")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({keys + " TO MOVE AND JUMP", stringToColor("white")});
texts_.push_back({"M TO SWITCH THE MUSIC", stringToColor("white")});
texts_.push_back({"H TO PAUSE THE GAME", stringToColor("white")});
texts_.push_back({"F1-F2 TO CHANGE WINDOWS SIZE", stringToColor("white")});
texts_.push_back({"F3 TO SWITCH TO FULLSCREEN", stringToColor("white")});
texts_.push_back({"B TO TOOGLE THE BORDER SCREEN", stringToColor("white")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"KEYS:", static_cast<Uint8>(PaletteColor::YELLOW)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({keys + " TO MOVE AND JUMP", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"M TO SWITCH THE MUSIC", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"H TO PAUSE THE GAME", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"F1-F2 TO CHANGE WINDOWS SIZE", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"F3 TO SWITCH TO FULLSCREEN", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"B TO TOOGLE THE BORDER SCREEN", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"A GAME BY JAILDESIGNER", stringToColor("yellow")});
texts_.push_back({"MADE ON SUMMER/FALL 2022", stringToColor("yellow")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"A GAME BY JAILDESIGNER", static_cast<Uint8>(PaletteColor::YELLOW)});
texts_.push_back({"MADE ON SUMMER/FALL 2022", static_cast<Uint8>(PaletteColor::YELLOW)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"I LOVE JAILGAMES! ", stringToColor("white")});
texts_.push_back({"", stringToColor("white")});
texts_.push_back({"I LOVE JAILGAMES! ", static_cast<Uint8>(PaletteColor::WHITE)});
texts_.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
#else
texts.clear();
texts.push_back({"", stringToColor("white")});
texts.push_back({"INSTRUCTIONS:", stringToColor("yellow")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor("white")});
texts.push_back({"HIS PROJECTS AND GO TO THE", stringToColor("white")});
texts.push_back({"JAIL TO FINISH THEM", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"INSTRUCTIONS:", static_cast<Uint8>(PaletteColor::YELLOW)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"HELP JAILDOC TO GET BACK ALL", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"HIS PROJECTS AND GO TO THE", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"JAIL TO FINISH THEM", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"KEYS:", stringToColor("yellow")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"B TO JUMP", stringToColor("white")});
texts.push_back({"R TO SWITCH THE MUSIC", stringToColor("white")});
texts.push_back({"L TO SWAP THE COLOR PALETTE", stringToColor("white")});
texts.push_back({"START TO PAUSE", stringToColor("white")});
texts.push_back({"SELECT TO EXIT", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"KEYS:", static_cast<Uint8>(PaletteColor::YELLOW)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"B TO JUMP", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"R TO SWITCH THE MUSIC", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"L TO SWAP THE COLOR PALETTE", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"START TO PAUSE", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"SELECT TO EXIT", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"A GAME BY JAILDESIGNER", stringToColor("yellow")});
texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor("yellow")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"A GAME BY JAILDESIGNER", static_cast<Uint8>(PaletteColor::YELLOW)});
texts.push_back({"MADE ON SUMMER/FALL 2022", static_cast<Uint8>(PaletteColor::YELLOW)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"I LOVE JAILGAMES! ", stringToColor("white")});
texts.push_back({"", stringToColor("white")});
texts.push_back({"I LOVE JAILGAMES! ", static_cast<Uint8>(PaletteColor::WHITE)});
texts.push_back({"", static_cast<Uint8>(PaletteColor::WHITE)});
#endif
}
@@ -144,7 +144,7 @@ void Credits::fillTexture()
// Rellena la textura de texto
auto previuos_renderer = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(text_surface_);
text_surface_->clear(stringToColor("black"));
text_surface_->clear(static_cast<Uint8>(PaletteColor::BLACK));
auto text = Resource::get()->getText("smb2");
@@ -161,17 +161,17 @@ void Credits::fillTexture()
// Escribe el corazón
const int TEXT_LENGHT = text->lenght(texts_[22].label, 1) - text->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio
const int POS_X = ((PLAY_AREA_WIDTH - TEXT_LENGHT) / 2) + TEXT_LENGHT;
text->writeColored(POS_X, 176, "}", stringToColor("bright_red"));
text->writeColored(POS_X, 176, "}", static_cast<Uint8>(PaletteColor::BRIGHT_RED));
// Recoloca el sprite del brillo
shining_sprite_->setPosX(POS_X + 2);
// Rellena la textura que cubre el texto con color transparente
text_surface_->clear(stringToColor("transparent"));
text_surface_->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
// Los primeros 8 pixels crea una malla
auto surface = Screen::get()->getRendererSurface();
auto color = stringToColor("black");
auto color = static_cast<Uint8>(PaletteColor::BLACK);
for (int i = 0; i < 256; i += 2)
{
surface->putPixel(i, 0, color);

View File

@@ -244,7 +244,8 @@ void Director::initInput()
Input::get()->bindKey(InputAction::WINDOW_INC_ZOOM, SDL_SCANCODE_F2);
Input::get()->bindKey(InputAction::TOGGLE_VIDEOMODE, SDL_SCANCODE_F3);
Input::get()->bindKey(InputAction::TOGGLE_SHADERS, SDL_SCANCODE_F4);
Input::get()->bindKey(InputAction::TOGGLE_PALETTE, SDL_SCANCODE_F5);
Input::get()->bindKey(InputAction::NEXT_PALETTE, SDL_SCANCODE_F5);
Input::get()->bindKey(InputAction::PREVIOUS_PALETTE, SDL_SCANCODE_F6);
Input::get()->bindKey(InputAction::TOGGLE_MUSIC, SDL_SCANCODE_M);
Input::get()->bindKey(InputAction::TOGGLE_BORDER, SDL_SCANCODE_B);
@@ -263,7 +264,7 @@ void Director::initInput()
Input::get()->bindGameControllerButton(InputAction::PAUSE, SDL_CONTROLLER_BUTTON_START);
Input::get()->bindGameControllerButton(InputAction::EXIT, SDL_CONTROLLER_BUTTON_BACK);
#endif
Input::get()->bindGameControllerButton(InputAction::TOGGLE_PALETTE, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
Input::get()->bindGameControllerButton(InputAction::NEXT_PALETTE, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
Input::get()->bindGameControllerButton(InputAction::TOGGLE_MUSIC, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
Input::get()->bindGameControllerButton(InputAction::TOGGLE_BORDER, SDL_CONTROLLER_BUTTON_X);
}
@@ -395,11 +396,17 @@ bool Director::setFileList()
Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT);
// Paletas
Asset::get()->add(prefix + "/data/palette/zx-spectrum.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/zx-spectrum-adjusted.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/ruzx-spectrum.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/ruzx-spectrum-revision-2.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/zxarne-5-2.gif", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/zx-spectrum.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/zx-spectrum-adjusted.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/zxarne-5-2.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/ruzx-spectrum.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/ruzx-spectrum-revision-2.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/pico-8.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/sweetie-16.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/island-joy-16.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/lost-century.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/na16.pal", AssetType::PALETTE);
Asset::get()->add(prefix + "/data/palette/steam-lords.pal", AssetType::PALETTE);
// Shaders
Asset::get()->add(prefix + "/data/shaders/crtpi_192.glsl", AssetType::DATA);

View File

@@ -17,8 +17,7 @@
#include "s_sprite.h" // for SSprite
#include "text.h" // for Text, TEXT_STROKE
#include "surface.h" // for Surface
#include "utils.h" // for Color, stringToColor, Palette
#include "utils.h" // for Color, static_cast<Uint8>,PaletteColor::PALETTE
// Constructor
Ending::Ending()
: counter_(-1),
@@ -40,7 +39,7 @@ Ending::Ending()
iniScenes();
// Cambia el color del borde
Screen::get()->setBorderColor(stringToColor("black"));
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
// Crea la textura para cubrir el texto
cover_surface_ = std::make_shared<Surface>(options.game.width, options.game.height + 8);
@@ -84,7 +83,7 @@ void Ending::render()
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clearSurface(stringToColor("black"));
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
// Dibuja las imagenes de la escena
sprite_pics_.at(current_scene_).image_sprite->render();
@@ -167,8 +166,8 @@ void Ending::iniTexts()
const int WIDTH = text->lenght(txt.caption, 1) + 2 + 2;
const int HEIGHT = text->getCharacterSize() + 2 + 2;
auto text_color = stringToColor("white");
auto shadow_color = stringToColor("black");
auto text_color = static_cast<Uint8>(PaletteColor::WHITE);
auto shadow_color = static_cast<Uint8>(PaletteColor::BLACK);
EndingSurface st;
@@ -187,11 +186,11 @@ void Ending::iniTexts()
Screen::get()->setRendererSurface(st.cover_surface);
// Rellena la cover_surface con color transparente
st.cover_surface->clear(stringToColor("transparent"));
st.cover_surface->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
// Crea una malla de 8 pixels de alto
auto surface = Screen::get()->getRendererSurface();
auto color = stringToColor("black");
auto color = static_cast<Uint8>(PaletteColor::BLACK);
for (int i = 0; i < WIDTH; i += 2)
{
surface->putPixel(i, 0, color);
@@ -255,11 +254,11 @@ void Ending::iniPics()
Screen::get()->setRendererSurface(sp.cover_surface);
// Rellena la cover_surface con color transparente
sp.cover_surface->clear(stringToColor("transparent"));
sp.cover_surface->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
// Crea una malla en los primeros 8 pixels
auto surface = Screen::get()->getRendererSurface();
auto color = stringToColor("black");
auto color = static_cast<Uint8>(PaletteColor::BLACK);
for (int i = 0; i < WIDTH; i += 2)
{
surface->putPixel(i, 0, color);
@@ -477,10 +476,10 @@ void Ending::fillCoverTexture()
// Rellena la textura que cubre el texto con color transparente
auto previuos_renderer = Screen::get()->getRendererSurface();
Screen::get()->setRendererSurface(cover_surface_);
cover_surface_->clear(stringToColor("transparent"));
cover_surface_->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
// Los primeros 8 pixels crea una malla
const Uint8 color = stringToColor("black");
const Uint8 color = static_cast<Uint8>(PaletteColor::BLACK);
auto surface = Screen::get()->getRendererSurface();
for (int i = 0; i < 256; i += 2)
{

View File

@@ -16,8 +16,7 @@
#include "screen.h" // for Screen
#include "text.h" // for Text
#include "surface.h" // for Surface
#include "utils.h" // for Color, stringToColor
#include <iostream>
#include "utils.h" // for Color, static_cast<Uint8>
// Constructor
Ending2::Ending2()
@@ -38,7 +37,7 @@ Ending2::Ending2()
}
// Cambia el color del borde
Screen::get()->setBorderColor(stringToColor("black"));
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
// Inicializa la lista de sprites
iniSpriteList();
@@ -101,7 +100,7 @@ void Ending2::render()
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clearSurface(stringToColor("black"));
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
// Dibuja los sprites
renderSprites();
@@ -113,7 +112,7 @@ void Ending2::render()
renderTexts();
// Dibuja una trama arriba y abajo
Uint8 color = stringToColor("black");
Uint8 color = static_cast<Uint8>(PaletteColor::BLACK);
auto surface = Screen::get()->getRendererSurface();
for (int i = 0; i < 256; i += 2)
{
@@ -326,7 +325,7 @@ void Ending2::updateTexts()
// Dibuja los sprites
void Ending2::renderSprites()
{
const Uint8 colorA = stringToColor("red");
const Uint8 colorA = static_cast<Uint8>(PaletteColor::RED);
for (auto sprite : sprites_)
{
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
@@ -338,14 +337,14 @@ void Ending2::renderSprites()
}
// Pinta el ultimo elemento de otro color
const Uint8 colorB = stringToColor("white");
const Uint8 colorB = static_cast<Uint8>(PaletteColor::WHITE);
sprites_.back()->render(1, colorB);
}
// Dibuja los sprites con el texto
void Ending2::renderSpriteTexts()
{
const Uint8 color = stringToColor("white");
const Uint8 color = static_cast<Uint8>(PaletteColor::WHITE);
for (auto sprite : sprite_texts_)
{
const bool A = sprite->getRect().y + sprite->getRect().h > 0;

View File

@@ -263,10 +263,6 @@ void Game::checkDebugEvents(const SDL_Event &event)
changeRoom(room_->getRoom(BORDER_RIGHT));
break;
case SDL_SCANCODE_F6:
Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS"}, NotificationText::LEFT, 2, false, "F6");
break;
case SDL_SCANCODE_F7:
Notifier::get()->show({"ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS"}, NotificationText::LEFT, 3, false, "F7");
break;

View File

@@ -24,11 +24,6 @@ namespace globalInputs
Notifier::get()->show({code}, NotificationText::CENTER, -1, true, code);
}
}
// Cambia la paleta de colores
void switchPalette()
{
Screen::get()->nextPalette();
}
// Cambia de seccion
void skip_section()
@@ -98,9 +93,15 @@ namespace globalInputs
Notifier::get()->show({"SHADERS " + std::string(options.video.shaders ? "ENABLED" : "DISABLED")}, NotificationText::CENTER);
}
else if (Input::get()->checkInput(InputAction::TOGGLE_PALETTE, REPEAT_FALSE))
else if (Input::get()->checkInput(InputAction::NEXT_PALETTE, REPEAT_FALSE))
{
switchPalette();
Screen::get()->nextPalette();
Notifier::get()->show({"PALETTE " + options.video.palette}, NotificationText::CENTER);
}
else if (Input::get()->checkInput(InputAction::PREVIOUS_PALETTE, REPEAT_FALSE))
{
Screen::get()->previousPalette();
Notifier::get()->show({"PALETTE " + options.video.palette}, NotificationText::CENTER);
}
}

View File

@@ -35,7 +35,8 @@ enum class InputAction
TOGGLE_VIDEOMODE,
TOGGLE_BORDER,
TOGGLE_MUSIC,
TOGGLE_PALETTE,
NEXT_PALETTE,
PREVIOUS_PALETTE,
TOGGLE_SHADERS,
// Input obligatorio

View File

@@ -81,13 +81,13 @@ void LoadingScreen::updateLoad()
if (loading_first_part_)
{
// Cada 5 pasos el load_counter_ se incrementa en uno
const int numSteps = 5;
const int step = 51;
load_counter_ = counter_ / numSteps;
constexpr int NUM_STEPS = 5;
constexpr int STEPS = 51;
load_counter_ = counter_ / NUM_STEPS;
if (load_counter_ < 192)
{
load_rect_.x = step * (counter_ % numSteps);
load_rect_.x = STEPS * (counter_ % NUM_STEPS);
load_rect_.y = line_index_[load_counter_];
mono_loading_screen_sprite_->setClip(load_rect_);
mono_loading_screen_sprite_->setPosition(load_rect_);

View File

@@ -24,7 +24,7 @@ private:
int load_counter_ = 0; // Contador para controlar las cargas
bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra
int line_index_[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga
SDL_Rect load_rect_ = {0, 0, 51, 1}; // Rectangulo para dibujar la pantalla de carga
SDL_Rect load_rect_ = {0, 0, 52, 1}; // Rectangulo para dibujar la pantalla de carga
// Actualiza las variables
void update();

View File

@@ -20,7 +20,7 @@ Logo::Logo()
since_1998_sprite_(std::make_shared<SSprite>(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight()))
{
since_1998_sprite_->setClip(0, 0, since_1998_surface_->getWidth(), since_1998_surface_->getHeight());
// since_1998_surface_->setColor(0, 0, 0);
since_1998_color_ = stringToColor("black");
// Crea los sprites de cada linea
for (int i = 0; i < jailgames_surface_->getHeight(); ++i)
@@ -42,7 +42,7 @@ Logo::Logo()
}
// Cambia el color del borde
Screen::get()->setBorderColor(stringToColor("black"));
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BRIGHT_BLACK));
}
// Comprueba el manejador de eventos
@@ -219,8 +219,6 @@ void Logo::render()
{
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clearSurface();
// Dibuja los objetos

View File

@@ -20,6 +20,8 @@ private:
std::shared_ptr<Surface> since_1998_surface_; // Textura con los graficos "Since 1998"
std::vector<std::shared_ptr<SSprite>> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
std::shared_ptr<SSprite> since_1998_sprite_; // SSprite para manejar la textura2
Uint8 jailgames_color_ = 0; // Color para el sprite de "JAILGAMES"
Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998"
// Variables
std::vector<Uint8> color_; // Vector con los colores para el fade

View File

@@ -165,7 +165,7 @@ bool saveOptionsToFile(const std::string &file_path)
file << "video.border.width " << options.video.border.width << "\n\n";
file << "# Alto del borde\n";
file << "video.border.height " << options.video.border.height << "\n\n";
file << "# Paleta:\n";
file << "# Paleta\n";
file << "video.palette " << options.video.palette << "\n";
// Cierra el fichero
@@ -263,15 +263,7 @@ bool setOptions(const std::string &var, const std::string &value)
}},
{"video.palette", [](const std::string &v)
{
std::string val = v;
if (val == "arreglar" || val == "esto")
{
options.video.palette = val;
}
else
{
options.video.palette = val;
}
options.video.palette = v;
}}};
auto it = optionHandlers.find(var);

View File

@@ -634,15 +634,15 @@ void Player::setColor()
{
if (options.cheats.invincible == Cheat::CheatState::ENABLED)
{
color_ = stringToColor("cyan");
color_ = static_cast<Uint8>(PaletteColor::CYAN);
}
else if (options.cheats.infinite_lives == Cheat::CheatState::ENABLED)
{
color_ = stringToColor("yellow");
color_ = static_cast<Uint8>(PaletteColor::YELLOW);
}
else
{
color_ = stringToColor("white");
color_ = static_cast<Uint8>(PaletteColor::WHITE);
}
}

View File

@@ -254,6 +254,7 @@ void Resource::loadSurfaces()
{
auto name = getFileName(l);
surfaces_.emplace_back(ResourceSurface(name, std::make_shared<Surface>(l)));
surfaces_.back().surface->setTransparentColor(0);
updateLoadingProgress();
}
}
@@ -268,7 +269,7 @@ void Resource::loadPalettes()
for (const auto &l : list)
{
auto name = getFileName(l);
palettes_.emplace_back(ResourcePalette(name, loadPalette(l)));
palettes_.emplace_back(ResourcePalette(name, readPalFile(l)));
updateLoadingProgress();
}
}

View File

@@ -89,11 +89,11 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
// Crea la surface donde se dibujan los graficos del juego
game_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
game_surface_->loadPalette(palettes_.at(current_palette_));
game_surface_->setPalette(readPalFile(palettes_.at(current_palette_)));
// Crea la surface donde se dibujan los graficos del juego
border_surface_ = std::make_shared<Surface>(options.game.width + options.video.border.width * 2, options.game.height + options.video.border.height * 2);
border_surface_->loadPalette(palettes_.at(current_palette_));
border_surface_->setPalette(readPalFile(palettes_.at(current_palette_)));
// Establece la surface que actuará como renderer para recibir las llamadas a render()
renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_);
@@ -352,13 +352,34 @@ void Screen::nextPalette()
current_palette_ = 0;
}
setPalete();
}
// Cambia la paleta
void Screen::previousPalette()
{
if (current_palette_ > 0)
{
--current_palette_;
}
else
{
current_palette_ = static_cast<Uint8>(palettes_.size() - 1);
}
setPalete();
}
// Establece la paleta
void Screen::setPalete()
{
game_surface_->loadPalette(Resource::get()->getPalette(palettes_.at(current_palette_)));
border_surface_->loadPalette(Resource::get()->getPalette(palettes_.at(current_palette_)));
options.video.palette = palettes_.at(current_palette_);
// Eliminar ".gif"
size_t pos = options.video.palette.find(".gif");
size_t pos = options.video.palette.find(".pal");
if (pos != std::string::npos)
{
options.video.palette.erase(pos, 4);
@@ -424,7 +445,7 @@ void Screen::renderOverlays()
// Localiza la paleta dentro del vector de paletas
size_t Screen::findPalette(const std::string &name)
{
std::string upper_name = toUpper(name + ".gif");
std::string upper_name = toUpper(name + ".pal");
for (size_t i = 0; i < palettes_.size(); ++i)
{

View File

@@ -156,6 +156,10 @@ public:
// Cambia la paleta
void nextPalette();
void previousPalette();
// Establece la paleta
void setPalete();
// Establece la visibilidad de las notificaciones
void setNotificationsEnabled(bool value) { notifications_enabled_ = value; }

View File

@@ -10,8 +10,14 @@
#include "asset.h" // for Asset
#include "screen.h"
#include "gif.h" // for LoadGif, LoadPalette
#include <iostream>
#include <fstream>
#include <sstream>
#include <array>
#include <cstdint>
#include <stdexcept>
// Carga una paleta desde un archivo
// Carga una paleta desde un archivo .gif
Palette loadPalette(const std::string &file_path)
{
// Abrir el archivo en modo binario
@@ -48,13 +54,61 @@ Palette loadPalette(const std::string &file_path)
return palette;
}
// Carga una paleta desde un archivo .pal
Palette readPalFile(const std::string& file_path)
{
Palette palette{};
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
std::ifstream file(file_path);
if (!file.is_open())
{
throw std::runtime_error("No se pudo abrir el archivo .pal");
}
std::string line;
int line_number = 0;
int color_index = 0;
while (std::getline(file, line))
{
++line_number;
// Ignorar las tres primeras líneas del archivo
if (line_number <= 3)
{
continue;
}
// Procesar las líneas restantes con valores RGB
std::istringstream ss(line);
int r, g, b;
if (ss >> r >> g >> b)
{
// Construir el color ARGB (A = 255 por defecto)
Uint32 color = (255 << 24) | (r << 16) | (g << 8) | b;
palette[color_index++] = color;
// Limitar a un máximo de 256 colores (opcional)
if (color_index >= 256)
{
break;
}
}
}
file.close();
return palette;
}
// Constructor
Surface::Surface(int w, int h)
: surface_data_(std::make_shared<SurfaceData>(w, h)),
transparent_color_(0) {}
transparent_color_(static_cast<Uint8>(PaletteColor::TRANSPARENT)) {}
Surface::Surface(const std::string &file_path)
: transparent_color_(0)
: transparent_color_(static_cast<Uint8>(PaletteColor::TRANSPARENT))
{
SurfaceData loadedData = loadSurface(file_path);
surface_data_ = std::make_shared<SurfaceData>(std::move(loadedData));

View File

@@ -9,8 +9,12 @@
// Alias
using Palette = std::array<Uint32, 256>;
// Carga una paleta desde un archivo .gif
Palette loadPalette(const std::string &file_path);
// Carga una paleta desde un archivo .pal
Palette readPalFile(const std::string &file_path);
struct SurfaceData
{
Uint8 *data; // Listado de indices de la paleta que conforman la imagen almacenada
@@ -66,7 +70,7 @@ class Surface
{
private:
std::shared_ptr<SurfaceData> surface_data_; // Datos a dibujar
Palette palette_; // Paleta para volcar la SurfaceData a una Textura
Palette palette_; // Paleta para volcar la SurfaceData a una Textura
int transparent_color_; // Indice de la paleta que se omite en la copia de datos
public:
@@ -126,11 +130,11 @@ public:
// Obtien ancho y alto
int getWidth() const { return surface_data_->width; }
int getHeight() const { return surface_data_->height; }
// Color transparente
int getTransparentColor() const { return transparent_color_; }
void setTransparentColor(int color) { transparent_color_ = color; }
Uint8 getTransparentColor() const { return transparent_color_; }
void setTransparentColor(Uint8 color) { transparent_color_ = color; }
// Paleta
void setPalette(const std::array<Uint32, 256> &palette) { palette_ = palette; }
};

View File

@@ -33,8 +33,6 @@ Title::Title()
pLoadPal(Asset::get()->get("loading_screen_color.gif").c_str());
pSetSource(loading_screen_);
// title_logo_surface_->setSurfaceDataDestRaw(bg_surface_->getSurfaceData());
// Inicializa variables
state_ = options.section.subsection == Subsection::TITLE_WITH_LOADING_SCREEN ? TitleState::SHOW_LOADING_SCREEN : TitleState::SHOW_MENU;
options.section.section = Section::TITLE;
@@ -45,7 +43,7 @@ Title::Title()
createCheevosTexture();
// Cambia el color del borde
Screen::get()->setBorderColor(stringToColor("black"));
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BRIGHT_BLACK));
// Rellena la textura de fondo con todos los gráficos
fillSurface();

View File

@@ -363,23 +363,31 @@ Uint8 stringToColor(const std::string &str)
{
// Mapas de colores para cada paleta
static const std::unordered_map<std::string, Uint8> paletteMap = {
{"transparent", 0},
{"black", 1},
{"bright_black", 2},
{"red", 3},
{"bright_red", 4},
{"green", 5},
{"bright_green", 6},
{"yellow", 7},
{"bright_yellow", 8},
{"blue", 9},
{"bright_blue", 10},
{"magenta", 11},
{"bright_magenta", 12},
{"cyan", 13},
{"bright_cyan", 14},
{"white", 15},
{"bright_white", 16}};
{"black", 0},
{"bright_black", 1},
{"blue", 2},
{"bright_blue", 3},
{"red", 4},
{"bright_red", 5},
{"magenta", 6},
{"bright_magenta", 7},
{"green", 8},
{"bright_green", 9},
{"cyan", 10},
{"bright_cyan", 11},
{"yellow", 12},
{"bright_yellow", 13},
{"white", 14},
{"bright_white", 15},
{"transparent", 255}};
// Busca el color en el mapa
auto it = paletteMap.find(str);

View File

@@ -1,10 +1,40 @@
#pragma once
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // for Uint8
#include <string> // for string
#include <vector> // for vector
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
#include <SDL2/SDL_render.h> // for SDL_Renderer, SDL_Texture
#include <SDL2/SDL_stdinc.h> // for Uint8
#include <string> // for string
#include <vector> // for vector
enum class PaletteColor : Uint8
{
BLACK = 0,
BRIGHT_BLACK = 1,
BLUE = 2,
BRIGHT_BLUE = 3,
RED = 4,
BRIGHT_RED = 5,
MAGENTA = 6,
BRIGHT_MAGENTA = 7,
GREEN = 8,
BRIGHT_GREEN = 9,
CYAN = 10,
BRIGHT_CYAN = 11,
YELLOW = 12,
BRIGHT_YELLOW = 13,
WHITE = 14,
BRIGHT_WHITE = 15,
TRANSPARENT = 255,
};
// Estructura para definir un circulo
struct Circle
@@ -105,10 +135,10 @@ std::string boolToString(bool value);
bool colorAreEqual(Color color1, Color color2);
// Convierte una cadena a minusculas
std::string toLower(const std::string& str);
std::string toLower(const std::string &str);
// Convierte una cadena a mayúsculas
std::string toUpper(const std::string& str);
std::string toUpper(const std::string &str);
// Obtiene el nombre de un fichero a partir de una ruta
std::string getFileName(const std::string &path);