jugant amb clang-tidy

This commit is contained in:
2025-07-19 22:38:01 +02:00
parent 1d3fd79a9e
commit a7ef29b750
28 changed files with 735 additions and 734 deletions

View File

@@ -253,8 +253,8 @@ void Game::updateStage() {
createMessage(paths, Resource::get()->getTexture("game_text_last_stage"));
} else {
auto text = Resource::get()->getText("04b_25_2x");
const std::string caption = std::to_string(10 - Stage::number) + Lang::getText("[GAME_TEXT] 2");
createMessage(paths, text->writeToTexture(caption, 1, -4));
const std::string CAPTION = std::to_string(10 - Stage::number) + Lang::getText("[GAME_TEXT] 2");
createMessage(paths, text->writeToTexture(CAPTION, 1, -4));
}
}
@@ -422,48 +422,48 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
switch (item->getType()) {
case ItemType::DISK: {
player->addScore(1000);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(0)->getWidth()) / 2;
createItemText(x, game_text_textures_.at(0));
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(0)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(0));
playSound("item_pickup.wav");
break;
}
case ItemType::GAVINA: {
player->addScore(2500);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(1)->getWidth()) / 2;
createItemText(x, game_text_textures_.at(1));
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(1)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(1));
playSound("item_pickup.wav");
break;
}
case ItemType::PACMAR: {
player->addScore(5000);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2;
createItemText(x, game_text_textures_.at(2));
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(2));
playSound("item_pickup.wav");
break;
}
case ItemType::DEBIAN: {
player->addScore(100000);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(6)->getWidth()) / 2;
createItemText(x, game_text_textures_.at(6));
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(6)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(6));
playSound("debian_pickup.wav");
break;
}
case ItemType::CLOCK: {
enableTimeStopItem();
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(5)->getWidth()) / 2;
createItemText(x, game_text_textures_.at(5));
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(5)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(5));
playSound("item_pickup.wav");
break;
}
case ItemType::COFFEE: {
if (player->getCoffees() == 2) {
player->addScore(5000);
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2;
createItemText(x, game_text_textures_.at(2));
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(2));
} else {
player->giveExtraHit();
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(4)->getWidth()) / 2;
createItemText(x, game_text_textures_.at(4));
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(4)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(4));
}
playSound("voice_coffee.wav");
break;
@@ -471,8 +471,8 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
case ItemType::COFFEE_MACHINE: {
player->setPowerUp();
coffee_machine_enabled_ = false;
const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(3)->getWidth()) / 2;
createItemText(x, game_text_textures_.at(3));
const auto X = item->getPosX() + (item->getWidth() - game_text_textures_.at(3)->getWidth()) / 2;
createItemText(X, game_text_textures_.at(3));
playSound("voice_power_up.wav");
break;
}
@@ -516,12 +516,12 @@ void Game::checkBulletCollision() {
auto player = getPlayer(bullet->getOwner());
// Suelta el item si se da el caso
const auto dropped_item = dropItem();
if (dropped_item != ItemType::NONE && !demo_.recording) {
if (dropped_item != ItemType::COFFEE_MACHINE) {
createItem(dropped_item, balloon->getPosX(), balloon->getPosY());
const auto DROPPED_ITEM = dropItem();
if (DROPPED_ITEM != ItemType::NONE && !demo_.recording) {
if (DROPPED_ITEM != ItemType::COFFEE_MACHINE) {
createItem(DROPPED_ITEM, balloon->getPosX(), balloon->getPosY());
} else {
createItem(dropped_item, player->getPosX(), param.game.game_area.rect.y - Item::COFFEE_MACHINE_HEIGHT);
createItem(DROPPED_ITEM, player->getPosX(), param.game.game_area.rect.y - Item::COFFEE_MACHINE_HEIGHT);
coffee_machine_enabled_ = true;
}
}
@@ -595,32 +595,32 @@ void Game::renderItems() {
// Devuelve un item al azar y luego segun sus probabilidades
ItemType Game::dropItem() {
const auto lucky_number = rand() % 100;
const auto item = rand() % 6;
const auto LUCKY_NUMBER = rand() % 100;
const auto ITEM = rand() % 6;
switch (item) {
switch (ITEM) {
case 0:
if (lucky_number < helper_.item_disk_odds) {
if (LUCKY_NUMBER < helper_.item_disk_odds) {
return ItemType::DISK;
}
break;
case 1:
if (lucky_number < helper_.item_gavina_odds) {
if (LUCKY_NUMBER < helper_.item_gavina_odds) {
return ItemType::GAVINA;
}
break;
case 2:
if (lucky_number < helper_.item_pacmar_odds) {
if (LUCKY_NUMBER < helper_.item_pacmar_odds) {
return ItemType::GAVINA;
}
break;
case 3:
if (lucky_number < helper_.item_clock_odds) {
if (LUCKY_NUMBER < helper_.item_clock_odds) {
return ItemType::CLOCK;
}
break;
case 4:
if (lucky_number < helper_.item_coffee_odds) {
if (LUCKY_NUMBER < helper_.item_coffee_odds) {
helper_.item_coffee_odds = ITEM_COFFEE_ODDS_;
return ItemType::COFFEE;
} else {
@@ -630,7 +630,7 @@ ItemType Game::dropItem() {
}
break;
case 5:
if (lucky_number < helper_.item_coffee_machine_odds) {
if (LUCKY_NUMBER < helper_.item_coffee_machine_odds) {
helper_.item_coffee_machine_odds = ITEM_COFFEE_MACHINE_ODDS_;
if (!coffee_machine_enabled_ && helper_.need_coffee_machine) {
return ItemType::COFFEE_MACHINE;
@@ -666,22 +666,22 @@ void Game::freeItems() {
void Game::createItemText(int x, std::shared_ptr<Texture> texture) {
path_sprites_.emplace_back(std::make_unique<PathSprite>(texture));
const auto w = texture->getWidth();
const auto h = texture->getHeight();
const auto W = texture->getWidth();
const auto H = texture->getHeight();
const int y0 = param.game.play_area.rect.h - h;
const int y1 = 160 - (h / 2);
const int y2 = -h;
const int Y0 = param.game.play_area.rect.h - H;
const int Y1 = 160 - (H / 2);
const int Y2 = -H;
// Ajusta para que no se dibuje fuera de pantalla
x = std::clamp(x, 2, static_cast<int>(param.game.play_area.rect.w) - w - 2);
x = std::clamp(x, 2, static_cast<int>(param.game.play_area.rect.w) - W - 2);
// Inicializa
path_sprites_.back()->setWidth(w);
path_sprites_.back()->setHeight(h);
path_sprites_.back()->setSpriteClip({0, 0, static_cast<float>(w), static_cast<float>(h)});
path_sprites_.back()->addPath(y0, y1, PathType::VERTICAL, x, 100, easeOutQuint, 0);
path_sprites_.back()->addPath(y1, y2, PathType::VERTICAL, x, 80, easeInQuint, 0);
path_sprites_.back()->setWidth(W);
path_sprites_.back()->setHeight(H);
path_sprites_.back()->setSpriteClip({0, 0, static_cast<float>(W), static_cast<float>(H)});
path_sprites_.back()->addPath(Y0, Y1, PathType::VERTICAL, x, 100, easeOutQuint, 0);
path_sprites_.back()->addPath(Y1, Y2, PathType::VERTICAL, x, 80, easeInQuint, 0);
path_sprites_.back()->enable();
}
@@ -866,19 +866,19 @@ void Game::updateBackground() {
// Calcula la velocidad en función de los globos explotados y el total de globos a explotar para acabar el juego
constexpr float CLOUDS_INITIAL_SPEED = 0.05f;
constexpr float CLOUDS_FINAL_SPEED = 2.00f - CLOUDS_INITIAL_SPEED;
const float cloudsSpeed = (-CLOUDS_INITIAL_SPEED) + (-CLOUDS_FINAL_SPEED * (static_cast<float>(Stage::total_power) / total_power_to_complete_game_));
background_->setCloudsSpeed(cloudsSpeed);
const float CLOUDS_SPEED = (-CLOUDS_INITIAL_SPEED) + (-CLOUDS_FINAL_SPEED * (static_cast<float>(Stage::total_power) / total_power_to_complete_game_));
background_->setCloudsSpeed(CLOUDS_SPEED);
// Calcula la transición de los diferentes fondos
constexpr float num = 1525.0f; // total_power_to_complete div 4
const float gradient_number = std::min(Stage::total_power / num, 3.0f);
const float percent = gradient_number - static_cast<int>(gradient_number);
background_->setGradientNumber(static_cast<int>(gradient_number));
background_->setTransition(percent);
constexpr float NUM = 1525.0f; // total_power_to_complete div 4
const float GRADIENT_NUMBER = std::min(Stage::total_power / NUM, 3.0f);
const float PERCENT = GRADIENT_NUMBER - static_cast<int>(GRADIENT_NUMBER);
background_->setGradientNumber(static_cast<int>(GRADIENT_NUMBER));
background_->setTransition(PERCENT);
// Calcula la posición del sol
constexpr float sun_final_power = num * 2;
background_->setSunProgression(Stage::total_power / sun_final_power);
constexpr float SUN_FINAL_POWER = NUM * 2;
background_->setSunProgression(Stage::total_power / SUN_FINAL_POWER);
background_->setMoonProgression(Stage::total_power / static_cast<float>(total_power_to_complete_game_));
// Actualiza el objeto
@@ -955,51 +955,51 @@ void Game::initPaths() {
// Recorrido para el texto de "Get Ready!" (0,1)
{
const auto &texture = Resource::get()->getTexture("game_text_get_ready");
const auto w = texture->getWidth();
const int x0 = -w;
const int x1 = param.game.play_area.center_x - w / 2;
const int x2 = param.game.play_area.rect.w;
const int y = param.game.play_area.center_y;
paths_.emplace_back(Path(createPath(x0, x1, PathType::HORIZONTAL, y, 80, easeOutQuint), 20));
paths_.emplace_back(Path(createPath(x1, x2, PathType::HORIZONTAL, y, 80, easeInQuint), 0));
const auto W = texture->getWidth();
const int X0 = -W;
const int X1 = param.game.play_area.center_x - W / 2;
const int X2 = param.game.play_area.rect.w;
const int Y = param.game.play_area.center_y;
paths_.emplace_back(Path(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 20));
paths_.emplace_back(Path(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0));
}
// Recorrido para el texto de "Last Stage!" o de "X stages left" o "Game Over" (2,3)
{
const auto &texture = Resource::get()->getTexture("game_text_last_stage");
const auto h = texture->getHeight();
const int y0 = param.game.play_area.rect.h - h;
const int y1 = param.game.play_area.center_y - h / 2;
const int y2 = -h;
const int x = param.game.play_area.center_x;
paths_.emplace_back(Path(createPath(y0, y1, PathType::VERTICAL, x, 80, easeOutQuint), 20));
paths_.emplace_back(Path(createPath(y1, y2, PathType::VERTICAL, x, 80, easeInQuint), 0));
const auto H = texture->getHeight();
const int Y0 = param.game.play_area.rect.h - H;
const int Y1 = param.game.play_area.center_y - H / 2;
const int Y2 = -H;
const int X = param.game.play_area.center_x;
paths_.emplace_back(Path(createPath(Y0, Y1, PathType::VERTICAL, X, 80, easeOutQuint), 20));
paths_.emplace_back(Path(createPath(Y1, Y2, PathType::VERTICAL, X, 80, easeInQuint), 0));
}
// Recorrido para el texto de "Congratulations!!" (3,4)
{
const auto &texture = Resource::get()->getTexture("game_text_congratulations");
const auto w = texture->getWidth();
const auto h = texture->getHeight();
const int x0 = -w;
const int x1 = param.game.play_area.center_x - w / 2;
const int x2 = param.game.play_area.rect.w;
const int y = param.game.play_area.center_y - h / 2 - 20;
paths_.emplace_back(Path(createPath(x0, x1, PathType::HORIZONTAL, y, 80, easeOutQuint), 400));
paths_.emplace_back(Path(createPath(x1, x2, PathType::HORIZONTAL, y, 80, easeInQuint), 0));
const auto W = texture->getWidth();
const auto H = texture->getHeight();
const int X0 = -W;
const int X1 = param.game.play_area.center_x - W / 2;
const int X2 = param.game.play_area.rect.w;
const int Y = param.game.play_area.center_y - H / 2 - 20;
paths_.emplace_back(Path(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 400));
paths_.emplace_back(Path(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0));
}
// Recorrido para el texto de "1.000.000 points!" (5,6)
{
const auto &texture = Resource::get()->getTexture("game_text_1000000_points");
const auto w = texture->getWidth();
const auto h = texture->getHeight();
const int x0 = param.game.play_area.rect.w;
const int x1 = param.game.play_area.center_x - w / 2;
const int x2 = -w;
const int y = param.game.play_area.center_y + h / 2 - 20;
paths_.emplace_back(Path(createPath(x0, x1, PathType::HORIZONTAL, y, 80, easeOutQuint), 400));
paths_.emplace_back(Path(createPath(x1, x2, PathType::HORIZONTAL, y, 80, easeInQuint), 0));
const auto W = texture->getWidth();
const auto H = texture->getHeight();
const int X0 = param.game.play_area.rect.w;
const int X1 = param.game.play_area.center_x - W / 2;
const int X2 = -W;
const int Y = param.game.play_area.center_y + H / 2 - 20;
paths_.emplace_back(Path(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 400));
paths_.emplace_back(Path(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0));
}
}
@@ -1097,17 +1097,17 @@ void Game::pause(bool value) {
// Añade una puntuación a la tabla de records
void Game::addScoreToScoreBoard(const std::shared_ptr<Player> &player) {
const auto entry = HiScoreEntry(trim(player->getLastEnterName()), player->getScore(), player->get1CC());
const auto ENTRY = HiScoreEntry(trim(player->getLastEnterName()), player->getScore(), player->get1CC());
auto manager = std::make_unique<ManageHiScoreTable>(Options::settings.hi_score_table);
Options::settings.last_hi_score_entry.at(player->getId() - 1) = manager->add(entry);
Options::settings.last_hi_score_entry.at(player->getId() - 1) = manager->add(ENTRY);
manager->saveToFile(Asset::get()->get("score.bin"));
hi_score_.name = Options::settings.hi_score_table.front().name;
}
// Saca del estado de GAME OVER al jugador si el otro está activo
void Game::checkAndUpdatePlayerStatus(int activePlayerIndex, int inactivePlayerIndex) {
if (players_[activePlayerIndex]->isGameOver() && !players_[inactivePlayerIndex]->isGameOver() && !players_[inactivePlayerIndex]->isWaiting()) {
players_[activePlayerIndex]->setPlayingState(PlayerState::WAITING);
void Game::checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index) {
if (players_[active_player_index]->isGameOver() && !players_[inactive_player_index]->isGameOver() && !players_[inactive_player_index]->isWaiting()) {
players_[active_player_index]->setPlayingState(PlayerState::WAITING);
}
}
@@ -1210,21 +1210,21 @@ void Game::DEMO_handleInput() {
// Procesa las entradas para un jugador específico durante el modo demo.
void Game::DEMO_handlePlayerInput(const std::shared_ptr<Player> &player, int index) {
const auto &demoData = demo_.data[index][demo_.counter];
const auto &demo_data = demo_.data[index][demo_.counter];
if (demoData.left == 1) {
if (demo_data.left == 1) {
player->setInput(InputAction::LEFT);
} else if (demoData.right == 1) {
} else if (demo_data.right == 1) {
player->setInput(InputAction::RIGHT);
} else if (demoData.no_input == 1) {
} else if (demo_data.no_input == 1) {
player->setInput(InputAction::NONE);
}
if (demoData.fire == 1) {
if (demo_data.fire == 1) {
handleFireInput(player, BulletType::UP);
} else if (demoData.fire_left == 1) {
} else if (demo_data.fire_left == 1) {
handleFireInput(player, BulletType::LEFT);
} else if (demoData.fire_right == 1) {
} else if (demo_data.fire_right == 1) {
handleFireInput(player, BulletType::RIGHT);
}
}
@@ -1275,31 +1275,31 @@ void Game::handleFireInput(const std::shared_ptr<Player> &player, BulletType bul
// Gestiona las entradas de todos los jugadores en el modo normal (fuera del modo demo).
void Game::handlePlayersInput() {
for (const auto &PLAYER : players_) {
if (PLAYER->isPlaying()) {
for (const auto &player : players_) {
if (player->isPlaying()) {
// Maneja el input de los jugadores en modo normal.
handleNormalPlayerInput(PLAYER);
} else if (PLAYER->isContinue() || PLAYER->isWaiting()) {
handleNormalPlayerInput(player);
} else if (player->isContinue() || player->isWaiting()) {
// Gestiona la continuación del jugador.
handlePlayerContinue(PLAYER);
} else if (PLAYER->isEnteringName() || PLAYER->isEnteringNameGameCompleted() || PLAYER->isShowingName()) {
handlePlayerContinue(player);
} else if (player->isEnteringName() || player->isEnteringNameGameCompleted() || player->isShowingName()) {
// Gestiona la introducción del nombre del jugador.
handleNameInput(PLAYER);
handleNameInput(player);
}
}
}
// 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 auto &controller = Options::controllers.at(player->getController());
const bool AUTOFIRE = player->isPowerUp() || Options::settings.autofire;
if (input_->checkInput(InputAction::LEFT, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (input_->checkInput(InputAction::LEFT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) {
player->setInput(InputAction::LEFT);
#ifdef RECORDING
demo_.keys.left = 1;
#endif
} else if (input_->checkInput(InputAction::RIGHT, INPUT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
} else if (input_->checkInput(InputAction::RIGHT, INPUT_ALLOW_REPEAT, controller.type, controller.index)) {
player->setInput(InputAction::RIGHT);
#ifdef RECORDING
demo_.keys.right = 1;
@@ -1315,18 +1315,18 @@ 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)) {
void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controller_index) {
if (input_->checkInput(InputAction::FIRE_CENTER, autofire, Options::controllers[controller_index].type, Options::controllers[controller_index].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[controller_index].type, Options::controllers[controller_index].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[controller_index].type, Options::controllers[controller_index].index)) {
handleFireInput(player, BulletType::RIGHT);
#ifdef RECORDING
demo_.keys.fire_right = 1;
@@ -1336,15 +1336,15 @@ void Game::handleFireInputs(const std::shared_ptr<Player> &player, bool autofire
// Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
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)) {
const auto CONTROLLER_INDEX = player->getController();
if (input_->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index)) {
player->setPlayingState(PlayerState::RESPAWNING);
}
// 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[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index) ||
input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index)) {
if (player->getContinueCounter() < param.scoreboard.skip_countdown_value) {
player->decContinueCounter();
}
@@ -1353,8 +1353,8 @@ void Game::handlePlayerContinue(const std::shared_ptr<Player> &player) {
// Procesa las entradas para la introducción del nombre del jugador.
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)) {
const auto CONTROLLER_INDEX = player->getController();
if (input_->checkInput(InputAction::FIRE_LEFT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index)) {
if (player->isShowingName()) {
player->setPlayingState(PlayerState::CONTINUE);
} else if (player->getEnterNamePositionOverflow()) {
@@ -1364,18 +1364,18 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player) {
} else {
player->setInput(InputAction::RIGHT);
}
} else if (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)) {
} else if (input_->checkInput(InputAction::FIRE_CENTER, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index) ||
input_->checkInput(InputAction::FIRE_RIGHT, INPUT_DO_NOT_ALLOW_REPEAT, Options::controllers[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index)) {
if (player->isShowingName()) {
player->setPlayingState(PlayerState::CONTINUE);
} else {
player->setInput(InputAction::LEFT);
}
} 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[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].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[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index)) {
player->setInput(InputAction::DOWN);
} 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[CONTROLLER_INDEX].type, Options::controllers[CONTROLLER_INDEX].index)) {
if (player->isShowingName()) {
player->setPlayingState(PlayerState::CONTINUE);
} else {
@@ -1666,12 +1666,12 @@ void Game::cleanVectors() {
// Gestiona el nivel de amenaza
void Game::updateMenace() {
if (state_ == GameState::PLAYING) {
const auto stage = Stage::get(Stage::number);
const float percent = Stage::power / stage.power_to_complete;
const int difference = stage.max_menace - stage.min_menace;
const auto STAGE = Stage::get(Stage::number);
const float PERCENT = Stage::power / STAGE.power_to_complete;
const int DIFFERENCE = STAGE.max_menace - STAGE.min_menace;
// Aumenta el nivel de amenaza en función de la puntuación
menace_threshold_ = stage.min_menace + (difference * percent);
menace_threshold_ = STAGE.min_menace + (DIFFERENCE * PERCENT);
// Si el nivel de amenza es inferior al umbral
if (menace_current_ < menace_threshold_) {
@@ -1694,11 +1694,11 @@ void Game::checkAndUpdateBalloonSpeed() {
if (difficulty_ != Options::DifficultyCode::NORMAL)
return;
const float percent = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
const float thresholds[] = {0.2f, 0.4f, 0.6f, 0.8f};
const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
const float THRESHOLDS[] = {0.2f, 0.4f, 0.6f, 0.8f};
for (size_t i = 0; i < std::size(thresholds); ++i) {
if (balloon_manager_->getBalloonSpeed() == BALLOON_SPEED[i] && percent > thresholds[i]) {
for (size_t i = 0; i < std::size(THRESHOLDS); ++i) {
if (balloon_manager_->getBalloonSpeed() == BALLOON_SPEED[i] && PERCENT > THRESHOLDS[i]) {
balloon_manager_->setBalloonSpeed(BALLOON_SPEED[i + 1]);
break; // Salir del bucle una vez actualizada la velocidad y aplicada
}
@@ -1715,8 +1715,8 @@ void Game::playSound(const std::string &name) {
if (demo_.enabled)
return;
static auto audio = Audio::get();
audio->playSound(name);
static auto audio_ = Audio::get();
audio_->playSound(name);
}
// Organiza los jugadores para que los vivos se pinten sobre los muertos
@@ -1727,9 +1727,9 @@ void Game::movePlayersToFront() {
for (auto &player : players_to_reorder) {
auto it = std::find(players_.begin(), players_.end(), player);
if (it != players_.end() && it != players_.begin()) {
std::shared_ptr<Player> dyingPlayer = *it;
std::shared_ptr<Player> dying_player = *it;
players_.erase(it);
players_.insert(players_.begin(), dyingPlayer);
players_.insert(players_.begin(), dying_player);
}
}
players_to_reorder.clear();
@@ -1740,21 +1740,21 @@ void Game::checkServiceMenu() {
if (demo_.enabled)
return;
static bool was_paused_before_service_menu = false;
static bool service_menu_was_active = false;
static bool was_paused_before_service_menu_ = false;
static bool service_menu_was_active_ = false;
bool service_menu_is_active = ServiceMenu::get()->isEnabled();
if (service_menu_is_active && !service_menu_was_active) {
if (service_menu_is_active && !service_menu_was_active_) {
// El menú acaba de abrirse
was_paused_before_service_menu = paused_;
was_paused_before_service_menu_ = paused_;
pause(true);
} else if (!service_menu_is_active && service_menu_was_active) {
} else if (!service_menu_is_active && service_menu_was_active_) {
// El menú acaba de cerrarse
pause(was_paused_before_service_menu);
pause(was_paused_before_service_menu_);
}
service_menu_was_active = service_menu_is_active;
service_menu_was_active_ = service_menu_is_active;
}
#ifdef DEBUG
@@ -1770,9 +1770,9 @@ void Game::checkDebugEvents(const SDL_Event &event) {
}
case SDLK_2: // Activa o desactiva la aparición de globos
{
static bool deploy_balloons = true;
deploy_balloons = !deploy_balloons;
balloon_manager_->enableBalloonDeployment(deploy_balloons);
static bool deploy_balloons_ = true;
deploy_balloons_ = !deploy_balloons_;
balloon_manager_->enableBalloonDeployment(deploy_balloons_);
break;
}
case SDLK_3: // Activa el modo para pasar el juego automaticamente