Options: creat namespace

This commit is contained in:
2025-06-14 17:43:53 +02:00
parent 23e8f90274
commit c748070ba5
18 changed files with 542 additions and 544 deletions

View File

@@ -107,7 +107,7 @@ Game::~Game()
else
{
// [Modo JUEGO] Guarda puntuaciones y transita a modo título
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
auto manager = std::make_unique<ManageHiScoreTable>(Options::game.hi_score_table);
manager->saveToFile(Asset::get()->get("score.bin"));
Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO;
Audio::get()->stopMusic();
@@ -326,7 +326,7 @@ void Game::updateGameStateGameOver()
if (fade_out_->isEnabled())
{
if (options.audio.enabled)
if (Options::audio.enabled)
{
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0f;
Audio::get()->setSoundVolume(static_cast<int>(VOL));
@@ -346,10 +346,10 @@ void Game::updateGameStateGameOver()
Section::name = Section::Name::HI_SCORE_TABLE;
}
Section::options = Section::Options::HI_SCORE_AFTER_PLAYING;
if (options.audio.enabled)
if (Options::audio.enabled)
{
Audio::get()->stopAllSounds();
Audio::get()->setSoundVolume(options.audio.sound.volume);
Audio::get()->setSoundVolume(Options::audio.sound.volume);
}
}
}
@@ -1267,10 +1267,10 @@ void Game::pause(bool value)
void Game::addScoreToScoreBoard(const std::shared_ptr<Player> &player)
{
const auto entry = HiScoreEntry(trim(player->getRecordName()), player->getScore(), player->get1CC());
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
options.game.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry);
auto manager = std::make_unique<ManageHiScoreTable>(Options::game.hi_score_table);
Options::game.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry);
manager->saveToFile(Asset::get()->get("score.bin"));
hi_score_.name = options.game.hi_score_table.front().name;
hi_score_.name = Options::game.hi_score_table.front().name;
}
// Saca del estado de GAME OVER al jugador si el otro está activo
@@ -1321,12 +1321,12 @@ std::shared_ptr<Player> Game::getPlayer(int id)
// Obtiene un controlador a partir del "id" del jugador
int Game::getController(int player_id)
{
auto it = std::find_if(options.controllers.begin(), options.controllers.end(), [player_id](const auto &controller)
auto it = std::find_if(Options::controllers.begin(), Options::controllers.end(), [player_id](const auto &controller)
{ return controller.player_id == player_id; });
if (it != options.controllers.end())
if (it != Options::controllers.end())
{
return std::distance(options.controllers.begin(), it);
return std::distance(Options::controllers.begin(), it);
}
return -1;
@@ -1443,7 +1443,7 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
Audio::get()->playSound("bullet.wav");
// Establece un tiempo de espera para el próximo disparo.
const int cooldown = player->isPowerUp() ? 5 : options.game.autofire ? 10
const int cooldown = player->isPowerUp() ? 5 : Options::game.autofire ? 10
: 7;
player->setFireCooldown(cooldown);
}
@@ -1475,8 +1475,8 @@ void Game::handlePlayersInput()
// Maneja las entradas de movimiento y disparo para un jugador en modo normal.
void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
{
const auto &controller = options.controllers.at(player->getController());
const bool autofire = player->isPowerUp() || options.game.autofire;
const auto &controller = Options::controllers.at(player->getController());
const bool autofire = player->isPowerUp() || Options::game.autofire;
if (input_->checkInput(InputAction::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index))
{
@@ -1506,21 +1506,21 @@ void Game::handleNormalPlayerInput(const std::shared_ptr<Player> &player)
// Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex)
{
if (input_->checkInput(InputAction::FIRE_CENTER, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
if (input_->checkInput(InputAction::FIRE_CENTER, autofire, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
handleFireInput(player, BulletType::UP);
#ifdef RECORDING
demo_.keys.fire = 1;
#endif
}
else if (input_->checkInput(InputAction::FIRE_LEFT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
else if (input_->checkInput(InputAction::FIRE_LEFT, autofire, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
handleFireInput(player, BulletType::LEFT);
#ifdef RECORDING
demo_.keys.fire_left = 1;
#endif
}
else if (input_->checkInput(InputAction::FIRE_RIGHT, autofire, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
else if (input_->checkInput(InputAction::FIRE_RIGHT, autofire, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
handleFireInput(player, BulletType::RIGHT);
#ifdef RECORDING
@@ -1533,16 +1533,16 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
{
const auto controllerIndex = player->getController();
if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
player->setPlayingState(PlayerState::PLAYING);
player->addCredit();
}
// Disminuye el contador de continuación si se presiona cualquier botón de disparo.
if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index) ||
input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
if (player->getContinueCounter() < 7)
{
@@ -1555,9 +1555,9 @@ void Game::handlePlayerContinue(const std::shared_ptr<Player> &player)
void Game::handleNameInput(const std::shared_ptr<Player> &player)
{
const auto controllerIndex = player->getController();
if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index) ||
input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
if (player->isShowingName())
{
@@ -1574,19 +1574,19 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player)
player->setInput(InputAction::RIGHT);
}
}
else if (input_->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
else if (input_->checkInput(InputAction::UP, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
player->setInput(InputAction::UP);
}
else if (input_->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
else if (input_->checkInput(InputAction::DOWN, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
player->setInput(InputAction::DOWN);
}
else if (input_->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
else if (input_->checkInput(InputAction::LEFT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
player->setInput(InputAction::LEFT);
}
else if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, options.controllers[controllerIndex].type, options.controllers[controllerIndex].index))
else if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[controllerIndex].type, Options::controllers[controllerIndex].index))
{
player->setInput(InputAction::START);
addScoreToScoreBoard(player);
@@ -1689,7 +1689,7 @@ void Game::initDifficultyVars()
// Variables relacionadas con la dificultad
switch (difficulty_)
{
case DifficultyCode::EASY:
case Options::DifficultyCode::EASY:
{
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
difficulty_score_multiplier_ = 0.5f;
@@ -1697,7 +1697,7 @@ void Game::initDifficultyVars()
break;
}
case DifficultyCode::NORMAL:
case Options::DifficultyCode::NORMAL:
{
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
difficulty_score_multiplier_ = 1.0f;
@@ -1705,7 +1705,7 @@ void Game::initDifficultyVars()
break;
}
case DifficultyCode::HARD:
case Options::DifficultyCode::HARD:
{
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[4]);
difficulty_score_multiplier_ = 1.5f;
@@ -1935,7 +1935,7 @@ void Game::evaluateAndSetMenace()
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
void Game::checkAndUpdateBalloonSpeed()
{
if (difficulty_ != DifficultyCode::NORMAL)
if (difficulty_ != Options::DifficultyCode::NORMAL)
return;
const float percent = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;