forked from jaildesigner-jailgames/jaildoctors_dilemma
Reestructurant la classe Options
This commit is contained in:
@@ -55,8 +55,8 @@ Game::Game()
|
||||
item_tracker_ = new ItemTracker();
|
||||
room_tracker_ = new RoomTracker();
|
||||
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 playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
||||
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||
const player_t player = {spawn_point_, playerPNG, playerANI, room_};
|
||||
player_ = new Player(player);
|
||||
text_ = new Text(resource_->getOffset("smb2.txt"), resource_->getTexture("smb2.png"), renderer_);
|
||||
@@ -93,7 +93,7 @@ Game::Game()
|
||||
board_.items = 0;
|
||||
board_.rooms = 1;
|
||||
board_.music = true;
|
||||
board_.jailEnabled = options.cheat.jailEnabled;
|
||||
board_.jail_is_open = options.cheats.jail_is_open == Cheat::CheatState::ENABLED;
|
||||
setScoreBoardColor();
|
||||
room_tracker_->addRoom(current_room_);
|
||||
paused_ = false;
|
||||
@@ -102,11 +102,10 @@ Game::Game()
|
||||
total_items_ = getTotalItems();
|
||||
initStats();
|
||||
stats_->addVisit(room_->getName());
|
||||
const bool cheats = options.cheat.infiniteLives || options.cheat.invincible || options.cheat.jailEnabled;
|
||||
cheevos_->enable(!cheats); // Deshabilita los logros si hay trucos activados
|
||||
cheevos_->enable(!options.cheats.enabled()); // Deshabilita los logros si hay trucos activados
|
||||
|
||||
options.section.name = SECTION_GAME;
|
||||
options.section.subsection = 0;
|
||||
options.section.section = Section::GAME;
|
||||
options.section.subsection = Subsection::NONE;
|
||||
}
|
||||
|
||||
Game::~Game()
|
||||
@@ -141,7 +140,7 @@ void Game::checkEvents()
|
||||
{
|
||||
case SDL_SCANCODE_G:
|
||||
debug_->switchEnabled();
|
||||
options.cheat.invincible = debug_->getEnabled();
|
||||
options.cheats.invincible = static_cast<Cheat::CheatState>(debug_->getEnabled());
|
||||
board_.music = !debug_->getEnabled();
|
||||
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||
break;
|
||||
@@ -215,7 +214,7 @@ void Game::run()
|
||||
JA_PauseMusic();
|
||||
}
|
||||
|
||||
while (options.section.name == SECTION_GAME)
|
||||
while (options.section.section == Section::GAME)
|
||||
{
|
||||
update();
|
||||
checkEvents();
|
||||
@@ -352,7 +351,7 @@ bool Game::changeRoom(std::string file)
|
||||
room_ = nullptr;
|
||||
|
||||
// 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
|
||||
fillRoomNameTexture();
|
||||
@@ -425,22 +424,22 @@ void Game::checkGameOver()
|
||||
{
|
||||
if (board_.lives < 0 && black_screen_counter_ > 17)
|
||||
{
|
||||
options.section.name = SECTION_GAME_OVER;
|
||||
options.section.section = Section::GAME_OVER;
|
||||
}
|
||||
}
|
||||
|
||||
// Mata al jugador
|
||||
void Game::killPlayer()
|
||||
{
|
||||
if (options.cheat.invincible)
|
||||
if (options.cheats.invincible == Cheat::CheatState::ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Resta una vida al jugador
|
||||
if (!options.cheat.infiniteLives)
|
||||
if (options.cheats.infinite_lives == Cheat::CheatState::DISABLED)
|
||||
{
|
||||
board_.lives--;
|
||||
--board_.lives;
|
||||
}
|
||||
|
||||
// Actualiza las estadisticas
|
||||
@@ -460,15 +459,15 @@ void Game::killPlayer()
|
||||
setBlackScreen();
|
||||
|
||||
// Crea la nueva habitación y el nuevo jugador
|
||||
room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, board_.jailEnabled);
|
||||
const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png";
|
||||
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
|
||||
room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, board_.jail_is_open);
|
||||
const std::string playerPNG = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.png" : "player.png";
|
||||
const std::string playerANI = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
|
||||
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
|
||||
room_->pause();
|
||||
this->player_->pause();
|
||||
player_->pause();
|
||||
}
|
||||
|
||||
// Recarga todas las texturas
|
||||
@@ -484,26 +483,6 @@ void Game::reLoadTextures()
|
||||
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
|
||||
void Game::setBlackScreen()
|
||||
{
|
||||
@@ -534,7 +513,7 @@ void Game::renderBlackScreen()
|
||||
if (black_screen_)
|
||||
{
|
||||
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()
|
||||
{
|
||||
// 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 isBrightBlack = colorAreEqual(colorBorder, stringToColor(options.palette, "bright_black"));
|
||||
const bool isBlack = colorAreEqual(colorBorder, stringToColor(options.video.palette, "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
|
||||
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
|
||||
bool Game::checkEndGame()
|
||||
{
|
||||
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 isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
|
||||
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.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)
|
||||
|
||||
if (haveTheItems)
|
||||
{
|
||||
board_.jailEnabled = true;
|
||||
board_.jail_is_open = true;
|
||||
}
|
||||
|
||||
if (haveTheItems && isOnTheRoom && isOnTheDoor)
|
||||
@@ -568,7 +547,7 @@ bool Game::checkEndGame()
|
||||
// Comprueba los logros de completar el juego
|
||||
checkEndGameCheevos();
|
||||
|
||||
options.section.name = SECTION_ENDING;
|
||||
options.section.section = Section::ENDING;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -671,7 +650,7 @@ void Game::fillRoomNameTexture()
|
||||
SDL_SetRenderTarget(renderer_, room_name_texture_);
|
||||
|
||||
// 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_RenderClear(renderer_);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user