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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 995 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
255 255 255
109 247 193
17 173 193
96 108 129
57 52 87
30 136 117
91 179 97
161 229 90
247 228 118
249 146 82
203 77 104
106 55 113
201 36 100
244 140 182
247 182 158
155 156 130

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
209 177 135
199 123 88
174 93 64
121 68 74
75 61 68
186 145 88
146 116 65
77 69 57
119 116 59
179 165 85
210 201 165
140 171 161
75 114 110
87 72 82
132 120 117
171 155 142

19
data/palette/na16.pal Normal file
View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
140 143 174
88 69 99
62 33 55
154 99 72
215 155 125
245 237 186
192 199 65
100 125 52
228 148 58
157 48 59
210 100 113
112 55 127
126 196 193
52 133 157
23 67 75
31 14 28

19
data/palette/pico-8.pal Normal file
View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
0 0 0
29 43 83
126 37 83
0 135 81
171 82 54
95 87 79
194 195 199
255 241 232
255 0 77
255 163 0
255 236 39
0 228 54
41 173 255
131 118 156
255 119 168
255 204 170

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
17 17 37
82 75 109
176 201 196
255 252 241
36 34 114
52 112 190
159 32 98
255 94 57
150 58 191
255 105 246
44 126 75
160 195 95
67 152 196
147 255 229
210 133 55
254 245 107

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
15 11 56
97 106 130
173 180 183
249 255 236
40 19 160
74 107 255
160 35 17
237 23 95
115 16 147
238 20 181
39 139 97
157 255 38
27 105 167
71 233 223
122 87 22
247 229 77

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
33 59 37
58 96 74
79 119 84
161 159 124
119 116 79
119 92 79
96 59 58
59 33 55
23 14 25
47 33 59
67 58 96
79 82 119
101 115 140
124 148 161
160 185 186
192 209 204

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
26 28 44
93 39 93
177 62 83
239 125 87
255 205 117
167 240 112
56 183 100
37 113 121
41 54 111
59 93 201
65 166 246
115 239 247
244 244 244
148 176 194
86 108 134
51 60 87

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
0 0 0
0 0 0
0 34 199
0 43 251
214 40 22
255 51 28
212 51 199
255 64 252
0 197 37
0 249 47
0 199 201
0 251 254
204 200 42
255 252 54
202 202 202
255 255 255

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
0 0 0
0 0 0
0 0 216
0 0 255
216 0 0
255 0 0
216 0 216
255 0 255
0 216 0
0 255 0
0 216 216
0 255 255
216 216 0
255 255 0
216 216 216
255 255 255

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

View File

@@ -0,0 +1,19 @@
JASC-PAL
0100
16
0 0 0
60 53 31
49 51 144
21 89 219
167 50 17
216 85 37
161 85 137
205 122 80
98 154 49
156 211 60
40 164 203
101 220 214
232 188 80
241 231 130
191 191 189
242 241 237

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

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);