diff --git a/data/ending/ending1.gif b/data/ending/ending1.gif index aa74226e..d7c03d4f 100644 Binary files a/data/ending/ending1.gif and b/data/ending/ending1.gif differ diff --git a/data/ending/ending2.gif b/data/ending/ending2.gif index 40237af3..d182b34b 100644 Binary files a/data/ending/ending2.gif and b/data/ending/ending2.gif differ diff --git a/data/ending/ending3.gif b/data/ending/ending3.gif index 9c61bf02..b65aee11 100644 Binary files a/data/ending/ending3.gif and b/data/ending/ending3.gif differ diff --git a/data/ending/ending4.gif b/data/ending/ending4.gif index 3f8933b4..e80ad02f 100644 Binary files a/data/ending/ending4.gif and b/data/ending/ending4.gif differ diff --git a/data/ending/ending5.gif b/data/ending/ending5.gif index cbdad65e..cf98d73f 100644 Binary files a/data/ending/ending5.gif and b/data/ending/ending5.gif differ diff --git a/data/loading/loading_screen_color.gif b/data/loading/loading_screen_color.gif index 2fbcfdb0..8b611685 100644 Binary files a/data/loading/loading_screen_color.gif and b/data/loading/loading_screen_color.gif differ diff --git a/data/palette/island-joy-16.pal b/data/palette/island-joy-16.pal new file mode 100644 index 00000000..d9dd4762 --- /dev/null +++ b/data/palette/island-joy-16.pal @@ -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 diff --git a/data/palette/lost-century.pal b/data/palette/lost-century.pal new file mode 100644 index 00000000..cd66b10f --- /dev/null +++ b/data/palette/lost-century.pal @@ -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 diff --git a/data/palette/na16.pal b/data/palette/na16.pal new file mode 100644 index 00000000..21b59d04 --- /dev/null +++ b/data/palette/na16.pal @@ -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 diff --git a/data/palette/pico-8.pal b/data/palette/pico-8.pal new file mode 100644 index 00000000..9868da09 --- /dev/null +++ b/data/palette/pico-8.pal @@ -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 diff --git a/data/palette/ruzx-spectrum-revision-2.gif b/data/palette/ruzx-spectrum-revision-2.gif deleted file mode 100644 index 1369996a..00000000 Binary files a/data/palette/ruzx-spectrum-revision-2.gif and /dev/null differ diff --git a/data/palette/ruzx-spectrum-revision-2.pal b/data/palette/ruzx-spectrum-revision-2.pal new file mode 100644 index 00000000..b7b9c781 --- /dev/null +++ b/data/palette/ruzx-spectrum-revision-2.pal @@ -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 diff --git a/data/palette/ruzx-spectrum.gif b/data/palette/ruzx-spectrum.gif deleted file mode 100644 index 9665d49b..00000000 Binary files a/data/palette/ruzx-spectrum.gif and /dev/null differ diff --git a/data/palette/ruzx-spectrum.pal b/data/palette/ruzx-spectrum.pal new file mode 100644 index 00000000..55d1a2f6 --- /dev/null +++ b/data/palette/ruzx-spectrum.pal @@ -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 diff --git a/data/palette/steam-lords.pal b/data/palette/steam-lords.pal new file mode 100644 index 00000000..4bb5a564 --- /dev/null +++ b/data/palette/steam-lords.pal @@ -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 diff --git a/data/palette/sweetie-16.pal b/data/palette/sweetie-16.pal new file mode 100644 index 00000000..0139203f --- /dev/null +++ b/data/palette/sweetie-16.pal @@ -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 diff --git a/data/palette/zx-spectrum-adjusted.gif b/data/palette/zx-spectrum-adjusted.gif deleted file mode 100644 index 2fc06863..00000000 Binary files a/data/palette/zx-spectrum-adjusted.gif and /dev/null differ diff --git a/data/palette/zx-spectrum-adjusted.pal b/data/palette/zx-spectrum-adjusted.pal new file mode 100644 index 00000000..4b31f2d1 --- /dev/null +++ b/data/palette/zx-spectrum-adjusted.pal @@ -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 diff --git a/data/palette/zx-spectrum.gif b/data/palette/zx-spectrum.gif deleted file mode 100644 index 4edde256..00000000 Binary files a/data/palette/zx-spectrum.gif and /dev/null differ diff --git a/data/palette/zx-spectrum.pal b/data/palette/zx-spectrum.pal new file mode 100644 index 00000000..283114a3 --- /dev/null +++ b/data/palette/zx-spectrum.pal @@ -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 diff --git a/data/palette/zxarne-5-2.gif b/data/palette/zxarne-5-2.gif deleted file mode 100644 index fa587836..00000000 Binary files a/data/palette/zxarne-5-2.gif and /dev/null differ diff --git a/data/palette/zxarne-5-2.pal b/data/palette/zxarne-5-2.pal new file mode 100644 index 00000000..8b91176f --- /dev/null +++ b/data/palette/zxarne-5-2.pal @@ -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 diff --git a/data/tilesets/standard.gif b/data/tilesets/standard.gif index b53e867b..0142112b 100644 Binary files a/data/tilesets/standard.gif and b/data/tilesets/standard.gif differ diff --git a/data/title/title_loading.gif b/data/title/title_loading.gif index ab9e8d51..313452ad 100644 Binary files a/data/title/title_loading.gif and b/data/title/title_loading.gif differ diff --git a/data/title/title_logo.gif b/data/title/title_logo.gif index 56770a47..4cf3557e 100644 Binary files a/data/title/title_logo.gif and b/data/title/title_logo.gif differ diff --git a/source/credits.cpp b/source/credits.cpp index 57ee7ecc..039a6d1e 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -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(PaletteColor::BLACK)); // Crea la textura para el texto que se escribe en pantalla text_surface_ = std::make_shared(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(PaletteColor::WHITE)}); + texts_.push_back({"INSTRUCTIONS:", static_cast(PaletteColor::YELLOW)}); + texts_.push_back({"", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"HELP JAILDOC TO GET BACK ALL", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"HIS PROJECTS AND GO TO THE", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"JAIL TO FINISH THEM", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"", static_cast(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(PaletteColor::YELLOW)}); + texts_.push_back({"", static_cast(PaletteColor::WHITE)}); + texts_.push_back({keys + " TO MOVE AND JUMP", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"M TO SWITCH THE MUSIC", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"H TO PAUSE THE GAME", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"F1-F2 TO CHANGE WINDOWS SIZE", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"F3 TO SWITCH TO FULLSCREEN", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"B TO TOOGLE THE BORDER SCREEN", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"", static_cast(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(PaletteColor::YELLOW)}); + texts_.push_back({"MADE ON SUMMER/FALL 2022", static_cast(PaletteColor::YELLOW)}); + texts_.push_back({"", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"", static_cast(PaletteColor::WHITE)}); - texts_.push_back({"I LOVE JAILGAMES! ", stringToColor("white")}); - texts_.push_back({"", stringToColor("white")}); + texts_.push_back({"I LOVE JAILGAMES! ", static_cast(PaletteColor::WHITE)}); + texts_.push_back({"", static_cast(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(PaletteColor::WHITE)}); + texts.push_back({"INSTRUCTIONS:", static_cast(PaletteColor::YELLOW)}); + texts.push_back({"", static_cast(PaletteColor::WHITE)}); + texts.push_back({"HELP JAILDOC TO GET BACK ALL", static_cast(PaletteColor::WHITE)}); + texts.push_back({"HIS PROJECTS AND GO TO THE", static_cast(PaletteColor::WHITE)}); + texts.push_back({"JAIL TO FINISH THEM", static_cast(PaletteColor::WHITE)}); + texts.push_back({"", static_cast(PaletteColor::WHITE)}); + texts.push_back({"", static_cast(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(PaletteColor::YELLOW)}); + texts.push_back({"", static_cast(PaletteColor::WHITE)}); + texts.push_back({"B TO JUMP", static_cast(PaletteColor::WHITE)}); + texts.push_back({"R TO SWITCH THE MUSIC", static_cast(PaletteColor::WHITE)}); + texts.push_back({"L TO SWAP THE COLOR PALETTE", static_cast(PaletteColor::WHITE)}); + texts.push_back({"START TO PAUSE", static_cast(PaletteColor::WHITE)}); + texts.push_back({"SELECT TO EXIT", static_cast(PaletteColor::WHITE)}); + texts.push_back({"", static_cast(PaletteColor::WHITE)}); + texts.push_back({"", static_cast(PaletteColor::WHITE)}); + texts.push_back({"", static_cast(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(PaletteColor::YELLOW)}); + texts.push_back({"MADE ON SUMMER/FALL 2022", static_cast(PaletteColor::YELLOW)}); + texts.push_back({"", static_cast(PaletteColor::WHITE)}); + texts.push_back({"", static_cast(PaletteColor::WHITE)}); - texts.push_back({"I LOVE JAILGAMES! ", stringToColor("white")}); - texts.push_back({"", stringToColor("white")}); + texts.push_back({"I LOVE JAILGAMES! ", static_cast(PaletteColor::WHITE)}); + texts.push_back({"", static_cast(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(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(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(PaletteColor::TRANSPARENT)); // Los primeros 8 pixels crea una malla auto surface = Screen::get()->getRendererSurface(); - auto color = stringToColor("black"); + auto color = static_cast(PaletteColor::BLACK); for (int i = 0; i < 256; i += 2) { surface->putPixel(i, 0, color); diff --git a/source/director.cpp b/source/director.cpp index 00dd599d..af5c4ca2 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -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); diff --git a/source/ending.cpp b/source/ending.cpp index 1bcdc10a..462d4fff 100644 --- a/source/ending.cpp +++ b/source/ending.cpp @@ -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,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(PaletteColor::BLACK)); // Crea la textura para cubrir el texto cover_surface_ = std::make_shared(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(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(PaletteColor::WHITE); + auto shadow_color = static_cast(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(PaletteColor::TRANSPARENT)); // Crea una malla de 8 pixels de alto auto surface = Screen::get()->getRendererSurface(); - auto color = stringToColor("black"); + auto color = static_cast(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(PaletteColor::TRANSPARENT)); // Crea una malla en los primeros 8 pixels auto surface = Screen::get()->getRendererSurface(); - auto color = stringToColor("black"); + auto color = static_cast(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(PaletteColor::TRANSPARENT)); // Los primeros 8 pixels crea una malla - const Uint8 color = stringToColor("black"); + const Uint8 color = static_cast(PaletteColor::BLACK); auto surface = Screen::get()->getRendererSurface(); for (int i = 0; i < 256; i += 2) { diff --git a/source/ending2.cpp b/source/ending2.cpp index 06921a96..3b58cc86 100644 --- a/source/ending2.cpp +++ b/source/ending2.cpp @@ -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 +#include "utils.h" // for Color, static_cast // Constructor Ending2::Ending2() @@ -38,7 +37,7 @@ Ending2::Ending2() } // Cambia el color del borde - Screen::get()->setBorderColor(stringToColor("black")); + Screen::get()->setBorderColor(static_cast(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(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(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(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(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(PaletteColor::WHITE); for (auto sprite : sprite_texts_) { const bool A = sprite->getRect().y + sprite->getRect().h > 0; diff --git a/source/game.cpp b/source/game.cpp index 27d4fca3..97102e5e 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -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; diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 40361dd4..38d60e9e 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -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); } } diff --git a/source/input.h b/source/input.h index e94e7b08..4e74ae65 100644 --- a/source/input.h +++ b/source/input.h @@ -35,7 +35,8 @@ enum class InputAction TOGGLE_VIDEOMODE, TOGGLE_BORDER, TOGGLE_MUSIC, - TOGGLE_PALETTE, + NEXT_PALETTE, + PREVIOUS_PALETTE, TOGGLE_SHADERS, // Input obligatorio diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index 714e9baa..2f3ceb95 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -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_); diff --git a/source/loading_screen.h b/source/loading_screen.h index 53863549..380ec2d9 100644 --- a/source/loading_screen.h +++ b/source/loading_screen.h @@ -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(); diff --git a/source/logo.cpp b/source/logo.cpp index 1a9c9d87..46553f98 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -20,7 +20,7 @@ Logo::Logo() since_1998_sprite_(std::make_shared(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(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 diff --git a/source/logo.h b/source/logo.h index e7b6ff39..6a0faa94 100644 --- a/source/logo.h +++ b/source/logo.h @@ -20,6 +20,8 @@ private: std::shared_ptr since_1998_surface_; // Textura con los graficos "Since 1998" std::vector> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES std::shared_ptr 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 color_; // Vector con los colores para el fade diff --git a/source/options.cpp b/source/options.cpp index b03fd68e..fbc334a3 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -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); diff --git a/source/player.cpp b/source/player.cpp index 729f7228..481ff911 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -634,15 +634,15 @@ void Player::setColor() { if (options.cheats.invincible == Cheat::CheatState::ENABLED) { - color_ = stringToColor("cyan"); + color_ = static_cast(PaletteColor::CYAN); } else if (options.cheats.infinite_lives == Cheat::CheatState::ENABLED) { - color_ = stringToColor("yellow"); + color_ = static_cast(PaletteColor::YELLOW); } else { - color_ = stringToColor("white"); + color_ = static_cast(PaletteColor::WHITE); } } diff --git a/source/resource.cpp b/source/resource.cpp index ebc95332..a194a00a 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -254,6 +254,7 @@ void Resource::loadSurfaces() { auto name = getFileName(l); surfaces_.emplace_back(ResourceSurface(name, std::make_shared(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(); } } diff --git a/source/screen.cpp b/source/screen.cpp index 1aa80bc7..253c73e7 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -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(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(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>(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(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) { diff --git a/source/screen.h b/source/screen.h index e5000b4b..9a671389 100644 --- a/source/screen.h +++ b/source/screen.h @@ -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; } diff --git a/source/surface.cpp b/source/surface.cpp index 2b07cac9..80a8563a 100644 --- a/source/surface.cpp +++ b/source/surface.cpp @@ -10,8 +10,14 @@ #include "asset.h" // for Asset #include "screen.h" #include "gif.h" // for LoadGif, LoadPalette +#include +#include +#include +#include +#include +#include -// 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(w, h)), - transparent_color_(0) {} + transparent_color_(static_cast(PaletteColor::TRANSPARENT)) {} Surface::Surface(const std::string &file_path) - : transparent_color_(0) + : transparent_color_(static_cast(PaletteColor::TRANSPARENT)) { SurfaceData loadedData = loadSurface(file_path); surface_data_ = std::make_shared(std::move(loadedData)); diff --git a/source/surface.h b/source/surface.h index bbddaa64..3a1c187a 100644 --- a/source/surface.h +++ b/source/surface.h @@ -9,8 +9,12 @@ // Alias using Palette = std::array; +// 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 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 &palette) { palette_ = palette; } }; diff --git a/source/title.cpp b/source/title.cpp index c4b72599..592b0319 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -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(PaletteColor::BRIGHT_BLACK)); // Rellena la textura de fondo con todos los gráficos fillSurface(); diff --git a/source/utils.cpp b/source/utils.cpp index 4764e78d..2d28917f 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -363,23 +363,31 @@ Uint8 stringToColor(const std::string &str) { // Mapas de colores para cada paleta static const std::unordered_map 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); diff --git a/source/utils.h b/source/utils.h index 2e84a42a..43209800 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,10 +1,40 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for SDL_Renderer, SDL_Texture -#include // for Uint8 -#include // for string -#include // for vector +#include // for SDL_Rect, SDL_Point +#include // for SDL_Renderer, SDL_Texture +#include // for Uint8 +#include // for string +#include // 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);