clang-tidy modernize

This commit is contained in:
2025-07-20 12:51:24 +02:00
parent bfda842d3c
commit 1f0184fde2
74 changed files with 658 additions and 665 deletions

View File

@@ -451,9 +451,9 @@ 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 auto r_ = static_cast<float>(UPPER_LIMIT);
static auto g_ = static_cast<float>(LOWER_LIMIT);
static auto 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;

View File

@@ -1,9 +1,9 @@
#include "game.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget
#include <stdlib.h> // Para rand, size_t
#include <algorithm> // Para find_if, clamp, find, min
#include <cstdlib> // Para rand, size_t
#include <functional> // Para function
#include <iterator> // Para distance, size
@@ -399,7 +399,7 @@ void Game::destroyAllItems() {
}
// Comprueba la colisión entre el jugador y los globos activos
std::shared_ptr<Balloon> Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) {
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::shared_ptr<Balloon> {
for (auto &balloon : balloon_manager_->getBalloons()) {
if (!balloon->isInvulnerable() && !balloon->isPowerBall()) {
if (checkCollision(player->getCollider(), balloon->getCollider())) {
@@ -594,7 +594,7 @@ void Game::renderItems() {
}
// Devuelve un item al azar y luego segun sus probabilidades
ItemType Game::dropItem() {
auto Game::dropItem() -> ItemType {
const auto LUCKY_NUMBER = rand() % 100;
const auto ITEM = rand() % 6;
@@ -960,8 +960,8 @@ void Game::initPaths() {
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));
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 20);
paths_.emplace_back(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)
@@ -972,8 +972,8 @@ void Game::initPaths() {
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));
paths_.emplace_back(createPath(Y0, Y1, PathType::VERTICAL, X, 80, easeOutQuint), 20);
paths_.emplace_back(createPath(Y1, Y2, PathType::VERTICAL, X, 80, easeInQuint), 0);
}
// Recorrido para el texto de "Congratulations!!" (3,4)
@@ -985,8 +985,8 @@ void Game::initPaths() {
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));
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 400);
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
}
// Recorrido para el texto de "1.000.000 points!" (5,6)
@@ -998,8 +998,8 @@ void Game::initPaths() {
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));
paths_.emplace_back(createPath(X0, X1, PathType::HORIZONTAL, Y, 80, easeOutQuint), 400);
paths_.emplace_back(createPath(X1, X2, PathType::HORIZONTAL, Y, 80, easeInQuint), 0);
}
}
@@ -1021,7 +1021,7 @@ void Game::updateHelper() {
}
// Comprueba si todos los jugadores han terminado de jugar
bool Game::allPlayersAreWaitingOrGameOver() {
auto Game::allPlayersAreWaitingOrGameOver() -> bool {
auto success = true;
for (const auto &player : players_)
success &= player->isWaiting() || player->isGameOver();
@@ -1030,7 +1030,7 @@ bool Game::allPlayersAreWaitingOrGameOver() {
}
// Comprueba si todos los jugadores han terminado de jugar
bool Game::allPlayersAreGameOver() {
auto Game::allPlayersAreGameOver() -> bool {
auto success = true;
for (const auto &player : players_)
success &= player->isGameOver();
@@ -1039,7 +1039,7 @@ bool Game::allPlayersAreGameOver() {
}
// Comprueba si todos los jugadores han terminado de jugar
bool Game::allPlayersAreNotPlaying() {
auto Game::allPlayersAreNotPlaying() -> bool {
auto success = true;
for (const auto &player : players_)
success &= !player->isPlaying();
@@ -1131,7 +1131,7 @@ void Game::checkPlayersStatusPlaying() {
}
// Obtiene un jugador a partir de su "id"
std::shared_ptr<Player> Game::getPlayer(int id) {
auto Game::getPlayer(int id) -> std::shared_ptr<Player> {
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto &player) { return player->getId() == id; });
if (it != players_.end()) {
@@ -1141,7 +1141,7 @@ std::shared_ptr<Player> Game::getPlayer(int id) {
}
// Obtiene un controlador a partir del "id" del jugador
int Game::getController(int player_id) {
auto Game::getController(int player_id) -> int {
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()) {

View File

@@ -74,28 +74,25 @@ class Game {
// --- Estructuras ---
struct Helper {
bool need_coffee; // Indica si se necesitan cafes
bool need_coffee_machine; // Indica si se necesita PowerUp
bool need_power_ball; // Indica si se necesita una PowerBall
int counter; // Contador para no dar ayudas consecutivas
int item_disk_odds; // Probabilidad de aparición del objeto
int item_gavina_odds; // Probabilidad de aparición del objeto
int item_pacmar_odds; // Probabilidad de aparición del objeto
int item_clock_odds; // Probabilidad de aparición del objeto
int item_coffee_odds; // Probabilidad de aparición del objeto
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
bool need_coffee{false}; // Indica si se necesitan cafes
bool need_coffee_machine{false}; // Indica si se necesita PowerUp
bool need_power_ball{false}; // Indica si se necesita una PowerBall
int counter; // Contador para no dar ayudas consecutivas
int item_disk_odds; // Probabilidad de aparición del objeto
int item_gavina_odds; // Probabilidad de aparición del objeto
int item_pacmar_odds; // Probabilidad de aparición del objeto
int item_clock_odds; // Probabilidad de aparición del objeto
int item_coffee_odds; // Probabilidad de aparición del objeto
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
Helper()
: need_coffee(false),
need_coffee_machine(false),
need_power_ball(false),
counter(HELP_COUNTER),
item_disk_odds(ITEM_POINTS_1_DISK_ODDS),
item_gavina_odds(ITEM_POINTS_2_GAVINA_ODDS),
item_pacmar_odds(ITEM_POINTS_3_PACMAR_ODDS),
item_clock_odds(ITEM_CLOCK_ODDS),
item_coffee_odds(ITEM_COFFEE_ODDS),
item_coffee_machine_odds(ITEM_COFFEE_MACHINE_ODDS) {}
Helper()
: counter(HELP_COUNTER),
item_disk_odds(ITEM_POINTS_1_DISK_ODDS),
item_gavina_odds(ITEM_POINTS_2_GAVINA_ODDS),
item_pacmar_odds(ITEM_POINTS_3_PACMAR_ODDS),
item_clock_odds(ITEM_CLOCK_ODDS),
item_coffee_odds(ITEM_COFFEE_ODDS),
item_coffee_machine_odds(ITEM_COFFEE_MACHINE_ODDS) {}
};
// --- Objetos y punteros ---
@@ -170,7 +167,7 @@ class Game {
void updateStage(); // Comprueba si hay cambio de fase y actualiza las variables
void updateGameStateGameOver(); // Actualiza el estado de fin de la partida
void destroyAllItems(); // Destruye todos los items
std::shared_ptr<Balloon> checkPlayerBalloonCollision(std::shared_ptr<Player> &player); // Comprueba la colisión entre el jugador y los globos activos
auto checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::shared_ptr<Balloon>; // Comprueba la colisión entre el jugador y los globos activos
void checkPlayerItemCollision(std::shared_ptr<Player> &player); // Comprueba la colisión entre el jugador y los items
void checkBulletCollision(); // Comprueba y procesa la colisión de las balas
void updateBullets(); // Mueve las balas activas
@@ -179,7 +176,7 @@ class Game {
void freeBullets(); // Vacia el vector de balas
void updateItems(); // Actualiza los items
void renderItems(); // Pinta los items activos
ItemType dropItem(); // Devuelve un item en función del azar
auto dropItem() -> ItemType; // Devuelve un item en función del azar
void createItem(ItemType type, float x, float y); // Crea un objeto item
void freeItems(); // Vacia el vector de items
void createItemText(int x, std::shared_ptr<Texture> texture); // Crea un objeto PathSprite
@@ -198,17 +195,17 @@ class Game {
void enableTimeStopItem(); // Habilita el efecto del item de detener el tiempo
void disableTimeStopItem(); // Deshabilita el efecto del item de detener el tiempo
void updateHelper(); // Actualiza las variables de ayuda
bool allPlayersAreWaitingOrGameOver(); // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreGameOver(); // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreNotPlaying(); // Comprueba si todos los jugadores han terminado de jugar
auto allPlayersAreWaitingOrGameOver() -> bool; // Comprueba si todos los jugadores han terminado de jugar
auto allPlayersAreGameOver() -> bool; // Comprueba si todos los jugadores han terminado de jugar
auto allPlayersAreNotPlaying() -> bool; // Comprueba si todos los jugadores han terminado de jugar
void updateScoreboard(); // Actualiza el marcador
void fillCanvas(); // Dibuja los elementos de la zona de juego en su textura
void pause(bool value); // Pausa el juego
void addScoreToScoreBoard(const std::shared_ptr<Player> &player); // Añade una puntuación a la tabla de records
void checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index); // Saca del estado de GAME OVER al jugador si el otro está activo
void checkPlayersStatusPlaying(); // Comprueba el estado de juego de los jugadores
std::shared_ptr<Player> getPlayer(int id); // Obtiene un jugador a partir de su "id"
int getController(int player_id); // Obtiene un controlador a partir del "id" del jugador
auto getPlayer(int id) -> std::shared_ptr<Player>; // Obtiene un jugador a partir de su "id"
auto getController(int player_id) -> int; // Obtiene un controlador a partir del "id" del jugador
void checkInput(); // Gestiona la entrada durante el juego
void checkPauseInput(); // Verifica si alguno de los controladores ha solicitado una pausa y actualiza el estado de pausa del juego.
void demoHandleInput(); // Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.

View File

@@ -1,9 +1,9 @@
#include "hiscore_table.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget
#include <stdlib.h> // Para rand, size_t
#include <algorithm> // Para max
#include <cstdlib> // Para rand, size_t
#include <functional> // Para function
#include <vector> // Para vector
@@ -32,7 +32,7 @@ HiScoreTable::HiScoreTable()
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
fade_(std::make_unique<Fade>()),
background_(std::make_unique<Background>()),
counter_(0),
ticks_(0),
view_area_(SDL_FRect{0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)}),
fade_mode_(FadeMode::IN),
@@ -168,7 +168,7 @@ void HiScoreTable::updateFade() {
}
// Convierte un entero a un string con separadores de miles
std::string HiScoreTable::format(int number) {
auto HiScoreTable::format(int number) -> std::string {
const std::string SEPARATOR = ".";
const std::string SCORE = std::to_string(number);
@@ -341,7 +341,7 @@ void HiScoreTable::initBackground() {
}
// Obtiene un color del vector de colores de entradas
Color HiScoreTable::getEntryColor(int counter) {
auto HiScoreTable::getEntryColor(int counter) -> Color {
int cycle_length = entry_colors_.size() * 2 - 2;
size_t n = counter % cycle_length;

View File

@@ -64,14 +64,14 @@ class HiScoreTable {
void render(); // Pinta en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
std::string format(int number); // Convierte un entero a un string con separadores de miles
auto format(int number) -> std::string; // Convierte un entero a un string con separadores de miles
void fillTexture(); // Dibuja los sprites en la textura
void updateFade(); // Gestiona el fade
void createSprites(); // Crea los sprites con los textos
void updateSprites(); // Actualiza las posiciones de los sprites de texto
void initFade(); // Inicializa el fade
void initBackground(); // Inicializa el fondo
Color getEntryColor(int counter); // Obtiene un color del vector de colores de entradas
auto getEntryColor(int counter) -> Color; // Obtiene un color del vector de colores de entradas
void iniEntryColors(); // Inicializa los colores de las entradas
void glowEntryNames(); // Hace brillar los nombres de la tabla de records
void updateCounter(); // Gestiona el contador

View File

@@ -279,7 +279,7 @@ void Instructions::run() {
}
// Método para inicializar las líneas
std::vector<Line> Instructions::initializeLines(int height) {
auto Instructions::initializeLines(int height) -> std::vector<Line> {
std::vector<Line> lines;
for (int y = 0; y < height; y++) {
int direction = (y % 2 == 0) ? -1 : 1; // Pares a la izquierda, impares a la derecha
@@ -289,7 +289,7 @@ 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 start_delay) {
auto Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 start_delay) -> bool {
Uint32 current_time = SDL_GetTicks();
bool all_lines_off_screen = true;

View File

@@ -29,11 +29,11 @@ struct Line {
int y; // Coordenada Y de la línea
float x; // Coordenada X inicial (usamos float para mayor precisión en el suavizado)
int direction; // Dirección de movimiento: -1 para izquierda, 1 para derecha
Uint32 start_time; // Tiempo de inicio del movimiento
Uint32 start_time{0}; // Tiempo de inicio del movimiento
// Constructor de Line
Line(int y, float x, int direction)
: y(y), x(x), direction(direction), start_time(0) {}
: y(y), x(x), direction(direction) {}
};
// Clase Instructions
@@ -80,8 +80,8 @@ class Instructions {
void fillBackbuffer(); // Rellena el backbuffer
void iniSprites(); // Inicializa los sprites de los items
void updateSprites(); // Actualiza los sprites
std::vector<Line> initializeLines(int height); // Inicializa las líneas animadas
bool moveLines(std::vector<Line> &lines, int width, float duration, Uint32 start_delay); // Mueve las líneas
auto initializeLines(int height) -> std::vector<Line>; // Inicializa las líneas animadas
auto moveLines(std::vector<Line> &lines, int width, float duration, Uint32 start_delay) -> bool; // Mueve las líneas
void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines); // Renderiza las líneas
void updateBackbuffer(); // Gestiona la textura con los gráficos
};

View File

@@ -46,14 +46,14 @@ Logo::Logo()
}
// Inicializa el vector de colores
color_.push_back(Color(0x00, 0x00, 0x00)); // Black
color_.push_back(Color(0x00, 0x00, 0xd8)); // Blue
color_.push_back(Color(0xd8, 0x00, 0x00)); // Red
color_.push_back(Color(0xd8, 0x00, 0xd8)); // Magenta
color_.push_back(Color(0x00, 0xd8, 0x00)); // Green
color_.push_back(Color(0x00, 0xd8, 0xd8)); // Cyan
color_.push_back(Color(0xd8, 0xd8, 0x00)); // Yellow
color_.push_back(Color(0xFF, 0xFF, 0xFF)); // Bright white
color_.emplace_back(0x00, 0x00, 0x00); // Black
color_.emplace_back(0x00, 0x00, 0xd8); // Blue
color_.emplace_back(0xd8, 0x00, 0x00); // Red
color_.emplace_back(0xd8, 0x00, 0xd8); // Magenta
color_.emplace_back(0x00, 0xd8, 0x00); // Green
color_.emplace_back(0x00, 0xd8, 0xd8); // Cyan
color_.emplace_back(0xd8, 0xd8, 0x00); // Yellow
color_.emplace_back(0xFF, 0xFF, 0xFF); // Bright white
}
// Destructor

View File

@@ -1,9 +1,9 @@
#include "title.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, Uint32, SDL_EventType
#include <stddef.h> // Para size_t
#include <algorithm> // Para find_if
#include <cstddef> // Para size_t
#include <iostream> // Para basic_ostream, basic_ostream::operator<<
#include <string> // Para basic_string, char_traits, operator+
#include <vector> // Para vector
@@ -513,7 +513,7 @@ void Title::renderPlayers() {
}
// Obtiene un jugador a partir de su "id"
std::shared_ptr<Player> Title::getPlayer(int id) {
auto Title::getPlayer(int id) -> std::shared_ptr<Player> {
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto &player) { return player->getId() == id; });
if (it != players_.end()) {

View File

@@ -92,5 +92,5 @@ class Title {
void initPlayers(); // Inicializa los jugadores
void renderPlayers(); // Renderiza los jugadores
void updatePlayers(); // Actualza los jugadores
std::shared_ptr<Player> getPlayer(int id); // Obtiene un jugador a partir de su "id"
auto getPlayer(int id) -> std::shared_ptr<Player>; // Obtiene un jugador a partir de su "id"
};