Reestructurant la classe Options

This commit is contained in:
2025-02-23 18:12:02 +01:00
parent 3ba4293e8a
commit 2ee0c70319
48 changed files with 898 additions and 984 deletions

View File

@@ -2,7 +2,7 @@
#include <string> // Para string #include <string> // Para string
#include <vector> // Para vector #include <vector> // Para vector
class Screen; class Screen;
struct options_t; struct Options;
// Struct para los logros // Struct para los logros
struct Achievement struct Achievement

View File

@@ -5,9 +5,9 @@
#include "utils.h" #include "utils.h"
// Textos // Textos
constexpr const char* WINDOW_CAPTION = "JailDoctor's Dilemma"; constexpr const char *WINDOW_CAPTION = "JailDoctor's Dilemma";
constexpr const char* TEXT_COPYRIGHT = "@2022 JailDesigner"; constexpr const char *TEXT_COPYRIGHT = "@2022 JailDesigner";
constexpr const char* VERSION = "0.7"; constexpr const char *VERSION = "0.7";
// Tamaño de bloque // Tamaño de bloque
constexpr int BLOCK = 8; constexpr int BLOCK = 8;
@@ -45,5 +45,5 @@ constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3; constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
// Colores // Colores
const color_t borderColor = {0x27, 0x27, 0x36}; const Color borderColor = {0x27, 0x27, 0x36};
const color_t black = {0xFF, 0xFF, 0xFF}; const Color black = {0xFF, 0xFF, 0xFF};

View File

@@ -31,12 +31,12 @@ Credits::Credits()
sprite_ = new AnimatedSprite(renderer_, resource_->getAnimation("shine.ani")); sprite_ = new AnimatedSprite(renderer_, resource_->getAnimation("shine.ani"));
// Inicializa variables // Inicializa variables
options.section.name = SECTION_CREDITS; options.section.section = Section::CREDITS;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
sprite_->setRect({194, 174, 8, 8}); sprite_->setRect({194, 174, 8, 8});
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.palette, "black")); screen_->setBorderColor(stringToColor(options.video.palette, "black"));
// Crea la textura para el texto que se escribe en pantalla // Crea la textura para el texto que se escribe en pantalla
text_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); text_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
@@ -93,11 +93,11 @@ void Credits::checkInput()
void Credits::iniTexts() void Credits::iniTexts()
{ {
std::string keys = ""; std::string keys = "";
if (options.keys == ctrl_cursor) if (options.keys == ControlScheme::CURSOR)
{ {
keys = "CURSORS"; keys = "CURSORS";
} }
else if (options.keys == ctrl_opqa) else if (options.keys == ControlScheme::OPQA)
{ {
keys = "O,P AND Q"; keys = "O,P AND Q";
} }
@@ -108,62 +108,62 @@ void Credits::iniTexts()
#ifndef GAME_CONSOLE #ifndef GAME_CONSOLE
texts_.clear(); texts_.clear();
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({"INSTRUCTIONS:", stringToColor(options.palette, "yellow")}); texts_.push_back({"INSTRUCTIONS:", stringToColor(options.video.palette, "yellow")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor(options.palette, "white")}); texts_.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor(options.video.palette, "white")});
texts_.push_back({"HIS PROJECTS AND GO TO THE", stringToColor(options.palette, "white")}); texts_.push_back({"HIS PROJECTS AND GO TO THE", stringToColor(options.video.palette, "white")});
texts_.push_back({"JAIL TO FINISH THEM", stringToColor(options.palette, "white")}); texts_.push_back({"JAIL TO FINISH THEM", stringToColor(options.video.palette, "white")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({"KEYS:", stringToColor(options.palette, "yellow")}); texts_.push_back({"KEYS:", stringToColor(options.video.palette, "yellow")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({keys + " TO MOVE AND JUMP", stringToColor(options.palette, "white")}); texts_.push_back({keys + " TO MOVE AND JUMP", stringToColor(options.video.palette, "white")});
texts_.push_back({"M TO SWITCH THE MUSIC", stringToColor(options.palette, "white")}); texts_.push_back({"M TO SWITCH THE MUSIC", stringToColor(options.video.palette, "white")});
texts_.push_back({"H TO PAUSE THE GAME", stringToColor(options.palette, "white")}); texts_.push_back({"H TO PAUSE THE GAME", stringToColor(options.video.palette, "white")});
texts_.push_back({"F1-F2 TO CHANGE WINDOWS SIZE", stringToColor(options.palette, "white")}); texts_.push_back({"F1-F2 TO CHANGE WINDOWS SIZE", stringToColor(options.video.palette, "white")});
texts_.push_back({"F3 TO SWITCH TO FULLSCREEN", stringToColor(options.palette, "white")}); texts_.push_back({"F3 TO SWITCH TO FULLSCREEN", stringToColor(options.video.palette, "white")});
texts_.push_back({"B TO TOOGLE THE BORDER SCREEN", stringToColor(options.palette, "white")}); texts_.push_back({"B TO TOOGLE THE BORDER SCREEN", stringToColor(options.video.palette, "white")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({"A GAME BY JAILDESIGNER", stringToColor(options.palette, "yellow")}); texts_.push_back({"A GAME BY JAILDESIGNER", stringToColor(options.video.palette, "yellow")});
texts_.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options.palette, "yellow")}); texts_.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options.video.palette, "yellow")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
texts_.push_back({"I LOVE JAILGAMES! ", stringToColor(options.palette, "white")}); texts_.push_back({"I LOVE JAILGAMES! ", stringToColor(options.video.palette, "white")});
texts_.push_back({"", stringToColor(options.palette, "white")}); texts_.push_back({"", stringToColor(options.video.palette, "white")});
#else #else
texts.clear(); texts.clear();
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"INSTRUCTIONS:", stringToColor(options.palette, "yellow")}); texts.push_back({"INSTRUCTIONS:", stringToColor(options.video.palette, "yellow")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor(options.palette, "white")}); texts.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor(options.video.palette, "white")});
texts.push_back({"HIS PROJECTS AND GO TO THE", stringToColor(options.palette, "white")}); texts.push_back({"HIS PROJECTS AND GO TO THE", stringToColor(options.video.palette, "white")});
texts.push_back({"JAIL TO FINISH THEM", stringToColor(options.palette, "white")}); texts.push_back({"JAIL TO FINISH THEM", stringToColor(options.video.palette, "white")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"KEYS:", stringToColor(options.palette, "yellow")}); texts.push_back({"KEYS:", stringToColor(options.video.palette, "yellow")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"B TO JUMP", stringToColor(options.palette, "white")}); texts.push_back({"B TO JUMP", stringToColor(options.video.palette, "white")});
texts.push_back({"R TO SWITCH THE MUSIC", stringToColor(options.palette, "white")}); texts.push_back({"R TO SWITCH THE MUSIC", stringToColor(options.video.palette, "white")});
texts.push_back({"L TO SWAP THE COLOR PALETTE", stringToColor(options.palette, "white")}); texts.push_back({"L TO SWAP THE COLOR PALETTE", stringToColor(options.video.palette, "white")});
texts.push_back({"START TO PAUSE", stringToColor(options.palette, "white")}); texts.push_back({"START TO PAUSE", stringToColor(options.video.palette, "white")});
texts.push_back({"SELECT TO EXIT", stringToColor(options.palette, "white")}); texts.push_back({"SELECT TO EXIT", stringToColor(options.video.palette, "white")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"A GAME BY JAILDESIGNER", stringToColor(options.palette, "yellow")}); texts.push_back({"A GAME BY JAILDESIGNER", stringToColor(options.video.palette, "yellow")});
texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options.palette, "yellow")}); texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options.video.palette, "yellow")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options.palette, "white")}); texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options.video.palette, "white")});
texts.push_back({"", stringToColor(options.palette, "white")}); texts.push_back({"", stringToColor(options.video.palette, "white")});
#endif #endif
} }
@@ -175,7 +175,7 @@ void Credits::fillTexture()
// Rellena la textura de texto // Rellena la textura de texto
SDL_SetRenderTarget(renderer_, text_texture_); SDL_SetRenderTarget(renderer_, text_texture_);
color_t c = stringToColor(options.palette, "black"); Color c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
@@ -192,7 +192,7 @@ void Credits::fillTexture()
// Escribe el corazón // Escribe el corazón
const int textLenght = text_->lenght(texts_[22].label, 1) - text_->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio const int textLenght = text_->lenght(texts_[22].label, 1) - text_->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio
const int posX = ((PLAY_AREA_WIDTH - textLenght) / 2) + textLenght; const int posX = ((PLAY_AREA_WIDTH - textLenght) / 2) + textLenght;
text_->writeColored(posX, 176, "}", stringToColor(options.palette, "bright_red")); text_->writeColored(posX, 176, "}", stringToColor(options.video.palette, "bright_red"));
// Recoloca el sprite del brillo // Recoloca el sprite del brillo
sprite_->setPosX(posX + 2); sprite_->setPosX(posX + 2);
@@ -249,7 +249,7 @@ void Credits::updateCounter()
// Comprueba si ha terminado la sección // Comprueba si ha terminado la sección
if (counter_ > 1200) if (counter_ > 1200)
{ {
options.section.name = SECTION_DEMO; options.section.section = Section::DEMO;
} }
} }
@@ -309,7 +309,7 @@ void Credits::render()
// Bucle para el logo del juego // Bucle para el logo del juego
void Credits::run() void Credits::run()
{ {
while (options.section.name == SECTION_CREDITS) while (options.section.section == Section::CREDITS)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -320,6 +320,6 @@ void Credits::run()
// Cambia la paleta // Cambia la paleta
void Credits::switchPalette() void Credits::switchPalette()
{ {
options.palette = options.palette == p_zxspectrum ? p_zxarne : p_zxspectrum; options.video.palette = options.video.palette == Palette::ZXSPECTRUM ? Palette::ZXARNE : Palette::ZXSPECTRUM;
fillTexture(); fillTexture();
} }

View File

@@ -19,7 +19,7 @@ private:
struct captions_t struct captions_t
{ {
std::string label; // Texto a escribir std::string label; // Texto a escribir
color_t color; // Color del texto Color color; // Color del texto
}; };
// Objetos y punteros // Objetos y punteros

View File

@@ -13,19 +13,19 @@ Debug *Debug::debug_ = nullptr;
// [SINGLETON] Crearemos el objeto con esta función estática // [SINGLETON] Crearemos el objeto con esta función estática
void Debug::init() void Debug::init()
{ {
Debug::debug_ = new Debug(); Debug::debug_ = new Debug();
} }
// [SINGLETON] Destruiremos el objeto con esta función estática // [SINGLETON] Destruiremos el objeto con esta función estática
void Debug::destroy() void Debug::destroy()
{ {
delete Debug::debug_; delete Debug::debug_;
} }
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
Debug *Debug::get() Debug *Debug::get()
{ {
return Debug::debug_; return Debug::debug_;
} }
// Constructor // Constructor
@@ -73,7 +73,7 @@ void Debug::render()
y = 0; y = 0;
for (auto l : log_) for (auto l : log_)
{ {
text_->writeColored(x_ + 10, y, l, color_t(255, 255, 255)); text_->writeColored(x_ + 10, y, l, Color(255, 255, 255));
y += text_->getCharacterSize() + 1; y += text_->getCharacterSize() + 1;
} }
} }

View File

@@ -53,12 +53,12 @@ Demo::Demo()
board.lives = 9; board.lives = 9;
board.items = 0; board.items = 0;
board.rooms = 1; board.rooms = 1;
board.jailEnabled = false; board.jail_is_open = false;
board.music = true; board.music = true;
setScoreBoardColor(); setScoreBoardColor();
options.section.name = SECTION_DEMO; options.section.section = Section::DEMO;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
} }
Demo::~Demo() Demo::~Demo()
@@ -89,7 +89,7 @@ void Demo::checkInput()
// Bucle para el juego // Bucle para el juego
void Demo::run() void Demo::run()
{ {
while (options.section.name == SECTION_DEMO) while (options.section.section == Section::DEMO)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -142,7 +142,7 @@ void Demo::renderRoomName()
{ {
// Texto en el centro de la pantalla // Texto en el centro de la pantalla
SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2}; SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2};
color_t color = stringToColor(options.palette, "white"); Color color = stringToColor(options.video.palette, "white");
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
SDL_RenderFillRect(renderer, &rect); SDL_RenderFillRect(renderer, &rect);
@@ -165,13 +165,13 @@ void Demo::reLoadTextures()
void Demo::switchPalette() void Demo::switchPalette()
{ {
// Modifica la variable // Modifica la variable
if (options.palette == p_zxspectrum) if (options.video.palette == Palette::ZXSPECTRUM)
{ {
options.palette = p_zxarne; options.video.palette = Palette::ZXARNE;
} }
else else
{ {
options.palette = p_zxspectrum; options.video.palette = Palette::ZXSPECTRUM;
} }
room->reLoadPalette(); room->reLoadPalette();
@@ -215,8 +215,8 @@ void Demo::checkRoomChange()
roomIndex++; roomIndex++;
if (roomIndex == (int)rooms.size()) if (roomIndex == (int)rooms.size())
{ {
options.section.name = SECTION_LOGO; options.section.section = Section::LOGO;
options.section.subsection = SUBSECTION_LOGO_TO_TITLE; options.section.subsection = Subsection::LOGO_TO_TITLE;
} }
else else
{ {
@@ -229,13 +229,13 @@ void Demo::checkRoomChange()
void Demo::setScoreBoardColor() void Demo::setScoreBoardColor()
{ {
// Obtiene el color del borde // Obtiene el color del borde
const color_t c = room->getBorderColor(); const Color color = room->getBorderColor();
// Si el color es negro lo cambia a blanco // Si el color es negro lo cambia a blanco
const color_t cBlack = stringToColor(options.palette, "black"); const Color black_color = stringToColor(options.video.palette, "black");
board.color = colorAreEqual(c, cBlack) ? stringToColor(options.palette, "white") : c; board.color = colorAreEqual(color, black_color) ? stringToColor(options.video.palette, "white") : color;
// Si el color es negro brillante lo cambia a blanco // Si el color es negro brillante lo cambia a blanco
const color_t cBrightBlack = stringToColor(options.palette, "bright_black"); const Color bright_blac_color = stringToColor(options.video.palette, "bright_black");
board.color = colorAreEqual(c, cBrightBlack) ? stringToColor(options.palette, "white") : c; board.color = colorAreEqual(color, bright_blac_color) ? stringToColor(options.video.palette, "white") : color;
} }

View File

@@ -14,8 +14,8 @@ class Resource;
class Room; class Room;
class Screen; class Screen;
class Text; class Text;
struct options_t; struct Options;
struct section_t; struct SectionState;
class Demo class Demo
{ {

View File

@@ -20,7 +20,7 @@
#include <vector> // Para vector #include <vector> // Para vector
#include <memory> // Para std::make_unique #include <memory> // Para std::make_unique
#include "asset.h" // Para Asset, assetType #include "asset.h" // Para Asset, assetType
#include "const.h" // Para SECTION_LOGO, SECTION_TITLE #include "const.h" // Para Section::LOGO, Section::TITLE
#include "debug.h" // Para Debug #include "debug.h" // Para Debug
#include "credits.h" // Para Credits #include "credits.h" // Para Credits
#include "demo.h" // Para Demo #include "demo.h" // Para Demo
@@ -126,22 +126,25 @@ std::string Director::checkProgramArguments(int argc, const char *argv[])
else if (strcmp(argv[i], "--infiniteLives") == 0) else if (strcmp(argv[i], "--infiniteLives") == 0)
{ {
options.cheat.infiniteLives = true; options.cheats.infinite_lives = Cheat::CheatState::ENABLED;
} }
else if (strcmp(argv[i], "--invincible") == 0) else if (strcmp(argv[i], "--invincible") == 0)
{ {
options.cheat.invincible = true; options.cheats.invincible = Cheat::CheatState::ENABLED;
;
} }
else if (strcmp(argv[i], "--jailEnabled") == 0) else if (strcmp(argv[i], "--jailEnabled") == 0)
{ {
options.cheat.jailEnabled = true; options.cheats.jail_is_open = Cheat::CheatState::ENABLED;
;
} }
else if (strcmp(argv[i], "--altSkin") == 0) else if (strcmp(argv[i], "--altSkin") == 0)
{ {
options.cheat.altSkin = true; options.cheats.alternate_skin = Cheat::CheatState::ENABLED;
;
} }
} }
@@ -209,14 +212,14 @@ void Director::createSystemFolder(const std::string &folder)
} }
// Carga los recursos // Carga los recursos
void Director::loadResources(section_t section) void Director::loadResources(SectionState section)
{ {
if (options.console) if (options.console)
{ {
std::cout << "** LOAD RESOURCES" << std::endl; std::cout << "** LOAD RESOURCES" << std::endl;
} }
if (options.section.name == SECTION_LOGO) if (options.section.section == Section::LOGO)
{ {
std::vector<std::string> textureList; std::vector<std::string> textureList;
textureList.push_back("jailgames.png"); textureList.push_back("jailgames.png");
@@ -225,7 +228,7 @@ void Director::loadResources(section_t section)
Resource::get()->loadTextures(textureList); Resource::get()->loadTextures(textureList);
} }
else if (options.section.name == SECTION_LOADING_SCREEN) else if (options.section.section == Section::LOADING_SCREEN)
{ {
std::vector<std::string> textureList; std::vector<std::string> textureList;
textureList.push_back("loading_screen_bn.png"); textureList.push_back("loading_screen_bn.png");
@@ -236,7 +239,7 @@ void Director::loadResources(section_t section)
Resource::get()->loadTextures(textureList); Resource::get()->loadTextures(textureList);
} }
else if (options.section.name == SECTION_TITLE) else if (options.section.section == Section::TITLE)
{ {
std::vector<std::string> textureList; std::vector<std::string> textureList;
textureList.push_back("loading_screen_color.png"); textureList.push_back("loading_screen_color.png");
@@ -256,7 +259,7 @@ void Director::loadResources(section_t section)
Resource::get()->loadOffsets(offsetsList); Resource::get()->loadOffsets(offsetsList);
} }
else if (options.section.name == SECTION_CREDITS) else if (options.section.section == Section::CREDITS)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -278,7 +281,7 @@ void Director::loadResources(section_t section)
Resource::get()->loadOffsets(offsetsList); Resource::get()->loadOffsets(offsetsList);
} }
else if (options.section.name == SECTION_ENDING) else if (options.section.section == Section::ENDING)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -303,7 +306,7 @@ void Director::loadResources(section_t section)
Resource::get()->loadOffsets(offsetsList); Resource::get()->loadOffsets(offsetsList);
} }
else if (options.section.name == SECTION_ENDING2) else if (options.section.section == Section::ENDING2)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -441,7 +444,7 @@ void Director::loadResources(section_t section)
Resource::get()->loadOffsets(offsetsList); Resource::get()->loadOffsets(offsetsList);
} }
else if (options.section.name == SECTION_GAME_OVER) else if (options.section.section == Section::GAME_OVER)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
@@ -465,20 +468,13 @@ void Director::loadResources(section_t section)
Resource::get()->loadOffsets(offsetsList); Resource::get()->loadOffsets(offsetsList);
} }
else if (options.section.name == SECTION_GAME || options.section.name == SECTION_DEMO) else if (options.section.section == Section::GAME || options.section.section == Section::DEMO)
{ {
// Texturas // Texturas
std::vector<std::string> textureList; std::vector<std::string> textureList;
// Jugador // Jugador
if (options.cheat.altSkin) textureList.push_back(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png");
{
textureList.push_back("player2.png");
}
else
{
textureList.push_back("player.png");
}
// Tilesets // Tilesets
textureList.push_back("standard.png"); textureList.push_back("standard.png");
@@ -556,14 +552,7 @@ void Director::loadResources(section_t section)
std::vector<std::string> animationList; std::vector<std::string> animationList;
// Jugador // Jugador
if (options.cheat.altSkin) animationList.push_back(options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani");
{
animationList.push_back("player2.ani");
}
else
{
animationList.push_back("player.ani");
}
// Enemigos // Enemigos
animationList.push_back("abad_bell.ani"); animationList.push_back("abad_bell.ani");
@@ -780,7 +769,7 @@ void Director::initInput()
Input::get()->discoverGameController(); Input::get()->discoverGameController();
// Teclado - Movimiento // Teclado - Movimiento
if (options.keys == ctrl_cursor) if (options.keys == ControlScheme::CURSOR)
{ {
Input::get()->bindKey(input_jump, SDL_SCANCODE_UP); Input::get()->bindKey(input_jump, SDL_SCANCODE_UP);
Input::get()->bindKey(input_left, SDL_SCANCODE_LEFT); Input::get()->bindKey(input_left, SDL_SCANCODE_LEFT);
@@ -788,7 +777,7 @@ void Director::initInput()
Input::get()->bindKey(input_up, SDL_SCANCODE_UP); Input::get()->bindKey(input_up, SDL_SCANCODE_UP);
Input::get()->bindKey(input_down, SDL_SCANCODE_DOWN); Input::get()->bindKey(input_down, SDL_SCANCODE_DOWN);
} }
else if (options.keys == ctrl_opqa) else if (options.keys == ControlScheme::OPQA)
{ {
Input::get()->bindKey(input_jump, SDL_SCANCODE_Q); Input::get()->bindKey(input_jump, SDL_SCANCODE_Q);
Input::get()->bindKey(input_left, SDL_SCANCODE_O); Input::get()->bindKey(input_left, SDL_SCANCODE_O);
@@ -796,7 +785,7 @@ void Director::initInput()
Input::get()->bindKey(input_up, SDL_SCANCODE_Q); Input::get()->bindKey(input_up, SDL_SCANCODE_Q);
Input::get()->bindKey(input_down, SDL_SCANCODE_A); Input::get()->bindKey(input_down, SDL_SCANCODE_A);
} }
else if (options.keys == ctrl_wasd) else if (options.keys == ControlScheme::WASD)
{ {
Input::get()->bindKey(input_jump, SDL_SCANCODE_W); Input::get()->bindKey(input_jump, SDL_SCANCODE_W);
Input::get()->bindKey(input_left, SDL_SCANCODE_A); Input::get()->bindKey(input_left, SDL_SCANCODE_A);
@@ -865,7 +854,7 @@ bool Director::initSDL()
std::srand(static_cast<unsigned int>(SDL_GetTicks())); std::srand(static_cast<unsigned int>(SDL_GetTicks()));
// Establece el filtro de la textura a nearest // Establece el filtro de la textura a nearest
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(options.filter).c_str())) if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast<int>(options.video.filter)).c_str()))
{ {
if (options.console) if (options.console)
{ {
@@ -880,15 +869,10 @@ bool Director::initSDL()
} }
// Crea la ventana // Crea la ventana
int incW = 0; options.window.width = options.video.border.enabled ? options.game.width + options.video.border.width * 2 : options.game.width;
int incH = 0; options.window.height = options.video.border.enabled ? options.game.height + options.video.border.height * 2 : options.game.height;
if (options.borderEnabled)
{
incW = options.borderWidth * 2;
incH = options.borderHeight * 2;
}
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options.gameWidth + incW) * options.windowSize, (options.gameHeight + incH) * options.windowSize, SDL_WINDOW_HIDDEN); window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options.window.width, options.window.height, SDL_WINDOW_HIDDEN);
if (window_ == nullptr) if (window_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -901,7 +885,7 @@ bool Director::initSDL()
{ {
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones // Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
Uint32 flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; Uint32 flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE;
if (options.vSync) if (options.video.vertical_sync)
{ {
flags = flags | SDL_RENDERER_PRESENTVSYNC; flags = flags | SDL_RENDERER_PRESENTVSYNC;
} }
@@ -921,7 +905,7 @@ bool Director::initSDL()
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
// Establece el tamaño del buffer de renderizado // Establece el tamaño del buffer de renderizado
SDL_RenderSetLogicalSize(renderer_, options.gameWidth, options.gameHeight); SDL_RenderSetLogicalSize(renderer_, options.game.width, options.game.height);
// Establece el modo de mezcla // Establece el modo de mezcla
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
@@ -1421,45 +1405,48 @@ void Director::runGame()
int Director::run() int Director::run()
{ {
// Bucle principal // Bucle principal
while (options.section.name != SECTION_QUIT) while (options.section.section != Section::QUIT)
{ {
switch (options.section.name) switch (options.section.section)
{ {
case SECTION_LOGO: case Section::LOGO:
runLogo(); runLogo();
break; break;
case SECTION_LOADING_SCREEN: case Section::LOADING_SCREEN:
runLoadingScreen(); runLoadingScreen();
break; break;
case SECTION_TITLE: case Section::TITLE:
runTitle(); runTitle();
break; break;
case SECTION_CREDITS: case Section::CREDITS:
runCredits(); runCredits();
break; break;
case SECTION_DEMO: case Section::DEMO:
runDemo(); runDemo();
break; break;
case SECTION_GAME: case Section::GAME:
runGame(); runGame();
break; break;
case SECTION_GAME_OVER: case Section::GAME_OVER:
runGameOver(); runGameOver();
break; break;
case SECTION_ENDING: case Section::ENDING:
runEnding(); runEnding();
break; break;
case SECTION_ENDING2: case Section::ENDING2:
runEnding2(); runEnding2();
break; break;
default:
break;
} }
} }

View File

@@ -9,8 +9,8 @@ class Input; // lines 14-14
class Resource; // lines 17-17 class Resource; // lines 17-17
class Screen; // lines 18-18 class Screen; // lines 18-18
struct JA_Music_t; // lines 20-20 struct JA_Music_t; // lines 20-20
struct options_t; // lines 21-21 struct Options; // lines 21-21
struct section_t; // lines 22-22 struct SectionState; // lines 22-22
class Director class Director
{ {
@@ -31,7 +31,7 @@ private:
void createSystemFolder(const std::string &folder); void createSystemFolder(const std::string &folder);
// Carga los recursos // Carga los recursos
void loadResources(section_t section); void loadResources(SectionState section);
// Inicializa jail_audio // Inicializa jail_audio
void initJailAudio(); void initJailAudio();

View File

@@ -36,8 +36,8 @@ Ending::Ending()
counter = -1; counter = -1;
preCounter = 0; preCounter = 0;
coverCounter = 0; coverCounter = 0;
options.section.name = SECTION_ENDING; options.section.section = Section::ENDING;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
scene = 0; scene = 0;
@@ -52,7 +52,7 @@ Ending::Ending()
iniScenes(); iniScenes();
// Cambia el color del borde // Cambia el color del borde
screen->setBorderColor(stringToColor(options.palette, "black")); screen->setBorderColor(stringToColor(options.video.palette, "black"));
// Crea la textura para cubrir el rexto // Crea la textura para cubrir el rexto
coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8); coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8);
@@ -131,7 +131,7 @@ void Ending::render()
screen->start(); screen->start();
// Limpia la pantalla // Limpia la pantalla
screen->clean(stringToColor(options.palette, "black")); screen->clean(stringToColor(options.video.palette, "black"));
// Dibuja las imagenes de la escena // Dibuja las imagenes de la escena
spritePics[scene].sprite->render(); spritePics[scene].sprite->render();
@@ -150,8 +150,6 @@ void Ending::render()
// Dibuja la cortinilla de cambio de escena // Dibuja la cortinilla de cambio de escena
renderCoverTexture(); renderCoverTexture();
// text->write(0, 0, std::to_string(counter));
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen->render(); screen->render();
} }
@@ -222,7 +220,7 @@ void Ending::iniTexts()
endingTexture_t st; endingTexture_t st;
const int width = text->lenght(t.caption, 1) + 2 + 2; const int width = text->lenght(t.caption, 1) + 2 + 2;
const int height = text->getCharacterSize() + 2 + 2; const int height = text->getCharacterSize() + 2 + 2;
color_t c = stringToColor(options.palette, "black"); Color c = stringToColor(options.video.palette, "black");
// Crea la texture // Crea la texture
st.texture = new Texture(renderer); st.texture = new Texture(renderer);
@@ -246,7 +244,7 @@ void Ending::iniTexts()
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
c = stringToColor(options.palette, "black"); c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
for (int i = 0; i < width; i += 2) for (int i = 0; i < width; i += 2)
{ {
@@ -261,7 +259,7 @@ void Ending::iniTexts()
// El resto se rellena de color sólido // El resto se rellena de color sólido
SDL_Rect rect = {0, 8, width, height}; SDL_Rect rect = {0, 8, width, height};
c = stringToColor(options.palette, "black"); c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
SDL_RenderFillRect(renderer, &rect); SDL_RenderFillRect(renderer, &rect);
@@ -284,7 +282,7 @@ void Ending::iniPics()
// Vector con las rutas y la posición // Vector con las rutas y la posición
std::vector<textAndPos_t> pics; std::vector<textAndPos_t> pics;
if (options.palette == p_zxspectrum) if (options.video.palette == Palette::ZXSPECTRUM)
{ {
pics.push_back({"ending1.png", 48}); pics.push_back({"ending1.png", 48});
pics.push_back({"ending2.png", 26}); pics.push_back({"ending2.png", 26});
@@ -334,7 +332,7 @@ void Ending::iniPics()
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
color_t c = stringToColor(options.palette, "black"); Color c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
for (int i = 0; i < width; i += 2) for (int i = 0; i < width; i += 2)
{ {
@@ -349,7 +347,7 @@ void Ending::iniPics()
// El resto se rellena de color sólido // El resto se rellena de color sólido
SDL_Rect rect = {0, 8, width, height}; SDL_Rect rect = {0, 8, width, height};
c = stringToColor(options.palette, "black"); c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
SDL_RenderFillRect(renderer, &rect); SDL_RenderFillRect(renderer, &rect);
@@ -454,7 +452,7 @@ void Ending::run()
{ {
JA_PlayMusic(music); JA_PlayMusic(music);
while (options.section.name == SECTION_ENDING) while (options.section.section == Section::ENDING)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -538,7 +536,7 @@ void Ending::checkChangeScene()
if (scene == 5) if (scene == 5)
{ {
// Termina el bucle // Termina el bucle
options.section.name = SECTION_ENDING2; options.section.section = Section::ENDING2;
// Mantiene los valores anteriores // Mantiene los valores anteriores
scene = 4; scene = 4;
@@ -556,8 +554,8 @@ void Ending::fillCoverTexture()
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
// Los primeros 8 pixels crea una malla // Los primeros 8 pixels crea una malla
const color_t c = stringToColor(options.palette, "brack"); const Color color = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
for (int i = 0; i < 256; i += 2) for (int i = 0; i < 256; i += 2)
{ {
SDL_RenderDrawPoint(renderer, i + 0, GAMECANVAS_HEIGHT + 0); SDL_RenderDrawPoint(renderer, i + 0, GAMECANVAS_HEIGHT + 0);
@@ -597,29 +595,4 @@ void Ending::updateMusicVolume()
const int volume = 128 * step; const int volume = 128 * step;
JA_SetVolume(volume); JA_SetVolume(volume);
} }
}
// Cambia la paleta
void Ending::switchPalette()
{
if (options.palette == p_zxspectrum)
{
options.palette = p_zxarne;
spritePics[0].sprite->setTexture(resource->getTexture("ending1_zxarne.png"));
spritePics[1].sprite->setTexture(resource->getTexture("ending2_zxarne.png"));
spritePics[2].sprite->setTexture(resource->getTexture("ending3_zxarne.png"));
spritePics[3].sprite->setTexture(resource->getTexture("ending4_zxarne.png"));
spritePics[4].sprite->setTexture(resource->getTexture("ending5_zxarne.png"));
}
else
{
options.palette = p_zxspectrum;
spritePics[0].sprite->setTexture(resource->getTexture("ending1.png"));
spritePics[1].sprite->setTexture(resource->getTexture("ending2.png"));
spritePics[2].sprite->setTexture(resource->getTexture("ending3.png"));
spritePics[3].sprite->setTexture(resource->getTexture("ending4.png"));
spritePics[4].sprite->setTexture(resource->getTexture("ending5.png"));
}
} }

View File

@@ -13,8 +13,8 @@ class Sprite;
class Text; class Text;
class Texture; class Texture;
struct JA_Music_t; struct JA_Music_t;
struct options_t; struct Options;
struct section_t; struct SectionState;
class Ending class Ending
{ {
@@ -109,9 +109,6 @@ private:
// Actualiza el volumen de la musica // Actualiza el volumen de la musica
void updateMusicVolume(); void updateMusicVolume();
// Cambia la paleta
void switchPalette();
public: public:
// Constructor // Constructor
Ending(); Ending();

View File

@@ -34,8 +34,8 @@ Ending2::Ending2()
preCounter = 0; preCounter = 0;
postCounter = 0; postCounter = 0;
postCounterEnabled = false; postCounterEnabled = false;
options.section.name = SECTION_ENDING2; options.section.section = Section::ENDING2;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
distSpriteText = 8; distSpriteText = 8;
@@ -45,14 +45,14 @@ Ending2::Ending2()
secondCol = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16); secondCol = GAMECANVAS_THIRD_QUARTER_X - (GAMECANVAS_WIDTH / 16);
// Inicializa el vector de colores // Inicializa el vector de colores
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"}; const std::vector<std::string> color_list = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (auto cl : colorList) for (auto color : color_list)
{ {
colors.push_back(stringToColor(options.palette, cl)); colors.push_back(stringToColor(options.video.palette, color));
} }
// Cambia el color del borde // Cambia el color del borde
screen->setBorderColor(stringToColor(options.palette, "black")); screen->setBorderColor(stringToColor(options.video.palette, "black"));
// Inicializa la lista de sprites // Inicializa la lista de sprites
iniSpriteList(); iniSpriteList();
@@ -126,7 +126,7 @@ void Ending2::render()
screen->start(); screen->start();
// Limpia la pantalla // Limpia la pantalla
screen->clean(stringToColor(options.palette, "black")); screen->clean(stringToColor(options.video.palette, "black"));
// Dibuja los sprites // Dibuja los sprites
renderSprites(); renderSprites();
@@ -207,7 +207,7 @@ void Ending2::run()
{ {
JA_PlayMusic(music); JA_PlayMusic(music);
while (options.section.name == SECTION_ENDING2) while (options.section.section == Section::ENDING2)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -238,8 +238,8 @@ void Ending2::updateCounters()
if (postCounter > 600) if (postCounter > 600)
{ {
options.section.name = SECTION_LOGO; options.section.section = Section::LOGO;
options.section.subsection = SUBSECTION_LOGO_TO_INTRO; options.section.subsection = Subsection::LOGO_TO_INTRO;
} }
} }
@@ -377,7 +377,7 @@ void Ending2::updateTexts()
// Dibuja los sprites // Dibuja los sprites
void Ending2::renderSprites() void Ending2::renderSprites()
{ {
const color_t color = stringToColor(options.palette, "red"); const Color color = stringToColor(options.video.palette, "red");
for (auto sprite : sprites) for (auto sprite : sprites)
{ {
const bool a = sprite->getRect().y + sprite->getRect().h > 0; const bool a = sprite->getRect().y + sprite->getRect().h > 0;
@@ -390,7 +390,7 @@ void Ending2::renderSprites()
} }
// Pinta el ultimo elemento de otro color // Pinta el ultimo elemento de otro color
const color_t c = stringToColor(options.palette, "white"); const Color c = stringToColor(options.video.palette, "white");
sprites.back()->getTexture()->setColor(c.r, c.g, c.b); sprites.back()->getTexture()->setColor(c.r, c.g, c.b);
sprites.back()->render(); sprites.back()->render();
} }
@@ -398,7 +398,7 @@ void Ending2::renderSprites()
// Dibuja los sprites con el texto // Dibuja los sprites con el texto
void Ending2::renderSpriteTexts() void Ending2::renderSpriteTexts()
{ {
const color_t color = stringToColor(options.palette, "white"); const Color color = stringToColor(options.video.palette, "white");
for (auto sprite : spriteTexts) for (auto sprite : spriteTexts)
{ {
const bool a = sprite->getRect().y + sprite->getRect().h > 0; const bool a = sprite->getRect().y + sprite->getRect().h > 0;
@@ -600,10 +600,4 @@ void Ending2::updateMusicVolume()
const int volume = 128 * step; const int volume = 128 * step;
JA_SetVolume(volume); JA_SetVolume(volume);
} }
}
// Cambia la paleta
void Ending2::switchPalette()
{
options.palette = (options.palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
} }

View File

@@ -13,9 +13,9 @@ class Resource; // lines 13-13
class Screen; // lines 14-14 class Screen; // lines 14-14
class Text; // lines 15-15 class Text; // lines 15-15
struct JA_Music_t; // lines 16-16 struct JA_Music_t; // lines 16-16
struct color_t; struct Color;
struct options_t; struct Options;
struct section_t; struct SectionState;
class Ending2 class Ending2
{ {
@@ -40,7 +40,7 @@ private:
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
JA_Music_t *music; // Musica que suena durante el final JA_Music_t *music; // Musica que suena durante el final
std::vector<std::string> spriteList; // Lista con todos los sprites a dibujar std::vector<std::string> spriteList; // Lista con todos los sprites a dibujar
std::vector<color_t> colors; // Vector con los colores para el fade std::vector<Color> colors; // Vector con los colores para el fade
int maxSpriteWidth; // El valor de ancho del sprite mas ancho int maxSpriteWidth; // El valor de ancho del sprite mas ancho
int maxSpriteHeight; // El valor de alto del sprite mas alto int maxSpriteHeight; // El valor de alto del sprite mas alto
int distSpriteText; // Distancia entre el sprite y el texto que lo acompaña int distSpriteText; // Distancia entre el sprite y el texto que lo acompaña
@@ -112,9 +112,6 @@ private:
// Actualiza el volumen de la musica // Actualiza el volumen de la musica
void updateMusicVolume(); void updateMusicVolume();
// Cambia la paleta
void switchPalette();
public: public:
// Constructor // Constructor
Ending2(); Ending2();

View File

@@ -137,7 +137,7 @@ void Enemy::reLoadTexture()
} }
// Asigna la paleta // Asigna la paleta
void Enemy::setPalette(palette_e pal) void Enemy::setPalette(Palette pal)
{ {
palette = pal; palette = pal;
color = stringToColor(palette, colorString); color = stringToColor(palette, colorString);

View File

@@ -27,7 +27,7 @@ struct enemy_t
bool mirror; // Indica si el enemigo está volteado verticalmente bool mirror; // Indica si el enemigo está volteado verticalmente
int frame; // Frame inicial para la animación del enemigo int frame; // Frame inicial para la animación del enemigo
std::string color; // Color del enemigo std::string color; // Color del enemigo
palette_e palette; // Paleta de colores Palette palette; // Paleta de colores
}; };
class Enemy class Enemy
@@ -37,9 +37,9 @@ private:
AnimatedSprite *sprite; // Sprite del enemigo AnimatedSprite *sprite; // Sprite del enemigo
// Variables // Variables
color_t color; // Color del enemigo Color color; // Color del enemigo
std::string colorString; // Color del enemigo en formato texto std::string colorString; // Color del enemigo en formato texto
palette_e palette; // Paleta de colores Palette palette; // Paleta de colores
int x1; // Limite izquierdo de la ruta en el eje X int x1; // Limite izquierdo de la ruta en el eje X
int x2; // Limite derecho de la ruta en el eje X int x2; // Limite derecho de la ruta en el eje X
int y1; // Limite superior de la ruta en el eje Y int y1; // Limite superior de la ruta en el eje Y
@@ -74,5 +74,5 @@ public:
void reLoadTexture(); void reLoadTexture();
// Asigna la paleta // Asigna la paleta
void setPalette(palette_e pal); void setPalette(Palette pal);
}; };

View File

@@ -55,8 +55,8 @@ Game::Game()
item_tracker_ = new ItemTracker(); item_tracker_ = new ItemTracker();
room_tracker_ = new RoomTracker(); room_tracker_ = new RoomTracker();
room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, false); room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, false);
const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png"; const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani"; const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
const player_t player = {spawn_point_, playerPNG, playerANI, room_}; const player_t player = {spawn_point_, playerPNG, playerANI, room_};
player_ = new Player(player); player_ = new Player(player);
text_ = new Text(resource_->getOffset("smb2.txt"), resource_->getTexture("smb2.png"), renderer_); text_ = new Text(resource_->getOffset("smb2.txt"), resource_->getTexture("smb2.png"), renderer_);
@@ -93,7 +93,7 @@ Game::Game()
board_.items = 0; board_.items = 0;
board_.rooms = 1; board_.rooms = 1;
board_.music = true; board_.music = true;
board_.jailEnabled = options.cheat.jailEnabled; board_.jail_is_open = options.cheats.jail_is_open == Cheat::CheatState::ENABLED;
setScoreBoardColor(); setScoreBoardColor();
room_tracker_->addRoom(current_room_); room_tracker_->addRoom(current_room_);
paused_ = false; paused_ = false;
@@ -102,11 +102,10 @@ Game::Game()
total_items_ = getTotalItems(); total_items_ = getTotalItems();
initStats(); initStats();
stats_->addVisit(room_->getName()); stats_->addVisit(room_->getName());
const bool cheats = options.cheat.infiniteLives || options.cheat.invincible || options.cheat.jailEnabled; cheevos_->enable(!options.cheats.enabled()); // Deshabilita los logros si hay trucos activados
cheevos_->enable(!cheats); // Deshabilita los logros si hay trucos activados
options.section.name = SECTION_GAME; options.section.section = Section::GAME;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
} }
Game::~Game() Game::~Game()
@@ -141,7 +140,7 @@ void Game::checkEvents()
{ {
case SDL_SCANCODE_G: case SDL_SCANCODE_G:
debug_->switchEnabled(); debug_->switchEnabled();
options.cheat.invincible = debug_->getEnabled(); options.cheats.invincible = static_cast<Cheat::CheatState>(debug_->getEnabled());
board_.music = !debug_->getEnabled(); board_.music = !debug_->getEnabled();
board_.music ? JA_ResumeMusic() : JA_PauseMusic(); board_.music ? JA_ResumeMusic() : JA_PauseMusic();
break; break;
@@ -215,7 +214,7 @@ void Game::run()
JA_PauseMusic(); JA_PauseMusic();
} }
while (options.section.name == SECTION_GAME) while (options.section.section == Section::GAME)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -352,7 +351,7 @@ bool Game::changeRoom(std::string file)
room_ = nullptr; room_ = nullptr;
// Crea un objeto habitación nuevo a partir del fichero // Crea un objeto habitación nuevo a partir del fichero
room_ = new Room(resource_->getRoom(file), item_tracker_, &board_.items, board_.jailEnabled); room_ = new Room(resource_->getRoom(file), item_tracker_, &board_.items, board_.jail_is_open);
// Pone el nombre de la habitación en la textura // Pone el nombre de la habitación en la textura
fillRoomNameTexture(); fillRoomNameTexture();
@@ -425,22 +424,22 @@ void Game::checkGameOver()
{ {
if (board_.lives < 0 && black_screen_counter_ > 17) if (board_.lives < 0 && black_screen_counter_ > 17)
{ {
options.section.name = SECTION_GAME_OVER; options.section.section = Section::GAME_OVER;
} }
} }
// Mata al jugador // Mata al jugador
void Game::killPlayer() void Game::killPlayer()
{ {
if (options.cheat.invincible) if (options.cheats.invincible == Cheat::CheatState::ENABLED)
{ {
return; return;
} }
// Resta una vida al jugador // Resta una vida al jugador
if (!options.cheat.infiniteLives) if (options.cheats.infinite_lives == Cheat::CheatState::DISABLED)
{ {
board_.lives--; --board_.lives;
} }
// Actualiza las estadisticas // Actualiza las estadisticas
@@ -460,15 +459,15 @@ void Game::killPlayer()
setBlackScreen(); setBlackScreen();
// Crea la nueva habitación y el nuevo jugador // Crea la nueva habitación y el nuevo jugador
room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, board_.jailEnabled); room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, board_.jail_is_open);
const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png"; const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani"; const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
const player_t player = {spawn_point_, playerPNG, playerANI, room_}; const player_t player = {spawn_point_, playerPNG, playerANI, room_};
this->player_ = new Player(player); player_ = new Player(player);
// Pone los objetos en pausa mientras esta la habitación en negro // Pone los objetos en pausa mientras esta la habitación en negro
room_->pause(); room_->pause();
this->player_->pause(); player_->pause();
} }
// Recarga todas las texturas // Recarga todas las texturas
@@ -484,26 +483,6 @@ void Game::reLoadTextures()
text_->reLoadTexture(); text_->reLoadTexture();
} }
// Cambia la paleta
void Game::switchPalette()
{
if (options.console)
{
std::cout << "** PALETTE SWITCH REQUESTED" << std::endl;
}
// Modifica la variable
options.palette = (options.palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
// Recarga las paletas
room_->reLoadPalette();
player_->reLoadPalette();
scoreboard_->reLoadPalette();
// Pone el color del marcador en función del color del borde de la habitación
setScoreBoardColor();
}
// Establece la pantalla en negro // Establece la pantalla en negro
void Game::setBlackScreen() void Game::setBlackScreen()
{ {
@@ -534,7 +513,7 @@ void Game::renderBlackScreen()
if (black_screen_) if (black_screen_)
{ {
screen_->clean(); screen_->clean();
screen_->setBorderColor(stringToColor(options.palette, "black")); screen_->setBorderColor(stringToColor(options.video.palette, "black"));
} }
} }
@@ -542,25 +521,25 @@ void Game::renderBlackScreen()
void Game::setScoreBoardColor() void Game::setScoreBoardColor()
{ {
// Obtiene el color del borde // Obtiene el color del borde
const color_t colorBorder = room_->getBorderColor(); const Color colorBorder = room_->getBorderColor();
const bool isBlack = colorAreEqual(colorBorder, stringToColor(options.palette, "black")); const bool isBlack = colorAreEqual(colorBorder, stringToColor(options.video.palette, "black"));
const bool isBrightBlack = colorAreEqual(colorBorder, stringToColor(options.palette, "bright_black")); const bool isBrightBlack = colorAreEqual(colorBorder, stringToColor(options.video.palette, "bright_black"));
// Si el color del borde es negro o negro brillante cambia el texto del marcador a blanco // Si el color del borde es negro o negro brillante cambia el texto del marcador a blanco
board_.color = isBlack || isBrightBlack ? stringToColor(options.palette, "white") : colorBorder; board_.color = isBlack || isBrightBlack ? stringToColor(options.video.palette, "white") : colorBorder;
} }
// Comprueba si ha finalizado el juego // Comprueba si ha finalizado el juego
bool Game::checkEndGame() bool Game::checkEndGame()
{ {
const bool isOnTheRoom = room_->getName() == "THE JAIL"; // Estar en la habitación que toca const bool isOnTheRoom = room_->getName() == "THE JAIL"; // Estar en la habitación que toca
const bool haveTheItems = board_.items >= int(total_items_ * 0.9f) || options.cheat.jailEnabled; // Con mas del 90% de los items recogidos const bool haveTheItems = board_.items >= int(total_items_ * 0.9f) || options.cheats.jail_is_open == Cheat::CheatState::ENABLED; // Con mas del 90% de los items recogidos
const bool isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta) const bool isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
if (haveTheItems) if (haveTheItems)
{ {
board_.jailEnabled = true; board_.jail_is_open = true;
} }
if (haveTheItems && isOnTheRoom && isOnTheDoor) if (haveTheItems && isOnTheRoom && isOnTheDoor)
@@ -568,7 +547,7 @@ bool Game::checkEndGame()
// Comprueba los logros de completar el juego // Comprueba los logros de completar el juego
checkEndGameCheevos(); checkEndGameCheevos();
options.section.name = SECTION_ENDING; options.section.section = Section::ENDING;
return true; return true;
} }
@@ -671,7 +650,7 @@ void Game::fillRoomNameTexture()
SDL_SetRenderTarget(renderer_, room_name_texture_); SDL_SetRenderTarget(renderer_, room_name_texture_);
// Rellena la textura de color // Rellena la textura de color
const color_t color = stringToColor(options.palette, "white"); const Color color = stringToColor(options.video.palette, "white");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);

View File

@@ -20,8 +20,8 @@ class Stats;
class Text; class Text;
struct JA_Music_t; struct JA_Music_t;
struct JA_Sound_t; struct JA_Sound_t;
struct options_t; struct Options;
struct section_t; struct SectionState;
class Game class Game
{ {
@@ -104,9 +104,6 @@ private:
// Recarga todas las texturas // Recarga todas las texturas
void reLoadTextures(); void reLoadTextures();
// Cambia la paleta
void switchPalette();
// Establece la pantalla en negro // Establece la pantalla en negro
void setBlackScreen(); void setBlackScreen();

View File

@@ -32,8 +32,8 @@ GameOver::GameOver()
// Inicializa variables // Inicializa variables
preCounter = 0; preCounter = 0;
counter = 0; counter = 0;
options.section.name = SECTION_GAME_OVER; options.section.section = Section::GAME_OVER;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
ticks = 0; ticks = 0;
ticksSpeed = 15; ticksSpeed = 15;
endSection = 400; endSection = 400;
@@ -48,7 +48,7 @@ GameOver::GameOver()
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"}; const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (auto cl : colorList) for (auto cl : colorList)
{ {
colors.push_back(stringToColor(options.palette, cl)); colors.push_back(stringToColor(options.video.palette, cl));
} }
color = colors.back(); color = colors.back();
} }
@@ -116,7 +116,7 @@ void GameOver::render()
// Escribe el texto con "Tu peor pesadilla" // Escribe el texto con "Tu peor pesadilla"
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 110, "YOUR WORST NIGHTMARE IS", 1, color); text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 110, "YOUR WORST NIGHTMARE IS", 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options.stats.worstNightmare, 1, color); text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options.stats.worst_nightmare, 1, color);
// Vuelca el contenido del renderizador en pantalla // Vuelca el contenido del renderizador en pantalla
screen->render(); screen->render();
@@ -141,7 +141,7 @@ void GameOver::checkInput()
// Bucle principal // Bucle principal
void GameOver::run() void GameOver::run()
{ {
while (options.section.name == SECTION_GAME_OVER) while (options.section.section == Section::GAME_OVER)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -200,13 +200,7 @@ void GameOver::updateCounters()
// Comprueba si ha terminado la sección // Comprueba si ha terminado la sección
else if (counter == endSection) else if (counter == endSection)
{ {
options.section.name = SECTION_LOGO; options.section.section = Section::LOGO;
options.section.subsection = SUBSECTION_LOGO_TO_TITLE; options.section.subsection = Subsection::LOGO_TO_TITLE;
} }
}
// Cambia la paleta
void GameOver::switchPalette()
{
options.palette = (options.palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
} }

View File

@@ -27,16 +27,16 @@ private:
AnimatedSprite *tvSprite; // Sprite con el televisor AnimatedSprite *tvSprite; // Sprite con el televisor
// Variables // Variables
int preCounter; // Contador previo int preCounter; // Contador previo
int counter; // Contador int counter; // Contador
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
std::vector<color_t> colors; // Vector con los colores para el fade std::vector<Color> colors; // Vector con los colores para el fade
color_t color; // Color usado para el texto y los sprites Color color; // Color usado para el texto y los sprites
int endSection; // Contador: cuando acaba la sección int endSection; // Contador: cuando acaba la sección
int iniFade; // Contador: cuando emiepza el fade int iniFade; // Contador: cuando emiepza el fade
int fadeLenght; // Contador: duración del fade int fadeLenght; // Contador: duración del fade
JA_Music_t *music; // Musica que suena durante el juego JA_Music_t *music; // Musica que suena durante el juego
// Actualiza el objeto // Actualiza el objeto
void update(); void update();
@@ -59,9 +59,6 @@ private:
// Actualiza los contadores // Actualiza los contadores
void updateCounters(); void updateCounters();
// Cambia la paleta
void switchPalette();
public: public:
// Constructor // Constructor
GameOver(); GameOver();

View File

@@ -1,5 +1,5 @@
#include "global_events.h" #include "global_events.h"
#include "options.h" // Para Options, options, OptionsGame, OptionsAudio #include "options.h" // Para Options, options, OptionsGame, OptionsAudio
#include "mouse.h" #include "mouse.h"
namespace globalEvents namespace globalEvents
@@ -10,14 +10,14 @@ namespace globalEvents
// Evento de salida de la aplicación // Evento de salida de la aplicación
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
options.section.name = SECTION_QUIT; options.section.section = Section::QUIT;
return; return;
} }
if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET) if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
{ {
//reLoadTextures(); // reLoadTextures();
} }
Mouse::handleEvent(event); Mouse::handleEvent(event);
} }

View File

@@ -9,23 +9,23 @@ namespace globalInputs
// Cambia la paleta // Cambia la paleta
void switchPalette() void switchPalette()
{ {
options.palette = options.palette == p_zxspectrum ? p_zxarne : p_zxspectrum; options.video.palette = options.video.palette == Palette::ZXSPECTRUM ? Palette::ZXARNE : Palette::ZXSPECTRUM;
} }
// Cambia de seccion // Cambia de seccion
void skip_section() void skip_section()
{ {
switch (options.section.name) switch (options.section.section)
{ {
case SECTION_LOGO: case Section::LOGO:
case SECTION_LOADING_SCREEN: case Section::LOADING_SCREEN:
case SECTION_CREDITS: case Section::CREDITS:
case SECTION_DEMO: case Section::DEMO:
case SECTION_GAME_OVER: case Section::GAME_OVER:
case SECTION_ENDING: case Section::ENDING:
case SECTION_ENDING2: case Section::ENDING2:
options.section.name = SECTION_TITLE; options.section.section = Section::TITLE;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
break; break;
default: default:
@@ -38,7 +38,7 @@ namespace globalInputs
{ {
if (Input::get()->checkInput(input_exit, REPEAT_FALSE)) if (Input::get()->checkInput(input_exit, REPEAT_FALSE))
{ {
options.section.name = SECTION_QUIT; options.section.section = Section::QUIT;
} }
else if (Input::get()->checkInput(input_accept, REPEAT_FALSE)) else if (Input::get()->checkInput(input_accept, REPEAT_FALSE))
@@ -58,12 +58,12 @@ namespace globalInputs
else if (Input::get()->checkInput(input_window_dec_size, REPEAT_FALSE)) else if (Input::get()->checkInput(input_window_dec_size, REPEAT_FALSE))
{ {
Screen::get()->decWindowSize(); Screen::get()->decWindowZoom();
} }
else if (Input::get()->checkInput(input_window_inc_size, REPEAT_FALSE)) else if (Input::get()->checkInput(input_window_inc_size, REPEAT_FALSE))
{ {
Screen::get()->incWindowSize(); Screen::get()->incWindowZoom();
} }
else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE)) else if (Input::get()->checkInput(input_toggle_shaders, REPEAT_FALSE))

View File

@@ -17,7 +17,7 @@ Item::Item(item_t item)
counter = item.counter * colorChangeSpeed; counter = item.counter * colorChangeSpeed;
// Inicializa los colores // Inicializa los colores
color_t c = item.color1; Color c = item.color1;
color.push_back(c); color.push_back(c);
color.push_back(c); color.push_back(c);
@@ -67,7 +67,7 @@ void Item::reLoadTexture()
} }
// Asigna los colores del objeto // Asigna los colores del objeto
void Item::setColors(color_t col1, color_t col2) void Item::setColors(Color col1, Color col2)
{ {
// Reinicializa el vector de colores // Reinicializa el vector de colores
color.clear(); color.clear();

View File

@@ -17,8 +17,8 @@ struct item_t
int y; // Posición del item en pantalla int y; // Posición del item en pantalla
int tile; // Número de tile dentro de la textura int tile; // Número de tile dentro de la textura
int counter; // Contador inicial. Es el que lo hace cambiar de color int counter; // Contador inicial. Es el que lo hace cambiar de color
color_t color1; // Uno de los dos colores que se utiliza para el item Color color1; // Uno de los dos colores que se utiliza para el item
color_t color2; // Uno de los dos colores que se utiliza para el item Color color2; // Uno de los dos colores que se utiliza para el item
// Constructor por defecto // Constructor por defecto
item_t() : renderer(nullptr), texture(nullptr), x(0), y(0), tile(0), counter(0), color1(), color2() {} item_t() : renderer(nullptr), texture(nullptr), x(0), y(0), tile(0), counter(0), color1(), color2() {}
@@ -31,10 +31,10 @@ private:
Sprite *sprite; // Sprite del objeto Sprite *sprite; // Sprite del objeto
// Variables // Variables
std::vector<color_t> color; // Vector con los colores del objeto std::vector<Color> color; // Vector con los colores del objeto
int counter; // Contador interno int counter; // Contador interno
SDL_Rect collider; // Rectangulo de colisión SDL_Rect collider; // Rectangulo de colisión
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
public: public:
// Constructor // Constructor
@@ -59,5 +59,5 @@ public:
void reLoadTexture(); void reLoadTexture();
// Asigna los colores del objeto // Asigna los colores del objeto
void setColors(color_t col1, color_t col2); void setColors(Color col1, Color col2);
}; };

View File

@@ -23,12 +23,12 @@ LoadingScreen::LoadingScreen()
input_(Input::get()) input_(Input::get())
{ {
// Reserva memoria para los punteros // Reserva memoria para los punteros
if (options.palette == p_zxspectrum) if (options.video.palette == Palette::ZXSPECTRUM)
{ {
mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn.png"); mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn.png");
color_loading_screen_texture_ = resource_->getTexture("loading_screen_color.png"); color_loading_screen_texture_ = resource_->getTexture("loading_screen_color.png");
} }
else if (options.palette == p_zxarne) else if (options.video.palette == Palette::ZXARNE)
{ {
mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn_zxarne.png"); mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn_zxarne.png");
color_loading_screen_texture_ = resource_->getTexture("loading_screen_color_zxarne.png"); color_loading_screen_texture_ = resource_->getTexture("loading_screen_color_zxarne.png");
@@ -40,8 +40,8 @@ LoadingScreen::LoadingScreen()
loading_sound3_ = JA_LoadMusic(asset_->get("loading_sound3.ogg").c_str()); loading_sound3_ = JA_LoadMusic(asset_->get("loading_sound3.ogg").c_str());
// Inicializa variables // Inicializa variables
options.section.name = SECTION_LOADING_SCREEN; options.section.section = Section::LOADING_SCREEN;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
// Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum // Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum
for (int i = 0; i < 192; ++i) for (int i = 0; i < 192; ++i)
@@ -63,7 +63,7 @@ LoadingScreen::LoadingScreen()
} }
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.palette, "black")); screen_->setBorderColor(stringToColor(options.video.palette, "black"));
} }
// Destructor // Destructor
@@ -133,8 +133,8 @@ void LoadingScreen::updateLoad()
// Comprueba si ha terminado la intro // Comprueba si ha terminado la intro
if (load_counter_ >= 768) if (load_counter_ >= 768)
{ {
options.section.name = SECTION_TITLE; options.section.section = Section::TITLE;
options.section.subsection = SUBSECTION_TITLE_WITH_LOADING_SCREEN; options.section.subsection = Subsection::TITLE_WITH_LOADING_SCREEN;
JA_StopMusic(); JA_StopMusic();
} }
} }
@@ -161,23 +161,16 @@ void LoadingScreen::renderLoad()
void LoadingScreen::renderBorder() void LoadingScreen::renderBorder()
{ {
// Pinta el borde de colro azul // Pinta el borde de colro azul
color_t color = stringToColor(options.palette, "blue"); Color color = stringToColor(options.video.palette, "blue");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
// Añade lineas amarillas // Añade lineas amarillas
color = stringToColor(options.palette, "yellow"); color = stringToColor(options.video.palette, "yellow");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
const int width = GAMECANVAS_WIDTH + (options.borderWidth * 2); const int width = GAMECANVAS_WIDTH + (options.video.border.width * 2);
const int height = GAMECANVAS_HEIGHT + (options.borderHeight * 2); const int height = GAMECANVAS_HEIGHT + (options.video.border.height * 2);
bool drawEnabled = rand() % 2 == 0 ? true : false; bool drawEnabled = rand() % 2 == 0 ? true : false;
// Para (int i = 0; i < height; ++i)
//{
// if (rand() % 2 == 0)
// {
// SDL_RenderDrawLine(renderer, 0, i, width, i);
// }
// }
int row = 0; int row = 0;
int rowSize = 1; int rowSize = 1;
while (row < height) while (row < height)
@@ -218,7 +211,7 @@ void LoadingScreen::update()
// Dibuja en pantalla // Dibuja en pantalla
void LoadingScreen::render() void LoadingScreen::render()
{ {
if (options.borderEnabled) if (options.video.border.enabled)
{ {
// Prepara para empezar a dibujar en la textura del borde // Prepara para empezar a dibujar en la textura del borde
screen_->startDrawOnBorder(); screen_->startDrawOnBorder();
@@ -249,7 +242,7 @@ void LoadingScreen::run()
screen_->clean(); screen_->clean();
screen_->render(); screen_->render();
while (options.section.name == SECTION_LOADING_SCREEN) while (options.section.section == Section::LOADING_SCREEN)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -259,25 +252,6 @@ void LoadingScreen::run()
JA_SetVolume(128); JA_SetVolume(128);
} }
// Cambia la paleta
void LoadingScreen::switchPalette()
{
if (options.palette == p_zxspectrum)
{
options.palette = p_zxarne;
mono_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_bn_zxarne.png"));
color_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_color_zxarne.png"));
}
else
{
options.palette = p_zxspectrum;
mono_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_bn.png"));
color_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_color.png"));
}
recreateLoadingScreen();
}
// Reconstruye la pantalla de carga // Reconstruye la pantalla de carga
void LoadingScreen::recreateLoadingScreen() void LoadingScreen::recreateLoadingScreen()
{ {

View File

@@ -11,8 +11,8 @@ class Screen;
class Sprite; class Sprite;
class Texture; class Texture;
struct JA_Music_t; struct JA_Music_t;
struct options_t; struct Options;
struct section_t; struct SectionState;
class LoadingScreen class LoadingScreen
{ {
@@ -65,9 +65,6 @@ private:
// Dibuja el efecto de carga en el borde // Dibuja el efecto de carga en el borde
void renderBorder(); void renderBorder();
// Cambia la paleta
void switchPalette();
// Reconstruye la pantalla de carga // Reconstruye la pantalla de carga
void recreateLoadingScreen(); void recreateLoadingScreen();

View File

@@ -47,17 +47,17 @@ Logo::Logo()
} }
// Inicializa variables // Inicializa variables
options.section.name = SECTION_LOGO; options.section.section = Section::LOGO;
// Inicializa el vector de colores // Inicializa el vector de colores
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"}; const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
for (auto v : vColors) for (auto v : vColors)
{ {
color_.push_back(stringToColor(options.palette, v)); color_.push_back(stringToColor(options.video.palette, v));
} }
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.palette, "black")); screen_->setBorderColor(stringToColor(options.video.palette, "black"));
} }
// Destructor // Destructor
@@ -265,7 +265,7 @@ void Logo::run()
// Detiene la música // Detiene la música
JA_StopMusic(); JA_StopMusic();
while (options.section.name == SECTION_LOGO) while (options.section.section == Section::LOGO)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -276,13 +276,13 @@ void Logo::run()
// Termina la sección // Termina la sección
void Logo::endSection() void Logo::endSection()
{ {
if (options.section.subsection == SUBSECTION_LOGO_TO_TITLE) if (options.section.subsection == Subsection::LOGO_TO_TITLE)
{ {
options.section.name = SECTION_TITLE; options.section.section = Section::TITLE;
} }
else if (options.section.subsection == SUBSECTION_LOGO_TO_INTRO) else if (options.section.subsection == Subsection::LOGO_TO_INTRO)
{ {
options.section.name = SECTION_LOADING_SCREEN; options.section.section = Section::LOADING_SCREEN;
} }
} }

View File

@@ -10,9 +10,9 @@ class Resource; // lines 10-10
class Screen; // lines 11-11 class Screen; // lines 11-11
class Sprite; // lines 12-12 class Sprite; // lines 12-12
class Texture; // lines 13-13 class Texture; // lines 13-13
struct color_t; struct Color;
struct options_t; struct Options;
struct section_t; struct SectionState;
class Logo class Logo
{ {
@@ -29,13 +29,13 @@ private:
Sprite *since_1998_sprite_; // Sprite para manejar la textura2 Sprite *since_1998_sprite_; // Sprite para manejar la textura2
// Variables // Variables
std::vector<color_t> color_; // Vector con los colores para el fade std::vector<Color> color_; // Vector con los colores para el fade
int counter_ = 0; // Contador int counter_ = 0; // Contador
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa
int init_fade_ = 300; // Tiempo del contador cuando inicia el fade a negro int init_fade_ = 300; // Tiempo del contador cuando inicia el fade a negro
int end_logo_ = 400; // Tiempo del contador para terminar el logo int end_logo_ = 400; // Tiempo del contador para terminar el logo
int post_logo_ = 20; // Tiempo que dura el logo con el fade al maximo int post_logo_ = 20; // Tiempo que dura el logo con el fade al maximo
// Actualiza las variables // Actualiza las variables
void update(); void update();

View File

@@ -106,11 +106,11 @@ void Notifier::update()
const float step = ((float)notifications_[i].counter / notifications_[i].travelDist); const float step = ((float)notifications_[i].counter / notifications_[i].travelDist);
const int alpha = 255 * step; const int alpha = 255 * step;
if (options.notifications.posV == pos_top) if (options.notifications.getVerticalPosition() == "UPPER")
{ {
notifications_[i].rect.y++; notifications_[i].rect.y++;
} }
else else if (options.notifications.getVerticalPosition() == "BOTTOM")
{ {
notifications_[i].rect.y--; notifications_[i].rect.y--;
} }
@@ -138,11 +138,11 @@ void Notifier::update()
const float step = (notifications_[i].counter / (float)notifications_[i].travelDist); const float step = (notifications_[i].counter / (float)notifications_[i].travelDist);
const int alpha = 255 * (1 - step); const int alpha = 255 * (1 - step);
if (options.notifications.posV == pos_top) if (options.notifications.getVerticalPosition() == "UPPER")
{ {
notifications_[i].rect.y--; notifications_[i].rect.y--;
} }
else else if (options.notifications.getVerticalPosition() == "BOTTOM")
{ {
notifications_[i].rect.y++; notifications_[i].rect.y++;
} }
@@ -187,41 +187,41 @@ void Notifier::show(std::string text1, std::string text2, int icon)
// Posición horizontal // Posición horizontal
int despH = 0; int despH = 0;
if (options.notifications.posH == pos_left) if (options.notifications.getHorizontalPosition() == "LEFT")
{ {
despH = padding; despH = padding;
} }
else if (options.notifications.posH == pos_middle) else if (options.notifications.getHorizontalPosition() == "CENTER")
{ {
despH = ((options.screen.windowWidth * options.windowSize) / 2 - (width / 2)); despH = (options.game.width - width) / 2;
} }
else else if (options.notifications.getHorizontalPosition() == "RIGHT")
{ {
despH = (options.screen.windowWidth * options.windowSize) - width - padding; despH = options.game.width - width - padding;
} }
// Posición vertical // Posición vertical
int despV = 0; int despV = 0;
if (options.notifications.posV == pos_top) if (options.notifications.getVerticalPosition() == "UPPER")
{ {
despV = padding; despV = padding;
} }
else else
{ {
despV = (options.screen.windowHeight * options.windowSize) - height - padding; despV = options.game.height - height - padding;
} }
const int travelDist = height + padding; const int travelDist = height + padding;
// Offset // Offset
int offset = 0; int offset = 0;
if (options.notifications.posV == pos_top) if (options.notifications.getVerticalPosition() == "UPPER")
{ {
offset = (int)notifications_.size() > 0 ? notifications_.back().y + travelDist : despV; offset = static_cast<int>(notifications_.size()) > 0 ? notifications_.back().y + travelDist : despV;
} }
else else
{ {
offset = (int)notifications_.size() > 0 ? notifications_.back().y - travelDist : despV; offset = static_cast<int>(notifications_.size()) > 0 ? notifications_.back().y - travelDist : despV;
} }
// Crea la notificacion // Crea la notificacion
@@ -234,7 +234,7 @@ void Notifier::show(std::string text1, std::string text2, int icon)
n.state = ns_rising; n.state = ns_rising;
n.text1 = text1; n.text1 = text1;
n.text2 = text2; n.text2 = text2;
if (options.notifications.posV == pos_top) if (options.notifications.getVerticalPosition() == "UPPER")
{ {
n.rect = {despH, offset - travelDist, width, height}; n.rect = {despH, offset - travelDist, width, height};
} }
@@ -277,7 +277,7 @@ void Notifier::show(std::string text1, std::string text2, int icon)
} }
// Escribe el texto de la notificación // Escribe el texto de la notificación
color_t color = {255, 255, 255}; Color color = {255, 255, 255};
if (text2 != "") if (text2 != "")
{ // Dos lineas de texto { // Dos lineas de texto
text_->writeColored(padding + iconSpace, padding, text1, color); text_->writeColored(padding + iconSpace, padding, text1, color);

View File

@@ -57,7 +57,7 @@ private:
Text *text_; // Objeto para dibujar texto Text *text_; // Objeto para dibujar texto
// Variables // Variables
color_t bg_color_; // Color de fondo de las notificaciones Color bg_color_; // Color de fondo de las notificaciones
int wait_time_; // Tiempo que se ve la notificación int wait_time_; // Tiempo que se ve la notificación
std::vector<notification_t> notifications_; // La lista de notificaciones activas std::vector<notification_t> notifications_; // La lista de notificaciones activas
JA_Sound_t *sound_; // Sonido a reproducir cuando suena la notificación JA_Sound_t *sound_; // Sonido a reproducir cuando suena la notificación

View File

@@ -5,72 +5,33 @@
#include <iostream> // Para basic_ostream, operator<<, cout #include <iostream> // Para basic_ostream, operator<<, cout
// Variables // Variables
options_t options; Options options;
bool setOptions(std::string var, std::string value); bool setOptions(const std::string &var, const std::string &value);
// Crea e inicializa las opciones del programa
void initOptions() void initOptions()
{ {
// Version del archivo de configuración options = Options();
options.configVersion = "v1.06.1";
// Opciones de control
options.keys = ctrl_cursor;
// Opciones de video
options.gameWidth = GAMECANVAS_WIDTH;
options.gameHeight = GAMECANVAS_HEIGHT;
options.videoMode = 0;
options.windowSize = 3;
options.filter = FILTER_NEAREST;
options.shaders = false;
options.vSync = true;
options.integerScale = true;
options.keepAspect = true;
options.borderEnabled = true;
options.borderWidth = 32;
options.borderHeight = 24;
options.palette = p_zxspectrum;
#ifdef GAME_CONSOLE
options.windowSize = 2;
#endif
// Estos valores no se guardan en el fichero de configuración
options.console = false;
#ifdef DEBUG #ifdef DEBUG
options.section = SectionState(Section::TITLE, Subsection::NONE);
options.console = true; options.console = true;
#endif
options.cheat.infiniteLives = false;
options.cheat.invincible = false;
options.cheat.jailEnabled = false;
options.cheat.altSkin = false;
options.stats.rooms = 0;
options.stats.items = 0;
// Opciones de las notificaciones
options.notifications.posV = pos_top;
options.notifications.posH = pos_left;
options.notifications.sound = true;
options.notifications.color = {48, 48, 48};
#ifdef DEBUG
options.section.name = SECTION_TITLE;
options.section.subsection = SUBSECTION_LOGO_TO_INTRO;
#else #else
options.section.name = SECTION_LOGO; options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO);
options.section.subsection = SUBSECTION_LOGO_TO_INTRO; options.console = false;
#endif #endif
} }
// Carga las opciones desde un fichero
bool loadOptionsFromFile(const std::string &file_path) bool loadOptionsFromFile(const std::string &file_path)
{ {
// Indicador de éxito en la carga // Indicador de éxito en la carga
bool success = true; bool success = true;
// Versión actual del fichero // Versión actual del fichero
const std::string configVersion = options.configVersion; const std::string configVersion = options.version;
options.configVersion = ""; options.version = "";
// Variables para manejar el fichero // Variables para manejar el fichero
std::string line; std::string line;
@@ -114,137 +75,70 @@ bool loadOptionsFromFile(const std::string &file_path)
// El fichero no existe // El fichero no existe
else else
{ // Crea el fichero con los valores por defecto {
// Crea el fichero con los valores por defecto
saveOptionsToFile(file_path); saveOptionsToFile(file_path);
} }
// Si la versión de fichero no coincide, crea un fichero nuevo con los valores por defecto // Si la versión de fichero no coincide, crea un fichero nuevo con los valores por defecto
if (configVersion != options.configVersion) if (configVersion != options.version)
{ {
initOptions(); initOptions();
saveOptionsToFile(file_path); saveOptionsToFile(file_path);
} }
// Normaliza los valores // Normaliza los valores
const bool a = options.videoMode == 0; if (options.video.mode != 0 &&
const bool b = options.videoMode == SDL_WINDOW_FULLSCREEN; options.video.mode != SDL_WINDOW_FULLSCREEN &&
const bool c = options.videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP; options.video.mode != SDL_WINDOW_FULLSCREEN_DESKTOP)
if (!(a || b || c))
{ {
options.videoMode = 0; options.video.mode = 0;
}
if (options.windowSize < 1 || options.windowSize > 4)
{
options.windowSize = 3;
} }
return success; return success;
} }
// Guarda las opciones en un fichero
bool saveOptionsToFile(const std::string &file_path) bool saveOptionsToFile(const std::string &file_path)
{ {
bool success = true;
// Crea y abre el fichero de texto // Crea y abre el fichero de texto
std::ofstream file(file_path); std::ofstream file(file_path);
bool success = file.is_open(); // Verifica si el archivo se abrió correctamente
if (file.good()) if (!success) // Si no se pudo abrir el archivo, muestra un mensaje de error y devuelve false
{ {
if (options.console) if (options.console)
{ {
std::cout << file_path << " open for writing" << std::endl; std::cerr << "Error: Unable to open file " << file_path << " for writing." << std::endl;
} }
return false;
} }
else
if (options.console)
{ {
if (options.console) std::cout << file_path << " open for writing" << std::endl;
{
std::cout << file_path << " can't be opened" << std::endl;
}
} }
// Escribe en el fichero // Escribe en el fichero
file << "## VERSION\n"; file << "## VERSION\n";
file << "configVersion=" + options.configVersion + "\n"; file << "version=" << options.version << "\n";
file << "\n## CONTROL OPTIONS\n"; file << "\n## CONTROL\n";
file << "## keys = CURSOR | OPQA | WASD\n"; file << "## keys = CURSOR | OPQA | WASD\n";
if (options.keys == ctrl_cursor) file << "keys=" << static_cast<int>(options.keys) << "\n";
{
file << "keys=CURSOR\n";
}
else if (options.keys == ctrl_opqa)
{
file << "keys=OPQA\n";
}
else if (options.keys == ctrl_wasd)
{
file << "keys=WASD\n";
}
file << "\n## VISUAL OPTIONS\n"; file << "\n## VIDEO\n";
if (options.videoMode == 0) file << "video.mode=" << options.video.mode << "\n";
{ file << "window.zoom=" << options.window.zoom << "\n";
file << "videoMode=0\n"; file << "video.filter=" << static_cast<int>(options.video.filter) << "\n";
} file << "video.shaders=" << boolToString(options.video.shaders) << "\n";
file << "video.vertical_sync=" << boolToString(options.video.vertical_sync) << "\n";
else if (options.videoMode == SDL_WINDOW_FULLSCREEN) file << "video.integer_scale=" << boolToString(options.video.integer_scale) << "\n";
{ file << "video.keep_aspect=" << boolToString(options.video.keep_aspect) << "\n";
file << "videoMode=SDL_WINDOW_FULLSCREEN\n"; file << "video.border.enabled=" << boolToString(options.video.border.enabled) << "\n";
} file << "video.border.width=" << options.video.border.width << "\n";
file << "video.border.height=" << options.video.border.height << "\n";
else if (options.videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP) file << "video.palette=" << static_cast<int>(options.video.palette) << "\n";
{
file << "videoMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
}
file << "windowSize=" + std::to_string(options.windowSize) + "\n";
if (options.filter == FILTER_NEAREST)
{
file << "filter=FILTER_NEAREST\n";
}
else
{
file << "filter=FILTER_LINEAR\n";
}
file << "shaders=" + boolToString(options.shaders) + "\n";
file << "vSync=" + boolToString(options.vSync) + "\n";
file << "integerScale=" + boolToString(options.integerScale) + "\n";
file << "keepAspect=" + boolToString(options.keepAspect) + "\n";
file << "borderEnabled=" + boolToString(options.borderEnabled) + "\n";
file << "borderWidth=" + std::to_string(options.borderWidth) + "\n";
file << "borderHeight=" + std::to_string(options.borderHeight) + "\n";
file << "palette=" + std::to_string(options.palette) + "\n";
file << "\n## NOTIFICATION OPTIONS\n";
file << "## notifications.posV = pos_top | pos_bottom\n";
if (options.notifications.posV == pos_top)
{
file << "notifications.posV=pos_top\n";
}
else
{
file << "notifications.posV=pos_bottom\n";
}
file << "## notifications.posH = pos_left | pos_middle | pos_right\n";
if (options.notifications.posH == pos_left)
{
file << "notifications.posH=pos_left\n";
}
else if (options.notifications.posH == pos_middle)
{
file << "notifications.posH=pos_middle\n";
}
else
{
file << "notifications.posH=pos_right\n";
}
file << "notifications.sound=" + boolToString(options.notifications.sound) + "\n";
// Cierra el fichero // Cierra el fichero
file.close(); file.close();
@@ -252,160 +146,27 @@ bool saveOptionsToFile(const std::string &file_path)
return success; return success;
} }
bool setOptions(std::string var, std::string value) // Establece las opciones
{ bool setOptions(const std::string &var, const std::string &value) {
// Indicador de éxito en la asignación static const std::unordered_map<std::string, std::function<void(std::string)>> optionHandlers = {
bool success = true; {"version", [](std::string v) { options.version = v; }},
{"keys", [](std::string v) { options.keys = static_cast<ControlScheme>(safeStoi(v, static_cast<int>(ControlScheme::CURSOR))); }},
if (var == "configVersion") {"video.mode", [](std::string v) { options.video.mode = safeStoi(v, 0); }},
{ {"window.zoom", [](std::string v) { options.window.zoom = safeStoi(v, 1); }},
options.configVersion = value; {"video.shaders", [](std::string v) { options.video.shaders = stringToBool(v); }},
{"video.vertical_sync", [](std::string v) { options.video.vertical_sync = stringToBool(v); }},
{"video.integer_scale", [](std::string v) { options.video.integer_scale = stringToBool(v); }},
{"video.keep_aspect", [](std::string v) { options.video.keep_aspect = stringToBool(v); }},
{"video.border.enabled", [](std::string v) { options.video.border.enabled = stringToBool(v); }},
{"video.border.width", [](std::string v) { options.video.border.width = safeStoi(v, 32); }},
{"video.border.height", [](std::string v) { options.video.border.height = safeStoi(v, 24); }},
{"video.palette", [](std::string v) { options.video.palette = static_cast<Palette>(safeStoi(v, static_cast<int>(DEFAULT_PALETTE))); }}
};
auto it = optionHandlers.find(var);
if (it != optionHandlers.end()) {
it->second(value);
return true;
} }
return false;
else if (var == "keys")
{
if (value == "OPQA")
{
options.keys = ctrl_opqa;
}
else if (value == "WASD")
{
options.keys = ctrl_wasd;
}
else
{
options.keys = ctrl_cursor;
}
}
else if (var == "videoMode")
{
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
{
options.videoMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
else if (value == "SDL_WINDOW_FULLSCREEN")
{
options.videoMode = SDL_WINDOW_FULLSCREEN;
}
else
{
options.videoMode = 0;
}
}
else if (var == "windowSize")
{
options.windowSize = std::stoi(value);
if ((options.windowSize < 1) || (options.windowSize > 4))
{
options.windowSize = 3;
}
}
else if (var == "filter")
{
if (value == "FILTER_LINEAR")
{
options.filter = FILTER_LINEAR;
}
else
{
options.filter = FILTER_NEAREST;
}
}
else if (var == "shaders")
{
options.shaders = stringToBool(value);
}
else if (var == "vSync")
{
options.vSync = stringToBool(value);
}
else if (var == "integerScale")
{
options.integerScale = stringToBool(value);
}
else if (var == "keepAspect")
{
options.keepAspect = stringToBool(value);
}
else if (var == "borderEnabled")
{
options.borderEnabled = stringToBool(value);
}
else if (var == "borderWidth")
{
options.borderWidth = std::stoi(value);
}
else if (var == "borderHeight")
{
options.borderHeight = std::stoi(value);
}
else if (var == "palette")
{
const int pal = std::stoi(value);
if (pal == 0)
{
options.palette = p_zxspectrum;
}
else if (pal == 1)
{
options.palette = p_zxarne;
}
}
else if (var == "notifications.posH")
{
if (value == "pos_left")
{
options.notifications.posH = pos_left;
}
else if (value == "pos_middle")
{
options.notifications.posH = pos_middle;
}
else
{
options.notifications.posH = pos_right;
}
}
else if (var == "notifications.posV")
{
if (value == "pos_top")
{
options.notifications.posV = pos_top;
}
else
{
options.notifications.posV = pos_bottom;
}
}
else if (var == "notifications.sound")
{
options.notifications.sound = stringToBool(value);
}
else if (var == "" || var.substr(0, 1) == "#")
{
}
else
{
success = false;
}
return success;
} }

View File

@@ -4,110 +4,366 @@
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32 #include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include "utils.h" #include "utils.h"
#include "screen.h"
constexpr int DEFAULT_WINDOW_WIDTH = 320; // Ancho de la ventana por defecto
constexpr int DEFAULT_WINDOW_HEIGHT = 240; // Alto de la ventana por defecto
constexpr int DEFAULT_WINDOW_ZOOM = 2; // Zoom de la ventana por defecto
constexpr int DEFAULT_VIDEO_MODE = 0; // Modo de pantalla completa por defecto
constexpr int DEFAULT_BORDER_WIDTH = 32; // Ancho del borde por defecto
constexpr int DEFAULT_BORDER_HEIGHT = 24; // Alto del borde por defecto
constexpr Palette DEFAULT_PALETTE = Palette::ZXSPECTRUM; // Paleta por defecto
// Secciones del programa // Secciones del programa
constexpr int SECTION_LOGO = 0; enum class Section
constexpr int SECTION_LOADING_SCREEN = 1; {
constexpr int SECTION_TITLE = 2; LOGO,
constexpr int SECTION_CREDITS = 3; LOADING_SCREEN,
constexpr int SECTION_GAME = 4; TITLE,
constexpr int SECTION_DEMO = 5; CREDITS,
constexpr int SECTION_GAME_OVER = 6; GAME,
constexpr int SECTION_ENDING = 7; DEMO,
constexpr int SECTION_ENDING2 = 8; GAME_OVER,
constexpr int SECTION_QUIT = 9; ENDING,
ENDING2,
QUIT
};
// Subsecciones // Subsecciones
constexpr int SUBSECTION_LOGO_TO_INTRO = 0; enum class Subsection
constexpr int SUBSECTION_LOGO_TO_TITLE = 1; {
constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2; NONE,
constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3; LOGO_TO_INTRO,
LOGO_TO_TITLE,
TITLE_WITH_LOADING_SCREEN,
TITLE_WITHOUT_LOADING_SCREEN
};
// Posiciones de las notificaciones // Posiciones de las notificaciones
enum not_pos_e enum class NotificationPosition
{ {
pos_top, UPPER_LEFT,
pos_bottom, UPPER_CENTER,
pos_left, UPPER_RIGHT,
pos_middle, MIDDLE_LEFT,
pos_right MIDDLE_RIGHT,
BOTTOM_LEFT,
BOTTOM_CENTER,
BOTTOM_RIGHT
}; };
// Tipos de control de teclado // Tipos de control de teclado
enum ctrl_schem_e enum class ControlScheme
{ {
ctrl_cursor, CURSOR,
ctrl_opqa, OPQA,
ctrl_wasd WASD
}; };
// Estructura para las opciones de las notificaciones // Estructura para las opciones de las notificaciones
struct op_notification_t struct OptionsNotification
{ {
not_pos_e posH; // Ubicación de las notificaciones en pantalla NotificationPosition pos; // Ubicación de las notificaciones en pantalla
not_pos_e posV; // Ubicación de las notificaciones en pantalla bool sound; // Indica si las notificaciones suenan
bool sound; // Indica si las notificaciones suenan Color color; // Color de las notificaciones
color_t color; // Color de las notificaciones
// Constructor por defecto
OptionsNotification()
{
pos = NotificationPosition::UPPER_LEFT;
sound = true;
color = {48, 48, 48};
}
// Constructor
OptionsNotification(NotificationPosition p, bool s, Color c)
{
pos = p;
sound = s;
color = c;
}
// Método que devuelve la posición horizontal
std::string getHorizontalPosition() const
{
switch (pos)
{
case NotificationPosition::UPPER_LEFT:
case NotificationPosition::MIDDLE_LEFT:
case NotificationPosition::BOTTOM_LEFT:
return "LEFT";
case NotificationPosition::UPPER_CENTER:
case NotificationPosition::BOTTOM_CENTER:
return "CENTER";
case NotificationPosition::UPPER_RIGHT:
case NotificationPosition::MIDDLE_RIGHT:
case NotificationPosition::BOTTOM_RIGHT:
return "RIGHT";
}
return "UNKNOWN";
}
// Método que devuelve la posición vertical
std::string getVerticalPosition() const
{
switch (pos)
{
case NotificationPosition::UPPER_LEFT:
case NotificationPosition::UPPER_CENTER:
case NotificationPosition::UPPER_RIGHT:
return "UPPER";
case NotificationPosition::MIDDLE_LEFT:
case NotificationPosition::MIDDLE_RIGHT:
return "MIDDLE";
case NotificationPosition::BOTTOM_LEFT:
case NotificationPosition::BOTTOM_CENTER:
case NotificationPosition::BOTTOM_RIGHT:
return "BOTTOM";
}
return "UNKNOWN";
}
}; };
// Estructura para saber la seccion y subseccion del programa // Estructura para saber la seccion y subseccion del programa
struct section_t struct SectionState
{ {
Uint8 name; Section section;
Uint8 subsection; Subsection subsection;
// Constructor por defecto
SectionState()
{
section = Section::LOGO;
subsection = Subsection::LOGO_TO_INTRO;
}
// Constructor
SectionState(Section s, Subsection ss)
{
section = s;
subsection = ss;
}
}; };
// Estructura para albergar trucos // Estructura para albergar trucos
struct cheat_t struct Cheat
{ {
bool infiniteLives; // Indica si el jugador dispone de vidas infinitas enum class CheatState : bool
bool invincible; // Indica si el jugador puede morir {
bool jailEnabled; // Indica si la Jail está abierta DISABLED = false,
bool altSkin; // Indicxa si se usa una skin diferente para el jugador ENABLED = true
};
CheatState infinite_lives; // Indica si el jugador dispone de vidas infinitas
CheatState invincible; // Indica si el jugador puede morir
CheatState jail_is_open; // Indica si la Jail está abierta
CheatState alternate_skin; // Indica si se usa una skin diferente para el jugador
// Constructor por defecto
Cheat()
: infinite_lives(CheatState::DISABLED),
invincible(CheatState::DISABLED),
jail_is_open(CheatState::DISABLED),
alternate_skin(CheatState::DISABLED)
{
}
// Constructor
Cheat(CheatState il, CheatState i, CheatState je, CheatState as)
: infinite_lives(il),
invincible(i),
jail_is_open(je),
alternate_skin(as)
{
}
// Método para comprobar si alguno de los tres primeros trucos está activo
bool enabled() const
{
return infinite_lives == CheatState::ENABLED ||
invincible == CheatState::ENABLED ||
jail_is_open == CheatState::ENABLED;
}
}; };
// Estructura para almacenar estadísticas // Estructura para almacenar estadísticas
struct op_stats_t struct OptionsStats
{ {
int rooms; // Cantidad de habitaciones visitadas int rooms; // Cantidad de habitaciones visitadas
int items; // Cantidad de items obtenidos int items; // Cantidad de items obtenidos
std::string worstNightmare; // Habitación con más muertes acumuladas std::string worst_nightmare; // Habitación con más muertes acumuladas
// Constructor por defecto
OptionsStats()
{
rooms = 0;
items = 0;
worst_nightmare = "";
}
// Constructor
OptionsStats(int r, int i, std::string wn)
{
rooms = r;
items = i;
worst_nightmare = wn;
}
}; };
// Estructura con opciones de la pantalla // Estructura con opciones de la pantalla
struct op_screen_t struct OptionsWindows
{ {
int windowWidth; // Ancho de la ventana int width; // Ancho de la ventana
int windowHeight; // Alto de la ventana int height; // Alto de la ventana
int zoom; // Zoom de la ventana
// Constructor por defecto
OptionsWindows()
{
width = DEFAULT_WINDOW_WIDTH;
height = DEFAULT_WINDOW_HEIGHT;
zoom = DEFAULT_WINDOW_ZOOM;
}
// Constructor
OptionsWindows(int w, int h, int z)
{
width = w;
height = h;
zoom = z;
}
};
// Estructura para gestionar el borde de la pantalla
struct Border
{
bool enabled; // Indica si se ha de mostrar el borde
int width; // Ancho del borde
int height; // Alto del borde
// Constructor por defecto
Border()
{
enabled = true;
width = DEFAULT_BORDER_WIDTH;
height = DEFAULT_BORDER_HEIGHT;
}
// Constructor
Border(bool e, int w, int h)
{
enabled = e;
width = w;
height = h;
}
};
// Estructura para las opciones de video
struct OptionsVideo
{
Uint32 mode; // Contiene el valor del modo de pantalla completa
ScreenFilter filter; // Filtro usado para el escalado de la imagen
bool vertical_sync; // Indica si se quiere usar vsync o no
bool shaders; // Indica si se van a usar shaders o no
bool integer_scale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
bool keep_aspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
Border border; // Borde de la pantalla
Palette palette; // Paleta de colores a usar en el juego
// Constructor por defecto
OptionsVideo()
{
mode = DEFAULT_VIDEO_MODE;
filter = ScreenFilter::NEAREST;
vertical_sync = true;
shaders = false;
integer_scale = true;
keep_aspect = true;
border = Border();
palette = DEFAULT_PALETTE;
}
// Constructor
OptionsVideo(Uint32 m, ScreenFilter f, bool vs, bool s, bool is, bool ka, Border b, Palette p)
{
mode = m;
filter = f;
vertical_sync = vs;
shaders = s;
integer_scale = is;
keep_aspect = ka;
border = b;
palette = p;
}
};
// Estructura para las opciones de juego
struct OptionsGame
{
int width; // Ancho de la resolucion nativa del juego
int height; // Alto de la resolucion nativa del juego
// Constructor por defecto
OptionsGame()
{
width = 320;
height = 240;
}
// Constructor
OptionsGame(int w, int h)
{
width = w;
height = h;
}
}; };
// Estructura con todas las opciones de configuración del programa // Estructura con todas las opciones de configuración del programa
struct options_t struct Options
{ {
std::string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles std::string version; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
Uint32 videoMode; // Contiene el valor del modo de pantalla completa bool console; // Indica si ha de mostrar información por la consola de texto
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana Cheat cheats; // Contiene trucos y ventajas para el juego
Uint32 filter; // Filtro usado para el escalado de la imagen OptionsGame game; // Opciones de juego
bool vSync; // Indica si se quiere usar vsync o no OptionsVideo video; // Opciones de video
bool shaders; // Indica si se van a usar shaders o no OptionsStats stats; // Datos con las estadisticas de juego
int gameWidth; // Ancho de la resolucion nativa del juego OptionsNotification notifications; // Opciones relativas a las notificaciones;
int gameHeight; // Alto de la resolucion nativa del juego OptionsWindows window; // Opciones relativas a la ventana
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa ControlScheme keys; // Teclas usadas para jugar
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa SectionState section; // Sección actual del programa
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana // Constructor por defecto
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana Options()
palette_e palette; // Paleta de colores a usar en el juego {
bool console; // Indica si ha de mostrar información por la consola de texto version = "v1.07";
cheat_t cheat; // Contiene trucos y ventajas para el juego console = false;
op_stats_t stats; // Datos con las estadisticas de juego cheats = Cheat();
op_notification_t notifications; // Opciones relativas a las notificaciones; game = OptionsGame();
op_screen_t screen; // Opciones relativas a la clase screen video = OptionsVideo();
ctrl_schem_e keys; // Teclas usadas para jugar stats = OptionsStats();
section_t section; // Sección actual del programa notifications = OptionsNotification();
window = OptionsWindows();
keys = ControlScheme::CURSOR;
section = SectionState();
}
// Constructor
Options(std::string cv, bool c, Cheat ch, OptionsGame g, OptionsVideo v, OptionsStats s, OptionsNotification n, OptionsWindows sw, ControlScheme k, SectionState sec)
{
version = cv;
console = c;
cheats = ch;
game = g;
video = v;
stats = s;
notifications = n;
window = sw;
keys = k;
section = sec;
}
}; };
extern options_t options; extern Options options;
// Crea e inicializa las opciones del programa // Crea e inicializa las opciones del programa
void initOptions(); void initOptions();

View File

@@ -785,14 +785,20 @@ void Player::reLoadTexture()
// Recarga la paleta // Recarga la paleta
void Player::reLoadPalette() void Player::reLoadPalette()
{ {
color = stringToColor(options.palette, "white"); color = stringToColor(options.video.palette, "white");
if (options.cheat.infiniteLives) if (options.cheats.infinite_lives == Cheat::CheatState::ENABLED)
{ {
color = stringToColor(options.palette, "yellow"); color = stringToColor(options.video.palette, "green");
} }
if (options.cheat.invincible)
{ {
color = stringToColor(options.palette, "cyan"); color = stringToColor(options.video.palette, "yellow");
}
if (options.cheats.invincible == Cheat::CheatState::ENABLED)
{
color = stringToColor(options.video.palette, "green");
}
{
color = stringToColor(options.video.palette, "cyan");
} }
} }

View File

@@ -58,7 +58,7 @@ public:
float vy; // Velocidad/desplazamiento del jugador en el eje Y float vy; // Velocidad/desplazamiento del jugador en el eje Y
int w; // Ancho del jugador int w; // Ancho del jugador
int h; // ALto del jugador int h; // ALto del jugador
color_t color; // Color del jugador Color color; // Color del jugador
SDL_Rect colliderBox; // Caja de colisión con los enemigos u objetos SDL_Rect colliderBox; // Caja de colisión con los enemigos u objetos
std::vector<SDL_Point> colliderPoints; // Puntos de colisión con el mapa std::vector<SDL_Point> colliderPoints; // Puntos de colisión con el mapa
std::vector<SDL_Point> underFeet; // Contiene los puntos que hay bajo cada pie del jugador std::vector<SDL_Point> underFeet; // Contiene los puntos que hay bajo cada pie del jugador
@@ -82,7 +82,7 @@ public:
#ifdef DEBUG #ifdef DEBUG
SDL_Rect rx; // Rectangulo de desplazamiento para el modo debug SDL_Rect rx; // Rectangulo de desplazamiento para el modo debug
SDL_Rect ry; // Rectangulo de desplazamiento para el modo debug SDL_Rect ry; // Rectangulo de desplazamiento para el modo debug
color_t debugColor; // Color del recuadro de debug del jugador Color debugColor; // Color del recuadro de debug del jugador
SDL_Point debugPoint; // Punto para debug SDL_Point debugPoint; // Punto para debug
#endif #endif

View File

@@ -6,7 +6,7 @@
class Asset; class Asset;
class Texture; class Texture;
struct animatedSprite_t; struct animatedSprite_t;
struct options_t; struct Options;
struct room_t; struct room_t;
struct textFile_t; struct textFile_t;

View File

@@ -95,7 +95,7 @@ room_t loadRoomFile(std::string file_path, bool verbose)
enemy.flip = false; enemy.flip = false;
enemy.mirror = false; enemy.mirror = false;
enemy.frame = -1; enemy.frame = -1;
enemy.palette = p_zxspectrum; enemy.palette = Palette::ZXSPECTRUM;
do do
{ {
@@ -123,8 +123,8 @@ room_t loadRoomFile(std::string file_path, bool verbose)
{ {
item_t item; item_t item;
item.counter = 0; item.counter = 0;
item.color1 = stringToColor(p_zxspectrum, "yellow"); item.color1 = stringToColor(Palette::ZXSPECTRUM, "yellow");
item.color2 = stringToColor(p_zxspectrum, "magenta"); item.color2 = stringToColor(Palette::ZXSPECTRUM, "magenta");
do do
{ {
@@ -428,7 +428,7 @@ Room::Room(room_t *room, ItemTracker *itemTracker, int *itemsPicked, bool jailEn
textureA = room->textureA; textureA = room->textureA;
textureB = room->textureB; textureB = room->textureB;
tileMap = *room->tileMap; tileMap = *room->tileMap;
texture = (options.palette == p_zxspectrum) ? textureA : textureB; texture = (options.video.palette == Palette::ZXSPECTRUM) ? textureA : textureB;
this->jailEnabled = jailEnabled; this->jailEnabled = jailEnabled;
// Inicializa variables // Inicializa variables
@@ -443,7 +443,7 @@ Room::Room(room_t *room, ItemTracker *itemTracker, int *itemsPicked, bool jailEn
for (auto &enemy : room->enemies) for (auto &enemy : room->enemies)
{ {
enemy.renderer = renderer; enemy.renderer = renderer;
enemy.palette = options.palette; enemy.palette = options.video.palette;
enemies.push_back(new Enemy(enemy)); enemies.push_back(new Enemy(enemy));
} }
@@ -455,8 +455,8 @@ Room::Room(room_t *room, ItemTracker *itemTracker, int *itemsPicked, bool jailEn
if (!itemTracker->hasBeenPicked(room->name, itemPos)) if (!itemTracker->hasBeenPicked(room->name, itemPos))
{ {
item.renderer = renderer; item.renderer = renderer;
item.color1 = stringToColor(options.palette, itemColor1); item.color1 = stringToColor(options.video.palette, itemColor1);
item.color2 = stringToColor(options.palette, itemColor2); item.color2 = stringToColor(options.video.palette, itemColor2);
items.push_back(new Item(item)); items.push_back(new Item(item));
} }
} }
@@ -497,7 +497,7 @@ Room::Room(room_t *room, ItemTracker *itemTracker, int *itemsPicked, bool jailEn
fillMapTexture(); fillMapTexture();
// Establece el color del borde // Establece el color del borde
screen->setBorderColor(stringToColor(options.palette, room->borderColor)); screen->setBorderColor(stringToColor(options.video.palette, room->borderColor));
} }
// Destructor // Destructor
@@ -530,21 +530,21 @@ std::string Room::getName()
} }
// Devuelve el color de la habitación // Devuelve el color de la habitación
color_t Room::getBGColor() Color Room::getBGColor()
{ {
return stringToColor(options.palette, bgColor); return stringToColor(options.video.palette, bgColor);
} }
// Devuelve el color del borde // Devuelve el color del borde
color_t Room::getBorderColor() Color Room::getBorderColor()
{ {
return stringToColor(options.palette, borderColor); return stringToColor(options.video.palette, borderColor);
} }
// Crea la textura con el mapeado de la habitación // Crea la textura con el mapeado de la habitación
void Room::fillMapTexture() void Room::fillMapTexture()
{ {
const color_t color = stringToColor(options.palette, bgColor); const Color color = stringToColor(options.video.palette, bgColor);
SDL_SetRenderTarget(renderer, mapTexture); SDL_SetRenderTarget(renderer, mapTexture);
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
@@ -870,20 +870,20 @@ void Room::reLoadPalette()
// Cambia el color de los items // Cambia el color de los items
for (auto item : items) for (auto item : items)
{ {
item->setColors(stringToColor(options.palette, itemColor1), stringToColor(options.palette, itemColor2)); item->setColors(stringToColor(options.video.palette, itemColor1), stringToColor(options.video.palette, itemColor2));
} }
// Cambia el color de los enemigos // Cambia el color de los enemigos
for (auto enemy : enemies) for (auto enemy : enemies)
{ {
enemy->setPalette(options.palette); enemy->setPalette(options.video.palette);
} }
// Establece el color del borde // Establece el color del borde
screen->setBorderColor(stringToColor(options.palette, borderColor)); screen->setBorderColor(stringToColor(options.video.palette, borderColor));
// Cambia la textura // Cambia la textura
texture = (options.palette == p_zxspectrum) ? textureA : textureB; texture = (options.video.palette == Palette::ZXSPECTRUM) ? textureA : textureB;
// Pone la nueva textura a los tiles animados // Pone la nueva textura a los tiles animados
for (auto tile : aTile) for (auto tile : aTile)

View File

@@ -168,10 +168,10 @@ public:
std::string getName(); std::string getName();
// Devuelve el color de la habitación // Devuelve el color de la habitación
color_t getBGColor(); Color getBGColor();
// Devuelve el color del borde // Devuelve el color del borde
color_t getBorderColor(); Color getBorderColor();
// Dibuja el mapa en pantalla // Dibuja el mapa en pantalla
void renderMap(); void renderMap();

View File

@@ -20,7 +20,7 @@ Scoreboard::Scoreboard(board_t *board)
{ {
// Reserva memoria para los objetos // Reserva memoria para los objetos
itemTexture = resource->getTexture("items.png"); itemTexture = resource->getTexture("items.png");
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani"; const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
sprite = new AnimatedSprite(renderer, resource->getAnimation(playerANI)); sprite = new AnimatedSprite(renderer, resource->getAnimation(playerANI));
sprite->setCurrentAnimation("walk_menu"); sprite->setCurrentAnimation("walk_menu");
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer); text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
@@ -31,13 +31,13 @@ Scoreboard::Scoreboard(board_t *board)
paused = false; paused = false;
timePaused = 0; timePaused = 0;
totalTimePaused = 0; totalTimePaused = 0;
itemsColor = stringToColor(options.palette, "white"); itemsColor = stringToColor(options.video.palette, "white");
// Inicializa el vector de colores // Inicializa el vector de colores
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"}; const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
for (auto v : vColors) for (auto v : vColors)
{ {
color.push_back(stringToColor(options.palette, v)); color.push_back(stringToColor(options.video.palette, v));
} }
} }
@@ -76,7 +76,7 @@ void Scoreboard::render()
// Muestra si suena la música // Muestra si suena la música
if (board->music) if (board->music)
{ {
const color_t c = board->color; const Color c = board->color;
SDL_Rect clip = {0, 8, 8, 8}; SDL_Rect clip = {0, 8, 8, 8};
itemTexture->setColor(c.r, c.g, c.b); itemTexture->setColor(c.r, c.g, c.b);
itemTexture->render(renderer, 20 * BLOCK, line2, &clip); itemTexture->render(renderer, 20 * BLOCK, line2, &clip);
@@ -88,11 +88,11 @@ void Scoreboard::render()
this->text->writeColored(BLOCK, line1, "Items collected ", board->color); this->text->writeColored(BLOCK, line1, "Items collected ", board->color);
this->text->writeColored(17 * BLOCK, line1, itemsTxt, itemsColor); this->text->writeColored(17 * BLOCK, line1, itemsTxt, itemsColor);
this->text->writeColored(20 * BLOCK, line1, " Time ", board->color); this->text->writeColored(20 * BLOCK, line1, " Time ", board->color);
this->text->writeColored(26 * BLOCK, line1, timeTxt, stringToColor(options.palette, "white")); this->text->writeColored(26 * BLOCK, line1, timeTxt, stringToColor(options.video.palette, "white"));
const std::string roomsTxt = std::to_string(board->rooms / 100) + std::to_string((board->rooms % 100) / 10) + std::to_string(board->rooms % 10); const std::string roomsTxt = std::to_string(board->rooms / 100) + std::to_string((board->rooms % 100) / 10) + std::to_string(board->rooms % 10);
this->text->writeColored(22 * BLOCK, line2, "Rooms", stringToColor(options.palette, "white")); this->text->writeColored(22 * BLOCK, line2, "Rooms", stringToColor(options.video.palette, "white"));
this->text->writeColored(28 * BLOCK, line2, roomsTxt, stringToColor(options.palette, "white")); this->text->writeColored(28 * BLOCK, line2, roomsTxt, stringToColor(options.video.palette, "white"));
} }
// Actualiza las variables del objeto // Actualiza las variables del objeto
@@ -141,7 +141,7 @@ void Scoreboard::reLoadPalette()
color.clear(); color.clear();
for (auto v : vColors) for (auto v : vColors)
{ {
color.push_back(stringToColor(options.palette, v)); color.push_back(stringToColor(options.video.palette, v));
} }
} }
@@ -162,18 +162,18 @@ void Scoreboard::resume()
// Actualiza el color de la cantidad de items recogidos // Actualiza el color de la cantidad de items recogidos
void Scoreboard::updateItemsColor() void Scoreboard::updateItemsColor()
{ {
if (!board->jailEnabled) if (!board->jail_is_open)
{ {
return; return;
} }
if (counter % 20 < 10) if (counter % 20 < 10)
{ {
itemsColor = stringToColor(options.palette, "white"); itemsColor = stringToColor(options.video.palette, "white");
} }
else else
{ {
itemsColor = stringToColor(options.palette, "magenta"); itemsColor = stringToColor(options.video.palette, "magenta");
} }
} }

View File

@@ -13,13 +13,13 @@ class Texture;
struct board_t struct board_t
{ {
int items; // Lleva la cuenta de los objetos recogidos int items; // Lleva la cuenta de los objetos recogidos
int lives; // Lleva la cuenta de ls vidas restantes del jugador int lives; // Lleva la cuenta de ls vidas restantes del jugador
int rooms; // Lleva la cuenta de las habitaciones visitadas int rooms; // Lleva la cuenta de las habitaciones visitadas
bool music; // Indica si ha de sonar la musica durante el juego bool music; // Indica si ha de sonar la musica durante el juego
color_t color; // Color para escribir el texto del marcador Color color; // Color para escribir el texto del marcador
Uint32 iniClock; // Tiempo inicial para calcular el tiempo transcurrido Uint32 iniClock; // Tiempo inicial para calcular el tiempo transcurrido
bool jailEnabled; // Indica si se puede entrar a la Jail bool jail_is_open; // Indica si se puede entrar a la Jail
}; };
class Scoreboard class Scoreboard
@@ -43,14 +43,14 @@ private:
board_t *board; // Contiene las variables a mostrar en el marcador board_t *board; // Contiene las variables a mostrar en el marcador
// Variables // Variables
std::vector<color_t> color; // Vector con los colores del objeto std::vector<Color> color; // Vector con los colores del objeto
int counter; // Contador interno int counter; // Contador interno
int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color int colorChangeSpeed; // Cuanto mas alto, mas tarda en cambiar de color
bool paused; // Indica si el marcador esta en modo pausa bool paused; // Indica si el marcador esta en modo pausa
Uint32 timePaused; // Milisegundos que ha estado el marcador en pausa Uint32 timePaused; // Milisegundos que ha estado el marcador en pausa
Uint32 totalTimePaused; // Tiempo acumulado en pausa Uint32 totalTimePaused; // Tiempo acumulado en pausa
clock_t clock; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida clock_t clock; // Contiene las horas, minutos y segundos transcurridos desde el inicio de la partida
color_t itemsColor; // Color de la cantidad de items recogidos Color itemsColor; // Color de la cantidad de items recogidos
// Obtiene el tiempo transcurrido de partida // Obtiene el tiempo transcurrido de partida
clock_t getTime(); clock_t getTime();

View File

@@ -40,8 +40,8 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
: window_(window), : window_(window),
renderer_(renderer) renderer_(renderer)
{ {
game_canvas_width_ = options.gameWidth; game_canvas_width_ = options.game.width;
game_canvas_height_ = options.gameHeight; game_canvas_height_ = options.game.height;
notification_logical_width_ = game_canvas_width_; notification_logical_width_ = game_canvas_width_;
notification_logical_height_ = game_canvas_height_; notification_logical_height_ = game_canvas_height_;
@@ -62,7 +62,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
} }
// Crea la textura donde se dibuja el borde que rodea el area de juego // Crea la textura donde se dibuja el borde que rodea el area de juego
border_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_ + options.borderWidth * 2, game_canvas_height_ + options.borderHeight * 2); border_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_ + options.video.border.width * 2, game_canvas_height_ + options.video.border.height * 2);
if (border_canvas_ == nullptr) if (border_canvas_ == nullptr)
{ {
if (options.console) if (options.console)
@@ -73,7 +73,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
setBorderColor(border_color_); setBorderColor(border_color_);
// Establece el modo de video // Establece el modo de video
setVideoMode(options.videoMode); setVideoMode(options.video.mode);
// Muestra la ventana // Muestra la ventana
SDL_ShowWindow(window); SDL_ShowWindow(window);
@@ -87,7 +87,7 @@ Screen::~Screen()
} }
// Limpia la pantalla // Limpia la pantalla
void Screen::clean(color_t color) void Screen::clean(Color color)
{ {
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF); SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
@@ -112,7 +112,7 @@ void Screen::render()
renderNotifications(); renderNotifications();
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas // Si está el borde activo, vuelca gameCanvas sobre borderCanvas
if (options.borderEnabled) if (options.video.border.enabled)
{ {
gameCanvasToBorderCanvas(); gameCanvasToBorderCanvas();
} }
@@ -134,11 +134,11 @@ void Screen::setVideoMode(int videoMode)
SDL_ShowCursor(SDL_ENABLE); SDL_ShowCursor(SDL_ENABLE);
// Modifica el tamaño de la ventana en función del borde // Modifica el tamaño de la ventana en función del borde
if (options.borderEnabled) if (options.video.border.enabled)
{ {
window_width_ = game_canvas_width_ + options.borderWidth * 2; window_width_ = game_canvas_width_ + options.video.border.width * 2;
window_height_ = game_canvas_height_ + options.borderHeight * 2; window_height_ = game_canvas_height_ + options.video.border.height * 2;
dest_ = {options.borderWidth, options.borderHeight, game_canvas_width_, game_canvas_height_}; dest_ = {options.video.border.width, options.video.border.height, game_canvas_width_, game_canvas_height_};
} }
else else
@@ -149,7 +149,7 @@ void Screen::setVideoMode(int videoMode)
} }
// Modifica el tamaño de la ventana // Modifica el tamaño de la ventana
SDL_SetWindowSize(window_, window_width_ * options.windowSize, window_height_ * options.windowSize); SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom);
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
} }
@@ -163,7 +163,7 @@ void Screen::setVideoMode(int videoMode)
SDL_GetWindowSize(window_, &window_width_, &window_height_); SDL_GetWindowSize(window_, &window_width_, &window_height_);
// Aplica el escalado al rectangulo donde se pinta la textura del juego // Aplica el escalado al rectangulo donde se pinta la textura del juego
if (options.integerScale) if (options.video.integer_scale)
{ {
// Calcula el tamaño de la escala máxima // Calcula el tamaño de la escala máxima
int scale = 0; int scale = 0;
@@ -177,7 +177,7 @@ void Screen::setVideoMode(int videoMode)
dest_.x = (window_width_ - dest_.w) / 2; dest_.x = (window_width_ - dest_.w) / 2;
dest_.y = (window_height_ - dest_.h) / 2; dest_.y = (window_height_ - dest_.h) / 2;
} }
else if (options.keepAspect) else if (options.video.keep_aspect)
{ {
float ratio = (float)game_canvas_width_ / (float)game_canvas_height_; float ratio = (float)game_canvas_width_ / (float)game_canvas_height_;
if ((window_width_ - game_canvas_width_) >= (window_height_ - game_canvas_height_)) if ((window_width_ - game_canvas_width_) >= (window_height_ - game_canvas_height_))
@@ -207,18 +207,18 @@ void Screen::setVideoMode(int videoMode)
SDL_RenderSetLogicalSize(renderer_, window_width_, window_height_); SDL_RenderSetLogicalSize(renderer_, window_width_, window_height_);
// Actualiza las opciones // Actualiza las opciones
options.videoMode = videoMode; options.video.mode = videoMode;
options.screen.windowWidth = window_width_; options.window.width = window_width_;
options.screen.windowHeight = window_height_; options.window.height = window_height_;
// Reinicia los shaders // Reinicia los shaders
if (options.shaders) if (options.video.shaders)
{ {
const std::string glsl_file = options.screen.windowHeight == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl"; const std::string glsl_file = options.window.height == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
std::ifstream f(Asset::get()->get(glsl_file).c_str()); std::ifstream f(Asset::get()->get(glsl_file).c_str());
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()); std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
if (options.borderEnabled) if (options.video.border.enabled)
{ {
shader::init(window_, border_canvas_, source.c_str()); shader::init(window_, border_canvas_, source.c_str());
} }
@@ -232,35 +232,35 @@ void Screen::setVideoMode(int videoMode)
// Camibia entre pantalla completa y ventana // Camibia entre pantalla completa y ventana
void Screen::toggleVideoMode() void Screen::toggleVideoMode()
{ {
options.videoMode = (options.videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0; options.video.mode = (options.video.mode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
setVideoMode(options.videoMode); setVideoMode(options.video.mode);
} }
// Cambia el tamaño de la ventana // Cambia el tamaño de la ventana
void Screen::setWindowSize(int size) void Screen::setWindowZoom(int size)
{ {
options.windowSize = size; options.window.zoom = size;
setVideoMode(0); setVideoMode(0);
} }
// Reduce el tamaño de la ventana // Reduce el tamaño de la ventana
void Screen::decWindowSize() void Screen::decWindowZoom()
{ {
--options.windowSize; --options.window.zoom;
options.windowSize = std::max(options.windowSize, 1); options.window.zoom = std::max(options.window.zoom, 1);
setVideoMode(0); setVideoMode(0);
} }
// Aumenta el tamaño de la ventana // Aumenta el tamaño de la ventana
void Screen::incWindowSize() void Screen::incWindowZoom()
{ {
++options.windowSize; ++options.window.zoom;
options.windowSize = std::min(options.windowSize, 4); options.window.zoom = std::min(options.window.zoom, 4);
setVideoMode(0); setVideoMode(0);
} }
// Cambia el color del borde // Cambia el color del borde
void Screen::setBorderColor(color_t color) void Screen::setBorderColor(Color color)
{ {
border_color_ = color; border_color_ = color;
auto temp = SDL_GetRenderTarget(renderer_); auto temp = SDL_GetRenderTarget(renderer_);
@@ -279,33 +279,27 @@ void Screen::setBlendMode(SDL_BlendMode blendMode)
// Establece el tamaño del borde // Establece el tamaño del borde
void Screen::setBorderWidth(int s) void Screen::setBorderWidth(int s)
{ {
options.borderWidth = s; options.video.border.width = s;
} }
// Establece el tamaño del borde // Establece el tamaño del borde
void Screen::setBorderHeight(int s) void Screen::setBorderHeight(int s)
{ {
options.borderHeight = s; options.video.border.height = s;
} }
// Establece si se ha de ver el borde en el modo ventana // Establece si se ha de ver el borde en el modo ventana
void Screen::setBorderEnabled(bool value) void Screen::setBorderEnabled(bool value) { options.video.border.enabled = value; }
{
options.borderEnabled = value;
}
// Cambia entre borde visible y no visible // Cambia entre borde visible y no visible
void Screen::toggleBorder() void Screen::toggleBorder()
{ {
options.borderEnabled = !options.borderEnabled; options.video.border.enabled = !options.video.border.enabled;
setVideoMode(0); setVideoMode(0);
} }
// Activa el fade // Activa el fade
void Screen::setFade() void Screen::setFade() { fade_ = true; }
{
fade_ = true;
}
// Comprueba si ha terminado el fade // Comprueba si ha terminado el fade
bool Screen::fadeEnded() bool Screen::fadeEnded()
@@ -367,7 +361,7 @@ void Screen::renderFade()
} }
const SDL_Rect rect = {0, 0, game_canvas_width_, game_canvas_height_}; const SDL_Rect rect = {0, 0, game_canvas_width_, game_canvas_height_};
color_t color = {0, 0, 0}; Color color = {0, 0, 0};
const float step = (float)fade_counter_ / (float)fade_lenght_; const float step = (float)fade_counter_ / (float)fade_lenght_;
const int alpha = 0 + (255 - 0) * step; const int alpha = 0 + (255 - 0) * step;
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, alpha); SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, alpha);
@@ -387,7 +381,7 @@ void Screen::iniSpectrumFade()
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"}; const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
for (auto v : vColors) for (auto v : vColors)
{ {
spectrum_color_.push_back(stringToColor(options.palette, v)); spectrum_color_.push_back(stringToColor(options.video.palette, v));
} }
} }
@@ -418,7 +412,7 @@ void Screen::renderSpectrumFade()
const float step = (float)spectrum_fade_counter_ / (float)spectrum_fade_lenght_; const float step = (float)spectrum_fade_counter_ / (float)spectrum_fade_lenght_;
const int max = spectrum_color_.size() - 1; const int max = spectrum_color_.size() - 1;
const int index = max + (0 - max) * step; const int index = max + (0 - max) * step;
const color_t c = spectrum_color_[index]; const Color c = spectrum_color_[index];
SDL_SetTextureColorMod(game_canvas_, c.r, c.g, c.b); SDL_SetTextureColorMod(game_canvas_, c.r, c.g, c.b);
} }
@@ -460,14 +454,14 @@ void Screen::renderPresent()
SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF); SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
if (options.shaders) if (options.video.shaders)
{ {
// Aplica shaders y renderiza el contenido // Aplica shaders y renderiza el contenido
shader::render(); shader::render();
} }
else else
{ {
if (options.borderEnabled) if (options.video.border.enabled)
{ {
SDL_RenderCopy(renderer_, border_canvas_, nullptr, nullptr); SDL_RenderCopy(renderer_, border_canvas_, nullptr, nullptr);
} }
@@ -482,8 +476,8 @@ void Screen::renderPresent()
// Cambia el estado de los shaders // Cambia el estado de los shaders
void Screen::toggleShaders() void Screen::toggleShaders()
{ {
options.shaders = !options.shaders; options.video.shaders = !options.video.shaders;
setVideoMode(options.videoMode); setVideoMode(options.video.mode);
} }
// Actualiza la lógica de la clase // Actualiza la lógica de la clase

View File

@@ -10,8 +10,12 @@
class Asset; class Asset;
class Notifier; class Notifier;
constexpr int FILTER_NEAREST = 0; // Tipos de filtro
constexpr int FILTER_LINEAR = 1; enum class ScreenFilter : Uint32
{
NEAREST = 0,
LINEAR = 1,
};
class Screen class Screen
{ {
@@ -31,18 +35,18 @@ private:
int game_canvas_width_; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego int game_canvas_width_; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
int game_canvas_height_; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego int game_canvas_height_; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
SDL_Rect dest_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana SDL_Rect dest_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
color_t border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla Color border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla
int notification_logical_width_; // Ancho lógico de las notificaciones en relación al tamaño de pantalla int notification_logical_width_; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
int notification_logical_height_; // Alto lógico de las notificaciones en relación al tamaño de pantalla int notification_logical_height_; // Alto lógico de las notificaciones en relación al tamaño de pantalla
// Variables - Efectos // Variables - Efectos
bool fade_; // Indica si esta activo el efecto de fade bool fade_; // Indica si esta activo el efecto de fade
int fade_counter_; // Temporizador para el efecto de fade int fade_counter_; // Temporizador para el efecto de fade
int fade_lenght_; // Duración del fade int fade_lenght_; // Duración del fade
bool spectrum_fade_; // Indica si esta activo el efecto de fade spectrum bool spectrum_fade_; // Indica si esta activo el efecto de fade spectrum
int spectrum_fade_counter_; // Temporizador para el efecto de fade spectrum int spectrum_fade_counter_; // Temporizador para el efecto de fade spectrum
int spectrum_fade_lenght_; // Duración del fade spectrum int spectrum_fade_lenght_; // Duración del fade spectrum
std::vector<color_t> spectrum_color_; // Colores para el fade spectrum std::vector<Color> spectrum_color_; // Colores para el fade spectrum
// Inicializa las variables para el fade // Inicializa las variables para el fade
void iniFade(); void iniFade();
@@ -88,7 +92,7 @@ public:
static Screen *get(); static Screen *get();
// Limpia la pantalla // Limpia la pantalla
void clean(color_t color = {0x00, 0x00, 0x00}); void clean(Color color = {0x00, 0x00, 0x00});
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
void start(); void start();
@@ -109,16 +113,16 @@ public:
void toggleVideoMode(); void toggleVideoMode();
// Cambia el tamaño de la ventana // Cambia el tamaño de la ventana
void setWindowSize(int size); void setWindowZoom(int size);
// Reduce el tamaño de la ventana // Reduce el tamaño de la ventana
void decWindowSize(); void decWindowZoom();
// Aumenta el tamaño de la ventana // Aumenta el tamaño de la ventana
void incWindowSize(); void incWindowZoom();
// Cambia el color del borde // Cambia el color del borde
void setBorderColor(color_t color); void setBorderColor(Color color);
// Cambia el tipo de mezcla // Cambia el tipo de mezcla
void setBlendMode(SDL_BlendMode blendMode); void setBlendMode(SDL_BlendMode blendMode);

View File

@@ -183,7 +183,7 @@ void Stats::checkWorstNightmare()
if (item.died > deaths) if (item.died > deaths)
{ {
deaths = item.died; deaths = item.died;
options.stats.worstNightmare = item.name; options.stats.worst_nightmare = item.name;
} }
} }
} }

View File

@@ -2,7 +2,7 @@
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include <vector> // Para vector #include <vector> // Para vector
struct options_t; struct Options;
class Stats class Stats
{ {

View File

@@ -147,7 +147,7 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght)
} }
// Escribe el texto con colores // Escribe el texto con colores
void Text::writeColored(int x, int y, std::string text, color_t color, int kerning, int lenght) void Text::writeColored(int x, int y, std::string text, Color color, int kerning, int lenght)
{ {
sprite->getTexture()->setColor(color.r, color.g, color.b); sprite->getTexture()->setColor(color.r, color.g, color.b);
write(x, y, text, kerning, lenght); write(x, y, text, kerning, lenght);
@@ -155,7 +155,7 @@ void Text::writeColored(int x, int y, std::string text, color_t color, int kerni
} }
// Escribe el texto con sombra // Escribe el texto con sombra
void Text::writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance, int kerning, int lenght) void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shadowDistance, int kerning, int lenght)
{ {
sprite->getTexture()->setColor(color.r, color.g, color.b); sprite->getTexture()->setColor(color.r, color.g, color.b);
write(x + shadowDistance, y + shadowDistance, text, kerning, lenght); write(x + shadowDistance, y + shadowDistance, text, kerning, lenght);
@@ -171,7 +171,7 @@ void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght
} }
// Escribe texto con extras // Escribe texto con extras
void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, color_t textColor, Uint8 shadowDistance, color_t shadowColor, int lenght) void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Color textColor, Uint8 shadowDistance, Color shadowColor, int lenght)
{ {
const bool centered = ((flags & TXT_CENTER) == TXT_CENTER); const bool centered = ((flags & TXT_CENTER) == TXT_CENTER);
const bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW); const bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW);

View File

@@ -54,16 +54,16 @@ public:
void write(int x, int y, std::string text, int kerning = 1, int lenght = -1); void write(int x, int y, std::string text, int kerning = 1, int lenght = -1);
// Escribe el texto con colores // Escribe el texto con colores
void writeColored(int x, int y, std::string text, color_t color, int kerning = 1, int lenght = -1); void writeColored(int x, int y, std::string text, Color color, int kerning = 1, int lenght = -1);
// Escribe el texto con sombra // Escribe el texto con sombra
void writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1); void writeShadowed(int x, int y, std::string text, Color color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1);
// Escribe el texto centrado en un punto x // Escribe el texto centrado en un punto x
void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1); void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1);
// Escribe texto con extras // Escribe texto con extras
void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = color_t(255, 255, 255), Uint8 shadowDistance = 1, color_t shadowColor = color_t(0, 0, 0), int lenght = -1); void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, Color textColor = Color(255, 255, 255), Uint8 shadowDistance = 1, Color shadowColor = Color(0, 0, 0), int lenght = -1);
// Obtiene la longitud en pixels de una cadena // Obtiene la longitud en pixels de una cadena
int lenght(std::string text, int kerning = 1); int lenght(std::string text, int kerning = 1);

View File

@@ -27,11 +27,11 @@ Title::Title()
input_(Input::get()) input_(Input::get())
{ {
// Reserva memoria para los punteros // Reserva memoria para los punteros
if (options.palette == p_zxspectrum) if (options.video.palette == Palette::ZXSPECTRUM)
{ {
texture_ = resource_->getTexture("title_logo.png"); texture_ = resource_->getTexture("title_logo.png");
} }
else if (options.palette == p_zxarne) else if (options.video.palette == Palette::ZXARNE)
{ {
texture_ = resource_->getTexture("title_logo.png"); texture_ = resource_->getTexture("title_logo.png");
} }
@@ -57,16 +57,16 @@ Title::Title()
pSetSource(loading_screen_); pSetSource(loading_screen_);
// Inicializa variables // Inicializa variables
state_ = options.section.subsection == SUBSECTION_TITLE_WITH_LOADING_SCREEN ? show_loading_screen : show_menu; state_ = options.section.subsection == Subsection::TITLE_WITH_LOADING_SCREEN ? show_loading_screen : show_menu;
options.section.name = SECTION_TITLE; options.section.section = Section::TITLE;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
initMarquee(); initMarquee();
// Crea y rellena la textura para mostrar los logros // Crea y rellena la textura para mostrar los logros
createCheevosTexture(); createCheevosTexture();
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.palette, "black")); screen_->setBorderColor(stringToColor(options.video.palette, "black"));
// Rellena la textura de fondo con todos los gráficos // Rellena la textura de fondo con todos los gráficos
fillTexture(); fillTexture();
@@ -107,7 +107,7 @@ void Title::checkEvents()
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
globalEvents::check(event); globalEvents::check(event);
// Solo se comprueban estas teclas si no está activo el menu de logros // Solo se comprueban estas teclas si no está activo el menu de logros
if (event.type == SDL_KEYDOWN) if (event.type == SDL_KEYDOWN)
{ {
@@ -116,8 +116,8 @@ void Title::checkEvents()
switch (event.key.keysym.scancode) switch (event.key.keysym.scancode)
{ {
case SDL_SCANCODE_1: case SDL_SCANCODE_1:
options.section.name = SECTION_GAME; options.section.section = Section::GAME;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
break; break;
case SDL_SCANCODE_2: case SDL_SCANCODE_2:
@@ -200,7 +200,7 @@ void Title::renderMarquee()
{ {
if (l.enabled) if (l.enabled)
{ {
text_->writeColored(l.x, 184, l.letter, stringToColor(options.palette, "white")); text_->writeColored(l.x, 184, l.letter, stringToColor(options.video.palette, "white"));
} }
} }
} }
@@ -258,8 +258,8 @@ void Title::update()
{ {
if (!show_cheevos_) if (!show_cheevos_)
{ {
options.section.name = SECTION_CREDITS; options.section.section = Section::CREDITS;
options.section.subsection = 0; options.section.subsection = Subsection::NONE;
} }
} }
break; break;
@@ -275,7 +275,7 @@ void Title::render()
{ {
// Prepara para empezar a dibujar en la textura de juego // Prepara para empezar a dibujar en la textura de juego
screen_->start(); screen_->start();
screen_->clean(stringToColor(options.palette, "black")); screen_->clean(stringToColor(options.video.palette, "black"));
if (state_ == show_menu) if (state_ == show_menu)
{ {
@@ -309,7 +309,7 @@ void Title::render()
// Bucle para el logo del juego // Bucle para el logo del juego
void Title::run() void Title::run()
{ {
while (options.section.name == SECTION_TITLE) while (options.section.section == Section::TITLE)
{ {
update(); update();
checkEvents(); checkEvents();
@@ -321,11 +321,11 @@ void Title::run()
void Title::reLoadTextures() void Title::reLoadTextures()
{ {
// Carga la textura adecuada // Carga la textura adecuada
if (options.palette == p_zxspectrum) if (options.video.palette == Palette::ZXSPECTRUM)
{ {
texture_ = resource_->getTexture("loading_screen_color.png"); texture_ = resource_->getTexture("loading_screen_color.png");
} }
else if (options.palette == p_zxarne) else if (options.video.palette == Palette::ZXARNE)
{ {
texture_ = resource_->getTexture("loading_screen_color_zxarne.png"); texture_ = resource_->getTexture("loading_screen_color_zxarne.png");
} }
@@ -336,19 +336,19 @@ void Title::reLoadTextures()
// Cambia la paleta // Cambia la paleta
void Title::switchPalette() void Title::switchPalette()
{ {
if (options.palette == p_zxspectrum) if (options.video.palette == Palette::ZXSPECTRUM)
{ {
options.palette = p_zxarne; options.video.palette = Palette::ZXARNE;
sprite_->setTexture(resource_->getTexture("loading_screen_color_zxarne.png")); sprite_->setTexture(resource_->getTexture("loading_screen_color_zxarne.png"));
} }
else else
{ {
options.palette = p_zxspectrum; options.video.palette = Palette::ZXSPECTRUM;
sprite_->setTexture(resource_->getTexture("loading_screen_color.png")); sprite_->setTexture(resource_->getTexture("loading_screen_color.png"));
} }
// Cambia el color del borde // Cambia el color del borde
screen_->setBorderColor(stringToColor(options.palette, "bright_blue")); screen_->setBorderColor(stringToColor(options.video.palette, "bright_blue"));
} }
// Desplaza la lista de logros // Desplaza la lista de logros
@@ -377,7 +377,7 @@ void Title::fillTexture()
SDL_SetRenderTarget(renderer_, bg_texture_); SDL_SetRenderTarget(renderer_, bg_texture_);
// Rellena la textura de color // Rellena la textura de color
const color_t c = stringToColor(options.palette, "black"); const Color c = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF); SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
@@ -385,7 +385,7 @@ void Title::fillTexture()
sprite_->render(); sprite_->render();
// Escribe el texto en la textura // Escribe el texto en la textura
const color_t textColor = stringToColor(options.palette, "green"); const Color textColor = stringToColor(options.video.palette, "green");
const int textSize = text_->getCharacterSize(); const int textSize = text_->getCharacterSize();
text_->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, 11 * textSize, "1.PLAY", 1, textColor); text_->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, 11 * textSize, "1.PLAY", 1, textColor);
text_->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, 13 * textSize, "2.ACHIEVEMENTS", 1, textColor); text_->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, 13 * textSize, "2.ACHIEVEMENTS", 1, textColor);
@@ -413,7 +413,7 @@ void Title::createCheevosTexture()
cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND); cheevos_texture_->setBlendMode(SDL_BLENDMODE_BLEND);
// Rellena la textura con color sólido // Rellena la textura con color sólido
const color_t cheevosBGColor = stringToColor(options.palette, "black"); const Color cheevosBGColor = stringToColor(options.video.palette, "black");
SDL_SetRenderDrawColor(renderer_, cheevosBGColor.r, cheevosBGColor.g, cheevosBGColor.b, 0xFF); SDL_SetRenderDrawColor(renderer_, cheevosBGColor.r, cheevosBGColor.g, cheevosBGColor.b, 0xFF);
SDL_RenderClear(renderer_); SDL_RenderClear(renderer_);
@@ -421,11 +421,11 @@ void Title::createCheevosTexture()
const std::string cheevosOwner = "ACHIEVEMENTS"; const std::string cheevosOwner = "ACHIEVEMENTS";
const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->count()) + ")"; const std::string cheevosListCaption = cheevosOwner + " (" + std::to_string(Cheevos::get()->unlocked()) + " / " + std::to_string(Cheevos::get()->count()) + ")";
int pos = 2; int pos = 2;
info_text_->writeDX(TXT_CENTER | TXT_COLOR, cheevos_texture_->getWidth() / 2, pos, cheevosListCaption, 1, stringToColor(options.palette, "bright_green")); info_text_->writeDX(TXT_CENTER | TXT_COLOR, cheevos_texture_->getWidth() / 2, pos, cheevosListCaption, 1, stringToColor(options.video.palette, "bright_green"));
pos += info_text_->getCharacterSize(); pos += info_text_->getCharacterSize();
const color_t cheevoLockedColor = stringToColor(options.palette, "white"); const Color cheevoLockedColor = stringToColor(options.video.palette, "white");
const color_t cheevoUnlockedColor = stringToColor(options.palette, "bright_green"); const Color cheevoUnlockedColor = stringToColor(options.video.palette, "bright_green");
color_t cheevoColor; Color cheevoColor;
SDL_SetRenderDrawColor(renderer_, cheevoLockedColor.r, cheevoLockedColor.g, cheevoLockedColor.b, 0xFF); SDL_SetRenderDrawColor(renderer_, cheevoLockedColor.r, cheevoLockedColor.g, cheevoLockedColor.b, 0xFF);
const int lineX1 = (cheevosTextureWidth / 7) * 3; const int lineX1 = (cheevosTextureWidth / 7) * 3;
const int lineX2 = lineX1 + ((cheevosTextureWidth / 7) * 1); const int lineX2 = lineX1 + ((cheevosTextureWidth / 7) * 1);

View File

@@ -16,8 +16,8 @@ class Screen;
class Sprite; class Sprite;
class Text; class Text;
class Texture; class Texture;
struct options_t; struct Options;
struct section_t; struct SectionState;
class Title class Title
{ {
@@ -37,17 +37,17 @@ private:
}; };
// Objetos y punteros // Objetos y punteros
Screen *screen_; // Objeto encargado de dibujar en pantalla Screen *screen_; // Objeto encargado de dibujar en pantalla
SDL_Renderer *renderer_; // El renderizador de la ventana SDL_Renderer *renderer_; // El renderizador de la ventana
Resource *resource_; // Objeto con los recursos Resource *resource_; // Objeto con los recursos
Input *input_; // Objeto pata gestionar la entrada Input *input_; // Objeto pata gestionar la entrada
Texture *texture_; // Textura con los graficos Texture *texture_; // Textura con los graficos
Sprite *sprite_; // Sprite para manejar la textura Sprite *sprite_; // Sprite para manejar la textura
SDL_Texture *bg_texture_; // Textura para dibujar el fondo de la pantalla SDL_Texture *bg_texture_; // Textura para dibujar el fondo de la pantalla
Text *text_; // Objeto para escribir texto en pantalla Text *text_; // Objeto para escribir texto en pantalla
Text *info_text_; // Objeto para escribir texto en pantalla Text *info_text_; // Objeto para escribir texto en pantalla
Texture *cheevos_texture_; // Textura con la lista de logros Texture *cheevos_texture_; // Textura con la lista de logros
Sprite *cheevos_sprite_; // Sprite para manejar la textura con la lista de logros Sprite *cheevos_sprite_; // Sprite para manejar la textura con la lista de logros
// Variables // Variables
int counter_ = 0; // Contador int counter_ = 0; // Contador

View File

@@ -1,7 +1,9 @@
#include "utils.h" #include "utils.h"
#include <filesystem> // Para path #include <filesystem> // Para path
#include <stdlib.h> // Para free, malloc, abs #include <stdlib.h> // Para free, malloc, abs
#include <cmath> // Para round, abs #include <cmath> // Para round, abs
#include <algorithm>
#include <cctype>
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos
double distanceSquared(int x1, int y1, int x2, int y2) double distanceSquared(int x1, int y1, int x2, int y2)
@@ -12,7 +14,7 @@ double distanceSquared(int x1, int y1, int x2, int y2)
} }
// Detector de colisiones entre dos circulos // Detector de colisiones entre dos circulos
bool checkCollision(circle_t &a, circle_t &b) bool checkCollision(Circle &a, Circle &b)
{ {
// Calcula el radio total al cuadrado // Calcula el radio total al cuadrado
int totalRadiusSquared = a.r + b.r; int totalRadiusSquared = a.r + b.r;
@@ -30,7 +32,7 @@ bool checkCollision(circle_t &a, circle_t &b)
} }
// Detector de colisiones entre un circulo y un rectangulo // Detector de colisiones entre un circulo y un rectangulo
bool checkCollision(circle_t &a, SDL_Rect &b) bool checkCollision(Circle &a, SDL_Rect &b)
{ {
// Closest point on collision box // Closest point on collision box
int cX, cY; int cX, cY;
@@ -350,9 +352,9 @@ bool checkCollision(SDL_Point &p, d_line_t &l)
} }
// Devuelve un color_t a partir de un string // Devuelve un color_t a partir de un string
color_t stringToColor(palette_e pal, std::string str) Color stringToColor(Palette pal, std::string str)
{ {
if (pal == p_zxspectrum) if (pal == Palette::ZXSPECTRUM)
{ {
if (str == "black") if (str == "black")
{ {
@@ -435,8 +437,8 @@ color_t stringToColor(palette_e pal, std::string str)
} }
} }
else if (pal == p_zxarne) else if (pal == Palette::ZXARNE)
{ // zxarne {
if (str == "black") if (str == "black")
{ {
return {0x00, 0x00, 0x00}; return {0x00, 0x00, 0x00};
@@ -521,34 +523,35 @@ color_t stringToColor(palette_e pal, std::string str)
return {0x00, 0x00, 0x00}; return {0x00, 0x00, 0x00};
} }
// Convierte una cadena en un valor booleano // Convierte una cadena a un entero de forma segura
bool stringToBool(std::string str) int safeStoi(const std::string &value, int defaultValue)
{ {
if (str == "true") try
{ {
return true; return std::stoi(value);
} }
else catch (const std::exception &)
{ {
return false; return defaultValue;
} }
} }
// Convierte un valor booleano en una cadena // Convierte una cadena a un booleano
bool stringToBool(const std::string &str)
{
std::string lowerStr = str;
std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), ::tolower);
return (lowerStr == "true" || lowerStr == "1" || lowerStr == "yes" || lowerStr == "on");
}
// Convierte un booleano a una cadena
std::string boolToString(bool value) std::string boolToString(bool value)
{ {
if (value) return value ? "1" : "0";
{
return "true";
}
else
{
return "false";
}
} }
// Compara dos colores // Compara dos colores
bool colorAreEqual(color_t color1, color_t color2) bool colorAreEqual(Color color1, Color color2)
{ {
const bool r = color1.r == color2.r; const bool r = color1.r == color2.r;
const bool g = color1.g == color2.g; const bool g = color1.g == color2.g;

View File

@@ -3,9 +3,17 @@
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point #include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32 #include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include <vector> // Para vector
// Tipos de paleta
enum class Palette : int
{
ZXSPECTRUM,
ZXARNE
};
// Estructura para definir un circulo // Estructura para definir un circulo
struct circle_t struct Circle
{ {
int x; int x;
int y; int y;
@@ -36,25 +44,18 @@ struct line_t
int x1, y1, x2, y2; int x1, y1, x2, y2;
}; };
// Tipos de paleta
enum palette_e
{
p_zxspectrum,
p_zxarne
};
// Estructura para definir un color // Estructura para definir un color
struct color_t struct Color
{ {
Uint8 r; Uint8 r;
Uint8 g; Uint8 g;
Uint8 b; Uint8 b;
// Constructor por defecto // Constructor por defecto
color_t() : r(0), g(0), b(0) {} Color() : r(0), g(0), b(0) {}
// Constructor // Constructor
color_t(Uint8 red, Uint8 green, Uint8 blue) Color(Uint8 red, Uint8 green, Uint8 blue)
: r(red), g(green), b(blue) {} : r(red), g(green), b(blue) {}
}; };
@@ -62,10 +63,10 @@ struct color_t
double distanceSquared(int x1, int y1, int x2, int y2); double distanceSquared(int x1, int y1, int x2, int y2);
// Detector de colisiones entre dos circulos // Detector de colisiones entre dos circulos
bool checkCollision(circle_t &a, circle_t &b); bool checkCollision(Circle &a, Circle &b);
// Detector de colisiones entre un circulo y un rectangulo // Detector de colisiones entre un circulo y un rectangulo
bool checkCollision(circle_t &a, SDL_Rect &b); bool checkCollision(Circle &a, SDL_Rect &b);
// Detector de colisiones entre un dos rectangulos // Detector de colisiones entre un dos rectangulos
bool checkCollision(SDL_Rect &a, SDL_Rect &b); bool checkCollision(SDL_Rect &a, SDL_Rect &b);
@@ -95,16 +96,19 @@ bool checkCollision(SDL_Point &p, d_line_t &l);
void normalizeLine(d_line_t &l); void normalizeLine(d_line_t &l);
// Devuelve un color_t a partir de un string // Devuelve un color_t a partir de un string
color_t stringToColor(palette_e pal, std::string str); Color stringToColor(Palette pal, std::string str);
// Convierte una cadena en un valor booleano // Convierte una cadena a un entero de forma segura
bool stringToBool(std::string str); int safeStoi(const std::string &value, int defaultValue = 0);
// Convierte un valor booleano en una cadena // Convierte una cadena a un booleano
bool stringToBool(const std::string &str);
// Convierte un booleano a una cadena
std::string boolToString(bool value); std::string boolToString(bool value);
// Compara dos colores // Compara dos colores
bool colorAreEqual(color_t color1, color_t color2); bool colorAreEqual(Color color1, Color color2);
// Convierte una cadena a minusculas // Convierte una cadena a minusculas
std::string toLower(std::string str); std::string toLower(std::string str);