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

@@ -257,8 +257,8 @@ void Credits::fillCanvas() {
// Dibuja el rectangulo rojo
// SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0xFF, 0, 0, 0xFF);
const Color color = color_.LIGHTEN();
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), color.r, color.g, color.b, 0xFF);
const Color COLOR = color_.LIGHTEN();
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), COLOR.r, COLOR.g, COLOR.b, 0xFF);
SDL_RenderRect(Screen::get()->getRenderer(), &red_rect);
// Si el mini_logo está en su destino, lo dibuja encima de lo anterior
@@ -305,19 +305,19 @@ void Credits::updateTextureDstRects() {
// Tira globos al escenario
void Credits::throwBalloons() {
constexpr int speed = 200;
const std::vector<int> sets = {0, 63, 25, 67, 17, 75, 13, 50};
constexpr int SPEED = 200;
const std::vector<int> SETS = {0, 63, 25, 67, 17, 75, 13, 50};
if (counter_ > ((sets.size() - 1) * speed) * 3) {
if (counter_ > ((SETS.size() - 1) * SPEED) * 3) {
return;
}
if (counter_ % speed == 0) {
const int index = (counter_ / speed) % sets.size();
balloon_manager_->deploySet(sets.at(index), -60);
if (counter_ % SPEED == 0) {
const int INDEX = (counter_ / SPEED) % SETS.size();
balloon_manager_->deploySet(SETS.at(INDEX), -60);
}
if (counter_ % (speed * 4) == 0 && counter_ > 0) {
if (counter_ % (SPEED * 4) == 0 && counter_ > 0) {
balloon_manager_->createPowerBall();
}
}
@@ -365,7 +365,7 @@ void Credits::initPlayers() {
// Actualiza los rectangulos negros
void Credits::updateBlackRects() {
static int current_step = steps_;
static int current_step_ = steps_;
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1) {
// Si los rectangulos superior e inferior no han llegado al centro
if (counter_ % 4 == 0) {
@@ -376,8 +376,8 @@ void Credits::updateBlackRects() {
++bottom_black_rect_.h;
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1);
--current_step;
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
--current_step_;
setVolume(static_cast<int>(initial_volume_ * current_step_ / steps_));
}
} else {
// Si los rectangulos superior e inferior han llegado al centro
@@ -391,8 +391,8 @@ void Credits::updateBlackRects() {
right_black_rect_.w += SPEED;
right_black_rect_.x = std::max(right_black_rect_.x - SPEED, param.game.game_area.center_x);
--current_step;
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
--current_step_;
setVolume(static_cast<int>(initial_volume_ * current_step_ / steps_));
} else {
// Si los rectangulos izquierdo y derecho han llegado al centro
setVolume(0);
@@ -452,33 +452,33 @@ void Credits::cycleColors() {
constexpr int UPPER_LIMIT = 140; // Límite superior
constexpr int LOWER_LIMIT = 30; // Límite inferior
static float r = static_cast<float>(UPPER_LIMIT);
static float g = static_cast<float>(LOWER_LIMIT);
static float b = static_cast<float>(LOWER_LIMIT);
static float stepR = -0.5f; // Paso flotante para transiciones suaves
static float stepG = 0.3f;
static float stepB = 0.1f;
static float r_ = static_cast<float>(UPPER_LIMIT);
static float g_ = static_cast<float>(LOWER_LIMIT);
static float b_ = static_cast<float>(LOWER_LIMIT);
static float step_r_ = -0.5f; // Paso flotante para transiciones suaves
static float step_g_ = 0.3f;
static float step_b_ = 0.1f;
// Ajustar valores de R
r += stepR;
if (r >= UPPER_LIMIT || r <= LOWER_LIMIT) {
stepR = -stepR; // Cambia de dirección al alcanzar los límites
r_ += step_r_;
if (r_ >= UPPER_LIMIT || r_ <= LOWER_LIMIT) {
step_r_ = -step_r_; // Cambia de dirección al alcanzar los límites
}
// Ajustar valores de G
g += stepG;
if (g >= UPPER_LIMIT || g <= LOWER_LIMIT) {
stepG = -stepG; // Cambia de dirección al alcanzar los límites
g_ += step_g_;
if (g_ >= UPPER_LIMIT || g_ <= LOWER_LIMIT) {
step_g_ = -step_g_; // Cambia de dirección al alcanzar los límites
}
// Ajustar valores de B
b += stepB;
if (b >= UPPER_LIMIT || b <= LOWER_LIMIT) {
stepB = -stepB; // Cambia de dirección al alcanzar los límites
b_ += step_b_;
if (b_ >= UPPER_LIMIT || b_ <= LOWER_LIMIT) {
step_b_ = -step_b_; // Cambia de dirección al alcanzar los límites
}
// Aplicar el color, redondeando a enteros antes de usar
color_ = Color(static_cast<int>(r), static_cast<int>(g), static_cast<int>(b));
color_ = Color(static_cast<int>(r_), static_cast<int>(g_), static_cast<int>(b_));
tiled_bg_->setColor(color_);
}

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

View File

@@ -169,19 +169,19 @@ void HiScoreTable::updateFade() {
// Convierte un entero a un string con separadores de miles
std::string HiScoreTable::format(int number) {
const std::string separator = ".";
const std::string score = std::to_string(number);
const std::string SEPARATOR = ".";
const std::string SCORE = std::to_string(number);
auto index = (int)score.size() - 1;
auto index = (int)SCORE.size() - 1;
std::string result;
auto i = 0;
while (index >= 0) {
result = score.at(index) + result;
result = SCORE.at(index) + result;
index--;
i++;
if (i == 3) {
i = 0;
result = separator + result;
result = SEPARATOR + result;
}
}
@@ -200,44 +200,44 @@ void HiScoreTable::createSprites() {
constexpr int ENTRY_LENGHT = 22;
constexpr int MAX_NAMES = 10;
const int space_between_header = entry_text->getCharacterSize() * 4;
const int space_between_lines = entry_text->getCharacterSize() * 2;
const int size = space_between_header + space_between_lines * (MAX_NAMES - 1) + entry_text->getCharacterSize();
const int first_line = (param.game.height - size) / 2;
const int SPACE_BETWEEN_HEADER = entry_text->getCharacterSize() * 4;
const int SPACE_BETWEEN_LINES = entry_text->getCharacterSize() * 2;
const int SIZE = SPACE_BETWEEN_HEADER + SPACE_BETWEEN_LINES * (MAX_NAMES - 1) + entry_text->getCharacterSize();
const int FIRST_LINE = (param.game.height - SIZE) / 2;
// Crea el sprite para el texto de cabecera
header_ = std::make_unique<Sprite>(header_text->writeDXToTexture(TEXT_COLOR, Lang::getText("[HIGHSCORE_TABLE] CAPTION"), -2, background_fade_color_.INVERSE().LIGHTEN(25)));
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line);
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), FIRST_LINE);
// Crea los sprites para las entradas en la tabla de puntuaciones
const int animation = rand() % 4;
const std::string sample_line(ENTRY_LENGHT + 3, ' ');
auto sample_entry = std::make_unique<Sprite>(entry_text->writeDXToTexture(TEXT_SHADOW, sample_line, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR));
const auto entry_width = sample_entry->getWidth();
const int ANIMATION = rand() % 4;
const std::string SAMPLE_LINE(ENTRY_LENGHT + 3, ' ');
auto sample_entry = std::make_unique<Sprite>(entry_text->writeDXToTexture(TEXT_SHADOW, SAMPLE_LINE, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR));
const auto ENTRY_WIDTH = sample_entry->getWidth();
for (int i = 0; i < MAX_NAMES; ++i) {
const auto table_position = format(i + 1) + ". ";
const auto score = format(Options::settings.hi_score_table.at(i).score);
const auto num_dots = ENTRY_LENGHT - Options::settings.hi_score_table.at(i).name.size() - score.size();
const auto one_cc = Options::settings.hi_score_table.at(i).one_credit_complete ? " }" : "";
const auto TABLE_POSITION = format(i + 1) + ". ";
const auto SCORE = format(Options::settings.hi_score_table.at(i).score);
const auto NUM_DOTS = ENTRY_LENGHT - Options::settings.hi_score_table.at(i).name.size() - SCORE.size();
const auto ONE_CC = Options::settings.hi_score_table.at(i).one_credit_complete ? " }" : "";
std::string dots;
for (int j = 0; j < (int)num_dots; ++j) {
for (int j = 0; j < (int)NUM_DOTS; ++j) {
dots = dots + ".";
}
const auto line = table_position + Options::settings.hi_score_table.at(i).name + dots + score + one_cc;
const auto LINE = TABLE_POSITION + Options::settings.hi_score_table.at(i).name + dots + SCORE + ONE_CC;
entry_names_.emplace_back(std::make_shared<PathSprite>(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR)));
const int default_pos_x = (backbuffer_width - entry_width) / 2;
const int pos_x = (i < 9) ? default_pos_x : default_pos_x - entry_text->getCharacterSize();
const int pos_y = (i * space_between_lines) + first_line + space_between_header;
constexpr int steps = 80;
switch (animation) {
entry_names_.emplace_back(std::make_shared<PathSprite>(entry_text->writeDXToTexture(TEXT_SHADOW, LINE, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR)));
const int DEFAULT_POS_X = (backbuffer_width - ENTRY_WIDTH) / 2;
const int POS_X = (i < 9) ? DEFAULT_POS_X : DEFAULT_POS_X - entry_text->getCharacterSize();
const int POS_Y = (i * SPACE_BETWEEN_LINES) + FIRST_LINE + SPACE_BETWEEN_HEADER;
constexpr int STEPS = 80;
switch (ANIMATION) {
case 0: // Ambos lados alternativamente
{
if (i % 2 == 0) {
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
} else {
entry_names_.back()->addPath(backbuffer_width, pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
entry_names_.back()->setPosition(backbuffer_width, 0);
}
break;
@@ -245,21 +245,21 @@ void HiScoreTable::createSprites() {
case 1: // Entran por la izquierda
{
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
break;
}
case 2: // Entran por la derecha
{
entry_names_.back()->addPath(backbuffer_width, pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->addPath(backbuffer_width, POS_X, PathType::HORIZONTAL, POS_Y, STEPS, easeOutQuint);
entry_names_.back()->setPosition(backbuffer_width, 0);
break;
}
case 3: // Entran desde la parte inferior
{
entry_names_.back()->addPath(backbuffer_height, pos_y, PathType::VERTICAL, pos_x, steps, easeOutQuint);
entry_names_.back()->addPath(backbuffer_height, POS_Y, PathType::VERTICAL, POS_X, STEPS, easeOutQuint);
entry_names_.back()->setPosition(0, backbuffer_height);
}
@@ -271,12 +271,12 @@ void HiScoreTable::createSprites() {
// Actualiza las posiciones de los sprites de texto
void HiScoreTable::updateSprites() {
constexpr int init_counter = 190;
const int counter_between_entries = 16;
if (counter_ >= init_counter) {
const int counter2 = counter_ - init_counter;
if (counter2 % counter_between_entries == 0) {
int index = counter2 / counter_between_entries;
constexpr int INIT_COUNTER = 190;
const int COUNTER_BETWEEN_ENTRIES = 16;
if (counter_ >= INIT_COUNTER) {
const int COUNTER2 = counter_ - INIT_COUNTER;
if (COUNTER2 % COUNTER_BETWEEN_ENTRIES == 0) {
int index = COUNTER2 / COUNTER_BETWEEN_ENTRIES;
if (index < static_cast<int>(entry_names_.size())) {
entry_names_.at(index)->enable();
}
@@ -303,8 +303,8 @@ void HiScoreTable::initBackground() {
background_->setPos(param.game.game_area.rect);
background_->setCloudsSpeed(-0.1f);
const int lucky = rand() % 3;
switch (lucky) {
const int LUCKY = rand() % 3;
switch (LUCKY) {
case 0: // Fondo verde
{
background_->setGradientNumber(2);
@@ -341,9 +341,9 @@ void HiScoreTable::initBackground() {
}
// Obtiene un color del vector de colores de entradas
Color HiScoreTable::getEntryColor(int counter_) {
Color HiScoreTable::getEntryColor(int counter) {
int cycle_length = entry_colors_.size() * 2 - 2;
size_t n = counter_ % cycle_length;
size_t n = counter % cycle_length;
size_t index;
if (n < entry_colors_.size()) {
@@ -366,10 +366,10 @@ void HiScoreTable::iniEntryColors() {
// Hace brillar los nombres de la tabla de records
void HiScoreTable::glowEntryNames() {
const Color entry_color = getEntryColor(counter_ / 5);
const Color ENTRY_COLOR = getEntryColor(counter_ / 5);
for (const auto &entry_index : Options::settings.last_hi_score_entry) {
if (entry_index != -1) {
entry_names_.at(entry_index)->getTexture()->setColor(entry_color);
entry_names_.at(entry_index)->getTexture()->setColor(ENTRY_COLOR);
}
}
}

View File

@@ -110,7 +110,7 @@ void Instructions::updateSprites() {
// Rellena la textura de texto
void Instructions::fillTexture() {
const int desp_x = param.game.item_size + 8;
const int DESP_X = param.game.item_size + 8;
// Modifica el renderizador para pintar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
@@ -121,19 +121,19 @@ void Instructions::fillTexture() {
SDL_RenderClear(renderer_);
// Constantes
constexpr int num_lines = 4;
constexpr int num_item_lines = 4;
constexpr int num_post_headers = 2;
constexpr int num_pre_headers = 1;
constexpr int NUM_LINES = 4;
constexpr int NUM_ITEM_LINES = 4;
constexpr int NUM_POST_HEADERS = 2;
constexpr int NUM_PRE_HEADERS = 1;
constexpr int space_post_header = 20;
constexpr int space_pre_header = 28;
const int space_between_lines = text_->getCharacterSize() * 1.5f;
const int space_between_item_lines = param.game.item_size + item_space_;
const int space_new_paragraph = space_between_lines * 0.5f;
constexpr int SPACE_POST_HEADER = 20;
constexpr int SPACE_PRE_HEADER = 28;
const int SPACE_BETWEEN_LINES = text_->getCharacterSize() * 1.5f;
const int SPACE_BETWEEN_ITEM_LINES = param.game.item_size + item_space_;
const int SPACE_NEW_PARAGRAPH = SPACE_BETWEEN_LINES * 0.5f;
const int size = (num_lines * space_between_lines) + (num_item_lines * space_between_item_lines) + (num_post_headers * space_post_header) + (num_pre_headers * space_pre_header) + (space_new_paragraph);
const int first_line = (param.game.height - size) / 2;
const int SIZE = (NUM_LINES * SPACE_BETWEEN_LINES) + (NUM_ITEM_LINES * SPACE_BETWEEN_ITEM_LINES) + (NUM_POST_HEADERS * SPACE_POST_HEADER) + (NUM_PRE_HEADERS * SPACE_PRE_HEADER) + (SPACE_NEW_PARAGRAPH);
const int FIRST_LINE = (param.game.height - SIZE) / 2;
// Calcula cual es el texto más largo de las descripciones de los items
int lenght = 0;
@@ -144,39 +144,39 @@ void Instructions::fillTexture() {
Lang::getText("[INSTRUCTIONS] 10"),
Lang::getText("[INSTRUCTIONS] 11")};
for (const auto &desc : ITEM_DESCRIPTIONS) {
const int l = text_->lenght(desc);
lenght = l > lenght ? l : lenght;
const int L = text_->lenght(desc);
lenght = L > lenght ? L : lenght;
}
const int ANCHOR_ITEM = (param.game.width - (lenght + desp_x)) / 2;
const int ANCHOR_ITEM = (param.game.width - (lenght + DESP_X)) / 2;
constexpr Color ORANGE_COLOR = Color(0XFF, 0X7A, 0X00);
// Escribe el texto de las instrucciones
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, first_line, Lang::getText("[INSTRUCTIONS] 01"), 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, FIRST_LINE, Lang::getText("[INSTRUCTIONS] 01"), 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR);
const int anchor1 = first_line + space_post_header;
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_between_lines * 0, Lang::getText("[INSTRUCTIONS] 02"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_between_lines * 1, Lang::getText("[INSTRUCTIONS] 03"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_new_paragraph + space_between_lines * 2, Lang::getText("[INSTRUCTIONS] 04"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_new_paragraph + space_between_lines * 3, Lang::getText("[INSTRUCTIONS] 05"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
const int ANCHOR1 = FIRST_LINE + SPACE_POST_HEADER;
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR1 + SPACE_BETWEEN_LINES * 0, Lang::getText("[INSTRUCTIONS] 02"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR1 + SPACE_BETWEEN_LINES * 1, Lang::getText("[INSTRUCTIONS] 03"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR1 + SPACE_NEW_PARAGRAPH + SPACE_BETWEEN_LINES * 2, Lang::getText("[INSTRUCTIONS] 04"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR1 + SPACE_NEW_PARAGRAPH + SPACE_BETWEEN_LINES * 3, Lang::getText("[INSTRUCTIONS] 05"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
// Escribe el texto de los objetos y sus puntos
const int anchor2 = anchor1 + space_pre_header + space_new_paragraph + space_between_lines * 3;
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor2, Lang::getText("[INSTRUCTIONS] 06"), 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR);
const int ANCHOR2 = ANCHOR1 + SPACE_PRE_HEADER + SPACE_NEW_PARAGRAPH + SPACE_BETWEEN_LINES * 3;
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, ANCHOR2, Lang::getText("[INSTRUCTIONS] 06"), 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR);
const int anchor3 = anchor2 + space_post_header;
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 0, Lang::getText("[INSTRUCTIONS] 07"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 1, Lang::getText("[INSTRUCTIONS] 08"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 2, Lang::getText("[INSTRUCTIONS] 09"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 3, Lang::getText("[INSTRUCTIONS] 10"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 4, Lang::getText("[INSTRUCTIONS] 11"), SHADOW_TEXT_COLOR);
const int ANCHOR3 = ANCHOR2 + SPACE_POST_HEADER;
text_->writeShadowed(ANCHOR_ITEM + DESP_X, ANCHOR3 + SPACE_BETWEEN_ITEM_LINES * 0, Lang::getText("[INSTRUCTIONS] 07"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + DESP_X, ANCHOR3 + SPACE_BETWEEN_ITEM_LINES * 1, Lang::getText("[INSTRUCTIONS] 08"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + DESP_X, ANCHOR3 + SPACE_BETWEEN_ITEM_LINES * 2, Lang::getText("[INSTRUCTIONS] 09"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + DESP_X, ANCHOR3 + SPACE_BETWEEN_ITEM_LINES * 3, Lang::getText("[INSTRUCTIONS] 10"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + DESP_X, ANCHOR3 + SPACE_BETWEEN_ITEM_LINES * 4, Lang::getText("[INSTRUCTIONS] 11"), SHADOW_TEXT_COLOR);
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
// Da valor a la variable
sprite_pos_.x = ANCHOR_ITEM;
sprite_pos_.y = anchor3 - ((param.game.item_size - text_->getCharacterSize()) / 2);
sprite_pos_.y = ANCHOR3 - ((param.game.item_size - text_->getCharacterSize()) / 2);
}
// Rellena el backbuffer
@@ -289,14 +289,14 @@ std::vector<Line> Instructions::initializeLines(int height) {
}
// Método para mover las líneas con suavizado
bool Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 startDelay) {
bool Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 start_delay) {
Uint32 current_time = SDL_GetTicks();
bool all_lines_off_screen = true;
for (auto &line : lines) {
// Establecer startTime en el primer cuadro de animación
if (line.startTime == 0) {
line.startTime = current_time + line.y * startDelay;
line.startTime = current_time + line.y * start_delay;
}
float elapsed_time = (current_time - line.startTime) / 1000.0f; // Convertir a segundos
@@ -319,10 +319,10 @@ bool Instructions::moveLines(std::vector<Line> &lines, int width, float duration
// Método para renderizar las líneas
void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines) {
for (const auto &LINE : lines) {
SDL_FRect srcRect = {0, static_cast<float>(LINE.y), 320, 1};
SDL_FRect dstRect = {static_cast<float>(LINE.x), static_cast<float>(LINE.y), 320, 1};
SDL_RenderTexture(renderer, texture, &srcRect, &dstRect);
for (const auto &line : lines) {
SDL_FRect src_rect = {0, static_cast<float>(line.y), 320, 1};
SDL_FRect dst_rect = {static_cast<float>(line.x), static_cast<float>(line.y), 320, 1};
SDL_RenderTexture(renderer, texture, &src_rect, &dst_rect);
}
}

View File

@@ -52,64 +52,64 @@ void Intro::checkEvents() {
while (SDL_PollEvent(&event)) {
#ifdef DEBUG
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 1) {
static Color color = param.intro.bg_color;
static Color color_ = param.intro.bg_color;
switch (event.key.key) {
case SDLK_A:
if (color.r < 255)
++color.r;
if (color_.r < 255)
++color_.r;
break;
case SDLK_Z:
if (color.r > 0)
--color.r;
if (color_.r > 0)
--color_.r;
break;
case SDLK_S:
if (color.g < 255)
++color.g;
if (color_.g < 255)
++color_.g;
break;
case SDLK_X:
if (color.g > 0)
--color.g;
if (color_.g > 0)
--color_.g;
break;
case SDLK_D:
if (color.b < 255)
++color.b;
if (color_.b < 255)
++color_.b;
break;
case SDLK_C:
if (color.b > 0)
--color.b;
if (color_.b > 0)
--color_.b;
break;
case SDLK_F:
if (color.r < 255)
++color.r;
if (color.g < 255)
++color.g;
if (color.b < 255)
++color.b;
if (color_.r < 255)
++color_.r;
if (color_.g < 255)
++color_.g;
if (color_.b < 255)
++color_.b;
break;
case SDLK_V:
if (color.r > 0)
--color.r;
if (color.g > 0)
--color.g;
if (color.b > 0)
--color.b;
if (color_.r > 0)
--color_.r;
if (color_.g > 0)
--color_.g;
if (color_.b > 0)
--color_.b;
break;
default:
break;
}
tiled_bg_->setColor(color);
tiled_bg_->setColor(color_);
std::cout << "#"
<< std::hex << std::setw(2) << std::setfill('0') << (int)color.r
<< std::setw(2) << std::setfill('0') << (int)color.g
<< std::setw(2) << std::setfill('0') << (int)color.b
<< std::hex << std::setw(2) << std::setfill('0') << (int)color_.r
<< std::setw(2) << std::setfill('0') << (int)color_.g
<< std::setw(2) << std::setfill('0') << (int)color_.b
<< std::endl;
}
#endif
@@ -572,7 +572,7 @@ void Intro::updatePostState() {
void Intro::renderTextRect() {
static const float HEIGHT = Resource::get()->getText("04b_25_metal")->getCharacterSize();
static SDL_FRect rect = {0.0f, param.game.height - param.intro.text_distance_from_bottom - HEIGHT, param.game.width, HEIGHT * 3};
static SDL_FRect rect_ = {0.0f, param.game.height - param.intro.text_distance_from_bottom - HEIGHT, param.game.width, HEIGHT * 3};
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), param.intro.shadow_color.r, param.intro.shadow_color.g, param.intro.shadow_color.b, param.intro.shadow_color.a);
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect);
SDL_RenderFillRect(Screen::get()->getRenderer(), &rect_);
}

View File

@@ -110,18 +110,18 @@ void Logo::updateJAILGAMES() {
// Gestiona el color de las texturas
void Logo::updateTextureColors() {
constexpr int inc = 4;
constexpr int INC = 4;
// Manejo de 'sinceTexture'
for (int i = 0; i <= 7; ++i) {
if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK + inc * i) {
if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK + INC * i) {
since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b);
}
}
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
for (int i = 0; i <= 6; ++i) {
if (counter_ == INIT_FADE_COUNTER_MARK + inc * i) {
if (counter_ == INIT_FADE_COUNTER_MARK + INC * i) {
jail_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
since_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
}

View File

@@ -109,65 +109,65 @@ void Title::checkEvents() {
while (SDL_PollEvent(&event)) {
#ifdef DEBUG
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 1) {
static Color color = param.title.bg_color;
static Color color_ = param.title.bg_color;
switch (event.key.key) {
case SDLK_A:
if (color.r < 255)
++color.r;
if (color_.r < 255)
++color_.r;
break;
case SDLK_Z:
if (color.r > 0)
--color.r;
if (color_.r > 0)
--color_.r;
break;
case SDLK_S:
if (color.g < 255)
++color.g;
if (color_.g < 255)
++color_.g;
break;
case SDLK_X:
if (color.g > 0)
--color.g;
if (color_.g > 0)
--color_.g;
break;
case SDLK_D:
if (color.b < 255)
++color.b;
if (color_.b < 255)
++color_.b;
break;
case SDLK_C:
if (color.b > 0)
--color.b;
if (color_.b > 0)
--color_.b;
break;
case SDLK_F:
if (color.r < 255)
++color.r;
if (color.g < 255)
++color.g;
if (color.b < 255)
++color.b;
if (color_.r < 255)
++color_.r;
if (color_.g < 255)
++color_.g;
if (color_.b < 255)
++color_.b;
break;
case SDLK_V:
if (color.r > 0)
--color.r;
if (color.g > 0)
--color.g;
if (color.b > 0)
--color.b;
if (color_.r > 0)
--color_.r;
if (color_.g > 0)
--color_.g;
if (color_.b > 0)
--color_.b;
break;
default:
break;
}
counter_ = 0;
tiled_bg_->setColor(color);
tiled_bg_->setColor(color_);
std::cout << "#"
<< std::hex << std::setw(2) << std::setfill('0') << (int)color.r
<< std::setw(2) << std::setfill('0') << (int)color.g
<< std::setw(2) << std::setfill('0') << (int)color.b
<< std::hex << std::setw(2) << std::setfill('0') << (int)color_.r
<< std::setw(2) << std::setfill('0') << (int)color_.g
<< std::setw(2) << std::setfill('0') << (int)color_.b
<< std::endl;
}
#endif
@@ -218,11 +218,11 @@ void Title::checkInput() {
if (!ServiceMenu::get()->isEnabled()) {
// Comprueba todos los métodos de control
for (const auto &CONTROLLER : Options::controllers) {
for (const auto &controller : Options::controllers) {
// Boton START
if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, controller.type, controller.index)) {
if ((state_ != TitleState::LOGO_ANIMATING || ALLOW_TITLE_ANIMATION_SKIP)) {
if (CONTROLLER.player_id == 1) {
if (controller.player_id == 1) {
if (!player1_start_pressed_) {
player1_start_pressed_ = true;
getPlayer(1)->setPlayingState(PlayerState::TITLE_ANIMATION);
@@ -231,7 +231,7 @@ void Title::checkInput() {
}
}
if (CONTROLLER.player_id == 2) {
if (controller.player_id == 2) {
if (!player2_start_pressed_) {
player2_start_pressed_ = true;
getPlayer(2)->setPlayingState(PlayerState::TITLE_ANIMATION);
@@ -292,9 +292,9 @@ void Title::showControllers() {
// Genera el texto correspondiente
for (size_t i = 0; i < NUM_CONTROLLERS; ++i) {
const size_t index = player_controller_index.at(i);
if (Options::controllers.at(index).plugged) {
text.at(i) = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(i + 1) + ": " + Options::controllers.at(index).name;
const size_t INDEX = player_controller_index.at(i);
if (Options::controllers.at(INDEX).plugged) {
text.at(i) = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(i + 1) + ": " + Options::controllers.at(INDEX).name;
}
}