clang-tidy readability-function-cognitive-complexity

This commit is contained in:
2025-07-20 15:24:47 +02:00
parent ca99f7be34
commit cb4e4b450d
20 changed files with 315 additions and 434 deletions

View File

@@ -97,7 +97,7 @@ class Balloon {
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; }
[[nodiscard]] auto isBeingCreated() const -> bool { return being_created_; }
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
auto isUsingReversedColor() const -> bool { return use_reversed_colors_; }
[[nodiscard]] auto isUsingReversedColor() const -> bool { return use_reversed_colors_; }
[[nodiscard]] auto canBePopped() const -> bool { return !isBeingCreated(); }
// --- Setters ---

View File

@@ -13,30 +13,45 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner
pos_y_(y),
bullet_type_(bullet_type),
owner_(owner) {
vel_x_ = (bullet_type_ == BulletType::LEFT) ? VEL_X_LEFT
: (bullet_type_ == BulletType::RIGHT) ? VEL_X_RIGHT
: 0;
vel_x_ = calculateVelocity(bullet_type_);
sprite_->setCurrentAnimation(buildAnimationString(bullet_type_, powered));
collider_.r = WIDTH / 2;
shiftColliders();
}
std::string powered_type = powered ? "powered_" : "normal_";
// Calcula la velocidad horizontal de la bala basada en su tipo
float Bullet::calculateVelocity(BulletType bullet_type) {
switch (bullet_type) {
case BulletType::LEFT:
return VEL_X_LEFT;
case BulletType::RIGHT:
return VEL_X_RIGHT;
default:
return VEL_X_CENTER;
}
}
// Construye el string de animación basado en el tipo de bala y si está potenciada
std::string Bullet::buildAnimationString(BulletType bullet_type, bool powered) {
std::string animation_string = powered ? "powered_" : "normal_";
switch (bullet_type) {
case BulletType::UP:
sprite_->setCurrentAnimation(powered_type + "up");
animation_string += "up";
break;
case BulletType::LEFT:
sprite_->setCurrentAnimation(powered_type + "left");
animation_string += "left";
break;
case BulletType::RIGHT:
sprite_->setCurrentAnimation(powered_type + "right");
animation_string += "right";
break;
default:
break;
}
collider_.r = WIDTH / 2;
shiftColliders();
return animation_string;
}
// Implementación de render (llama al render del sprite_)

View File

@@ -23,46 +23,49 @@ enum class BulletMoveStatus : Uint8 {
// Clase Bullet
class Bullet {
public:
// Constantes
static constexpr float WIDTH = 12.0F;
static constexpr float HEIGHT = 12.0F;
public:
// Constantes
static constexpr float WIDTH = 12.0F;
static constexpr float HEIGHT = 12.0F;
// Constructor y Destructor
Bullet(float x, float y, BulletType bullet_type, bool powered, int owner);
~Bullet() = default;
// Constructor y Destructor
Bullet(float x, float y, BulletType bullet_type, bool powered, int owner);
~Bullet() = default;
// Métodos principales
void render(); // Dibuja la bala en pantalla
auto update() -> BulletMoveStatus; // Actualiza el estado del objeto
// Métodos principales
void render(); // Dibuja la bala en pantalla
auto update() -> BulletMoveStatus; // Actualiza el estado del objeto
// Estado de la bala
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si está activa
void disable(); // Desactiva la bala
// Estado de la bala
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si está activa
void disable(); // Desactiva la bala
// Getters
[[nodiscard]] auto getOwner() const -> int; // Devuelve el identificador del dueño
auto getCollider() -> Circle &; // Devuelve el círculo de colisión
// Getters
[[nodiscard]] auto getOwner() const -> int; // Devuelve el identificador del dueño
auto getCollider() -> Circle &; // Devuelve el círculo de colisión
private:
// Constantes
static constexpr float VEL_Y = -3.0F;
static constexpr float VEL_X_LEFT = -2.0F;
static constexpr float VEL_X_RIGHT = 2.0F;
private:
// Constantes
static constexpr float VEL_Y = -3.0F;
static constexpr float VEL_X_LEFT = -2.0F;
static constexpr float VEL_X_RIGHT = 2.0F;
static constexpr float VEL_X_CENTER = 0.0F;
// Propiedades
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los gráficos
// Propiedades
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los gráficos
float pos_x_; // Posición en el eje X
float pos_y_; // Posición en el eje Y
float vel_x_; // Velocidad en el eje X
float pos_x_; // Posición en el eje X
float pos_y_; // Posición en el eje Y
float vel_x_; // Velocidad en el eje X
BulletType bullet_type_; // Tipo de bala
int owner_; // Identificador del dueño
Circle collider_; // Círculo de colisión
BulletType bullet_type_; // Tipo de bala
int owner_; // Identificador del dueño
Circle collider_; // Círculo de colisión
// Métodos internos
void shiftColliders(); // Ajusta el círculo de colisión
void shiftSprite(); // Ajusta el sprite
auto move() -> BulletMoveStatus; // Mueve la bala y devuelve su estado
// Métodos internos
void shiftColliders(); // Ajusta el círculo de colisión
void shiftSprite(); // Ajusta el sprite
auto move() -> BulletMoveStatus; // Mueve la bala y devuelve su estado
float calculateVelocity(BulletType bullet_type); // Calcula la velocidad horizontal de la bala basada en su tipo
std::string buildAnimationString(BulletType bullet_type, bool powered); // Construye el string de animación basado en el tipo de bala y si está potenciada
};

View File

@@ -588,7 +588,7 @@ void Director::reset() {
Lang::setLanguage(Options::settings.language);
Audio::get()->stopMusic();
Audio::get()->stopAllSounds();
if (Section::options == Section::Options::RELOAD || true) {
if (true) {
Resource::get()->reload();
}
Input::get()->discoverGameControllers();

View File

@@ -26,29 +26,29 @@ private:
void close(); // Cierra y libera recursos
// --- Configuración inicial ---
void loadParams(); // Carga los parámetros del programa
void loadScoreFile(); // Carga el fichero de puntuaciones
static void loadParams(); // Carga los parámetros del programa
static void loadScoreFile(); // Carga el fichero de puntuaciones
void createSystemFolder(const std::string &folder); // Crea la carpeta del sistema
// --- Gestión de entrada y archivos ---
void bindInputs(); // Asigna botones y teclas al sistema de entrada
static void bindInputs(); // Asigna botones y teclas al sistema de entrada
void setFileList(); // Crea el índice de archivos disponibles
void checkProgramArguments(int argc, std::span<char*> argv); // Verifica los parámetros del programa // NOLINT(modernize-avoid-c-arrays)
// --- Secciones del programa ---
void runLogo(); // Ejecuta la pantalla con el logo
void runIntro(); // Ejecuta la introducción del juego
void runTitle(); // Ejecuta la pantalla de título
void runGame(); // Inicia el juego
void runInstructions(); // Muestra las instrucciones
void runCredits(); // Muestra los créditos del juego
void runHiScoreTable(); // Muestra la tabla de puntuaciones
void runDemoGame(); // Ejecuta el modo demo
static void runLogo(); // Ejecuta la pantalla con el logo
static void runIntro(); // Ejecuta la introducción del juego
static void runTitle(); // Ejecuta la pantalla de título
static void runGame(); // Inicia el juego
static void runInstructions(); // Muestra las instrucciones
static void runCredits(); // Muestra los créditos del juego
static void runHiScoreTable(); // Muestra la tabla de puntuaciones
static void runDemoGame(); // Ejecuta el modo demo
void reset(); // Reinicia objetos y vuelve a la sección inicial
// --- Gestión de archivos de idioma ---
auto getLangFile(Lang::Code code) -> std::string; // Obtiene un fichero de idioma según el código
// --- Apagado del sistema ---
void shutdownSystem(bool should_shutdown); // Apaga el sistema
static void shutdownSystem(bool should_shutdown); // Apaga el sistema
};

View File

@@ -78,5 +78,5 @@ private:
// --- Métodos internos ---
void init(); // Inicializa las variables
auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
[[nodiscard]] auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
};

View File

@@ -321,7 +321,8 @@ auto Input::checkAxisInput(InputAction input, int controller_index, bool repeat)
// Transición de inactivo a activo
binding.axis_active = true;
return true;
} else if (!axis_active_now && binding.axis_active) {
}
if (!axis_active_now && binding.axis_active) {
// Transición de activo a inactivo
binding.axis_active = false;
}

View File

@@ -87,7 +87,7 @@ class Input {
// --- Métodos de gestión de mandos ---
auto discoverGameControllers() -> bool; // Busca si hay mandos conectados
auto gameControllerFound() const -> bool; // Comprueba si hay algún mando conectado
[[nodiscard]] auto gameControllerFound() const -> bool; // Comprueba si hay algún mando conectado
[[nodiscard]] auto getNumControllers() const -> int; // Obtiene el número de mandos conectados
[[nodiscard]] auto getControllerName(int controller_index) const -> std::string; // Obtiene el nombre de un mando de juego
[[nodiscard]] auto getJoyIndex(SDL_JoystickID id) const -> int; // Obtiene el índice del controlador a partir de un event.id

View File

@@ -185,7 +185,8 @@ auto Item::getCoffeeMachineSpawn(int player_x, int item_width, int area_width, i
} // Lado derecho
return rand() % (RIGHT_BOUND - exclude_right) + exclude_right;
} else if (can_spawn_left) {
}
if (can_spawn_left) {
// Solo lado izquierdo disponible
return rand() % (exclude_left - LEFT_BOUND) + LEFT_BOUND;
} else if (can_spawn_right) {

View File

@@ -50,7 +50,7 @@ struct VideoOptions {
std::string info; // Información sobre el modo de vídeo
// Constructor por defecto con valores iniciales
VideoOptions() {}
VideoOptions() = default;
};
// --- Opciones de música ---
@@ -79,9 +79,7 @@ struct AudioOptions {
int volume{100}; // Volumen general del audio
// Constructor por defecto
AudioOptions()
{}
AudioOptions() = default;
};
// --- Opciones de configuración ---
@@ -119,7 +117,6 @@ struct GamepadOptions {
GamepadOptions()
: index(INVALID_INDEX),
player_id(INVALID_INDEX),
inputs{
InputAction::FIRE_LEFT,
InputAction::FIRE_CENTER,

View File

@@ -2,10 +2,12 @@
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogError, SDL_LogInfo
#include <fstream> // Para basic_istream, basic_ifstream, ifstream
#include <fstream> // Para basic_istream, basic_ifstream, ifstream
#include <functional>
#include <sstream> // Para basic_istringstream
#include <stdexcept> // Para runtime_error
#include <string> // Para operator==, stoi, char_traits, string, ope...
#include <unordered_map>
#include "utils.h" // Para Zone, Color, NotifyPosition, getFileName
@@ -15,7 +17,7 @@ Param param;
void precalculateZones();
// Asigna variables a partir de dos cadenas
auto setParams(const std::string &var, const std::string &value) -> bool;
auto setParams(const std::string& var, const std::string& value) -> bool;
// Establece valores por defecto a las variables
void initParam() {
@@ -89,7 +91,7 @@ void initParam() {
}
// Carga los parámetros desde un archivo
void loadParamsFromFile(const std::string &file_path) {
void loadParamsFromFile(const std::string& file_path) {
// Inicializa los parámetros con valores por defecto
initParam();
@@ -128,219 +130,97 @@ void loadParamsFromFile(const std::string &file_path) {
precalculateZones();
}
// Asigna variables a partir de dos cadenas
auto setParams(const std::string &var, const std::string &value) -> bool {
// Indicador de éxito en la asignación
auto success = true;
auto setParams(const std::string& var, const std::string& value) -> bool {
static const std::unordered_map<std::string, std::function<void(const std::string&)>> intParams = {
{"game.width", [](const std::string& v) { param.game.width = std::stoi(v); }},
{"game.height", [](const std::string& v) { param.game.height = std::stoi(v); }},
{"game.item_size", [](const std::string& v) { param.game.item_size = std::stoi(v); }},
{"game.play_area.rect.x", [](const std::string& v) { param.game.play_area.rect.x = std::stoi(v); }},
{"game.play_area.rect.y", [](const std::string& v) { param.game.play_area.rect.y = std::stoi(v); }},
{"game.play_area.rect.w", [](const std::string& v) { param.game.play_area.rect.w = std::stoi(v); }},
{"game.play_area.rect.h", [](const std::string& v) { param.game.play_area.rect.h = std::stoi(v); }},
{"game.name_entry_idle_time", [](const std::string& v) { param.game.name_entry_idle_time = std::stoi(v); }},
{"game.name_entry_total_time", [](const std::string& v) { param.game.name_entry_total_time = std::stoi(v); }},
{"game.hit_stop_ms", [](const std::string& v) { param.game.hit_stop_ms = std::stoi(v); }},
{"fade.num_squares_width", [](const std::string& v) { param.fade.num_squares_width = std::stoi(v); }},
{"fade.num_squares_height", [](const std::string& v) { param.fade.num_squares_height = std::stoi(v); }},
{"fade.random_squares_delay", [](const std::string& v) { param.fade.random_squares_delay = std::stoi(v); }},
{"fade.random_squares_mult", [](const std::string& v) { param.fade.random_squares_mult = std::stoi(v); }},
{"fade.post_duration", [](const std::string& v) { param.fade.post_duration = std::stoi(v); }},
{"fade.venetian_size", [](const std::string& v) { param.fade.venetian_size = std::stoi(v); }},
{"scoreboard.rect.x", [](const std::string& v) { param.scoreboard.rect.x = std::stoi(v); }},
{"scoreboard.rect.y", [](const std::string& v) { param.scoreboard.rect.y = std::stoi(v); }},
{"scoreboard.rect.w", [](const std::string& v) { param.scoreboard.rect.w = std::stoi(v); }},
{"scoreboard.rect.h", [](const std::string& v) { param.scoreboard.rect.h = std::stoi(v); }},
{"scoreboard.skip_countdown_value", [](const std::string& v) { param.scoreboard.skip_countdown_value = std::stoi(v); }},
{"title.press_start_position", [](const std::string& v) { param.title.press_start_position = std::stoi(v); }},
{"title.title_duration", [](const std::string& v) { param.title.title_duration = std::stoi(v); }},
{"title.arcade_edition_position", [](const std::string& v) { param.title.arcade_edition_position = std::stoi(v); }},
{"title.title_c_c_position", [](const std::string& v) { param.title.title_c_c_position = std::stoi(v); }},
{"intro.text_distance_from_bottom", [](const std::string& v) { param.intro.text_distance_from_bottom = std::stoi(v); }}};
// GAME
if (var == "game.width") {
param.game.width = std::stoi(value);
static const std::unordered_map<std::string, std::function<void(const std::string&)>> colorParams = {
{"fade.color", [](const std::string& v) { param.fade.color = Color::fromHex(v); }},
{"scoreboard.separator_color", [](const std::string& v) { param.scoreboard.separator_color = Color::fromHex(v); }},
{"scoreboard.easy_color", [](const std::string& v) { param.scoreboard.easy_color = Color::fromHex(v); }},
{"scoreboard.normal_color", [](const std::string& v) { param.scoreboard.normal_color = Color::fromHex(v); }},
{"scoreboard.hard_color", [](const std::string& v) { param.scoreboard.hard_color = Color::fromHex(v); }},
{"scoreboard.text_color1", [](const std::string& v) { param.scoreboard.text_color1 = Color::fromHex(v); }},
{"scoreboard.text_color2", [](const std::string& v) { param.scoreboard.text_color2 = Color::fromHex(v); }},
{"title.bg_color", [](const std::string& v) { param.title.bg_color = Color::fromHex(v); }},
{"background.attenuate_color", [](const std::string& v) { param.background.attenuate_color = Color::fromHex(v); }},
{"notification.color", [](const std::string& v) { param.notification.color = Color::fromHex(v); }},
{"service_menu.title_color", [](const std::string& v) { param.service_menu.title_color = Color::fromHex(v); }},
{"service_menu.text_color", [](const std::string& v) { param.service_menu.text_color = Color::fromHex(v); }},
{"service_menu.selected_color", [](const std::string& v) { param.service_menu.selected_color = Color::fromHex(v); }},
{"service_menu.bg_color", [](const std::string& v) { param.service_menu.bg_color = Color::fromHex(v); }},
{"intro.bg_color", [](const std::string& v) { param.intro.bg_color = Color::fromHex(v); }},
{"intro.card_color", [](const std::string& v) { param.intro.card_color = Color::fromHex(v); }},
{"intro.shadow_color", [](const std::string& v) { param.intro.shadow_color = Color::fromHex(v); }},
{"debug.color", [](const std::string& v) { param.debug.color = Color::fromHex(v); }},
{"resource.color", [](const std::string& v) { param.resource.color = Color::fromHex(v); }}};
static const std::unordered_map<std::string, std::function<void(const std::string&)>> boolParams = {
{"game.hit_stop", [](const std::string& v) { param.game.hit_stop = stringToBool(v); }},
{"scoreboard.separator_autocolor", [](const std::string& v) { param.scoreboard.separator_autocolor = stringToBool(v); }},
{"scoreboard.text_autocolor", [](const std::string& v) { param.scoreboard.text_autocolor = stringToBool(v); }},
{"balloon.bouncing_sound", [](const std::string& v) { param.balloon.bouncing_sound = stringToBool(v); }},
{"notification.sound", [](const std::string& v) { param.notification.sound = stringToBool(v); }},
{"service_menu.drop_shadow", [](const std::string& v) { param.service_menu.drop_shadow = stringToBool(v); }}};
static const std::unordered_map<std::string, std::function<void(const std::string&)>> floatParams = {
{"balloon.settings[0].vel", [](const std::string& v) { param.balloon.settings.at(0).vel = std::stof(v); }},
{"balloon.settings[0].grav", [](const std::string& v) { param.balloon.settings.at(0).grav = std::stof(v); }},
{"balloon.settings[1].vel", [](const std::string& v) { param.balloon.settings.at(1).vel = std::stof(v); }},
{"balloon.settings[1].grav", [](const std::string& v) { param.balloon.settings.at(1).grav = std::stof(v); }},
{"balloon.settings[2].vel", [](const std::string& v) { param.balloon.settings.at(2).vel = std::stof(v); }},
{"balloon.settings[2].grav", [](const std::string& v) { param.balloon.settings.at(2).grav = std::stof(v); }},
{"balloon.settings[3].vel", [](const std::string& v) { param.balloon.settings.at(3).vel = std::stof(v); }},
{"balloon.settings[3].grav", [](const std::string& v) { param.balloon.settings.at(3).grav = std::stof(v); }}};
static const std::unordered_map<std::string, std::function<void(const std::string&)>> stringParams = {
{"balloon.color[0]", [](const std::string& v) { param.balloon.color.at(0) = v; }},
{"balloon.color[1]", [](const std::string& v) { param.balloon.color.at(1) = v; }},
{"balloon.color[2]", [](const std::string& v) { param.balloon.color.at(2) = v; }},
{"balloon.color[3]", [](const std::string& v) { param.balloon.color.at(3) = v; }}};
// Intentar cada mapa de parámetros
auto tryMap = [&](const auto& paramMap) -> bool {
auto it = paramMap.find(var);
if (it != paramMap.end()) {
it->second(value);
return true;
}
return false;
};
if (tryMap(intParams) || tryMap(colorParams) || tryMap(boolParams) ||
tryMap(floatParams) || tryMap(stringParams)) {
return true;
}
else if (var == "game.height") {
param.game.height = std::stoi(value);
}
else if (var == "game.item_size") {
param.game.item_size = std::stoi(value);
}
else if (var == "game.play_area.rect.x") {
param.game.play_area.rect.x = std::stoi(value);
}
else if (var == "game.play_area.rect.y") {
param.game.play_area.rect.y = std::stoi(value);
}
else if (var == "game.play_area.rect.w") {
param.game.play_area.rect.w = std::stoi(value);
}
else if (var == "game.play_area.rect.h") {
param.game.play_area.rect.h = std::stoi(value);
}
else if (var == "game.name_entry_idle_time") {
param.game.name_entry_idle_time = std::stoi(value);
}
else if (var == "game.name_entry_total_time") {
param.game.name_entry_total_time = std::stoi(value);
}
else if (var == "game.hit_stop") {
param.game.hit_stop = stringToBool(value);
}
else if (var == "game.hit_stop_ms") {
param.game.hit_stop_ms = std::stoi(value);
}
// FADE
else if (var == "fade.color") {
param.fade.color = Color::fromHex(value);
}
else if (var == "fade.num_squares_width") {
param.fade.num_squares_width = std::stoi(value);
}
else if (var == "fade.num_squares_height") {
param.fade.num_squares_height = std::stoi(value);
}
else if (var == "fade.random_squares_delay") {
param.fade.random_squares_delay = std::stoi(value);
}
else if (var == "fade.random_squares_mult") {
param.fade.random_squares_mult = std::stoi(value);
}
else if (var == "fade.post_duration") {
param.fade.post_duration = std::stoi(value);
}
else if (var == "fade.venetian_size") {
param.fade.venetian_size = std::stoi(value);
}
// SCOREBOARD
else if (var == "scoreboard.rect.x") {
param.scoreboard.rect.x = std::stoi(value);
}
else if (var == "scoreboard.rect.y") {
param.scoreboard.rect.y = std::stoi(value);
}
else if (var == "scoreboard.rect.w") {
param.scoreboard.rect.w = std::stoi(value);
}
else if (var == "scoreboard.rect.h") {
param.scoreboard.rect.h = std::stoi(value);
}
else if (var == "scoreboard.separator_autocolor") {
param.scoreboard.separator_autocolor = stringToBool(value);
}
else if (var == "scoreboard.separator_color") {
param.scoreboard.separator_color = Color::fromHex(value);
}
else if (var == "scoreboard.easy_color") {
param.scoreboard.easy_color = Color::fromHex(value);
}
else if (var == "scoreboard.normal_color") {
param.scoreboard.normal_color = Color::fromHex(value);
}
else if (var == "scoreboard.hard_color") {
param.scoreboard.hard_color = Color::fromHex(value);
}
else if (var == "scoreboard.text_autocolor") {
param.scoreboard.text_autocolor = stringToBool(value);
}
else if (var == "scoreboard.text_color1") {
param.scoreboard.text_color1 = Color::fromHex(value);
}
else if (var == "scoreboard.text_color2") {
param.scoreboard.text_color2 = Color::fromHex(value);
}
else if (var == "scoreboard.skip_countdown_value") {
param.scoreboard.skip_countdown_value = std::stoi(value);
}
// TITLE
else if (var == "title.press_start_position") {
param.title.press_start_position = std::stoi(value);
}
else if (var == "title.title_duration") {
param.title.title_duration = std::stoi(value);
}
else if (var == "title.arcade_edition_position") {
param.title.arcade_edition_position = std::stoi(value);
}
else if (var == "title.title_c_c_position") {
param.title.title_c_c_position = std::stoi(value);
}
else if (var == "title.bg_color") {
param.title.bg_color = Color::fromHex(value);
}
// BACKGROUND
else if (var == "background.attenuate_color") {
param.background.attenuate_color = Color::fromHex(value);
}
// BALLOON
else if (var == "balloon.settings[0].vel") {
param.balloon.settings.at(0).vel = std::stof(value);
}
else if (var == "balloon.settings[0].grav") {
param.balloon.settings.at(0).grav = std::stof(value);
}
else if (var == "balloon.settings[1].vel") {
param.balloon.settings.at(1).vel = std::stof(value);
}
else if (var == "balloon.settings[1].grav") {
param.balloon.settings.at(1).grav = std::stof(value);
}
else if (var == "balloon.settings[2].vel") {
param.balloon.settings.at(2).vel = std::stof(value);
}
else if (var == "balloon.settings[2].grav") {
param.balloon.settings.at(2).grav = std::stof(value);
}
else if (var == "balloon.settings[3].vel") {
param.balloon.settings.at(3).vel = std::stof(value);
}
else if (var == "balloon.settings[3].grav") {
param.balloon.settings.at(3).grav = std::stof(value);
}
else if (var == "balloon.color[0]") {
param.balloon.color.at(0) = value;
}
else if (var == "balloon.color[1]") {
param.balloon.color.at(1) = value;
}
else if (var == "balloon.color[2]") {
param.balloon.color.at(2) = value;
}
else if (var == "balloon.color[3]") {
param.balloon.color.at(3) = value;
}
else if (var == "balloon.bouncing_sound") {
param.balloon.bouncing_sound = stringToBool(value);
}
// NOTIFICACIONES
else if (var == "notification.pos_h") {
// Casos especiales que necesitan lógica personalizada
if (var == "notification.pos_h") {
if (value == "LEFT") {
param.notification.pos_h = NotifyPosition::LEFT;
} else if (value == "MIDDLE") {
@@ -348,74 +228,15 @@ auto setParams(const std::string &var, const std::string &value) -> bool {
} else {
param.notification.pos_h = NotifyPosition::RIGHT;
}
return true;
}
else if (var == "notification.pos_v") {
if (var == "notification.pos_v") {
param.notification.pos_v = value == "TOP" ? NotifyPosition::TOP : NotifyPosition::BOTTOM;
return true;
}
else if (var == "notification.sound") {
param.notification.sound = stringToBool(value);
}
else if (var == "notification.color") {
param.notification.color = Color::fromHex(value);
}
// SERVICE MENU
else if (var == "service_menu.title_color") {
param.service_menu.title_color = Color::fromHex(value);
}
else if (var == "service_menu.text_color") {
param.service_menu.text_color = Color::fromHex(value);
}
else if (var == "service_menu.selected_color") {
param.service_menu.selected_color = Color::fromHex(value);
}
else if (var == "service_menu.bg_color") {
param.service_menu.bg_color = Color::fromHex(value);
}
else if (var == "service_menu.drop_shadow") {
param.service_menu.drop_shadow = stringToBool(value);
}
// INTRO
else if (var == "intro.bg_color") {
param.intro.bg_color = Color::fromHex(value);
}
else if (var == "intro.card_color") {
param.intro.card_color = Color::fromHex(value);
}
else if (var == "intro.shadow_color") {
param.intro.shadow_color = Color::fromHex(value);
}
else if (var == "intro.text_distance_from_bottom") {
param.intro.text_distance_from_bottom = std::stoi(value);
}
// DEBUG
else if (var == "debug.color") {
param.debug.color = Color::fromHex(value);
}
// RESOURCE
else if (var == "resource.color") {
param.resource.color = Color::fromHex(value);
}
// RESTO
else {
success = false;
}
return success;
return false; // Parámetro no encontrado
}
// Calcula variables a partir de otras variables

View File

@@ -55,7 +55,7 @@ void Resource::load() {
// Muerstra la ventana y desactiva el sincronismo vertical
auto *screen = Screen::get();
auto vsync = screen->getVSync();
auto vsync = Screen::getVSync();
screen->setVSync(false);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");

View File

@@ -94,7 +94,7 @@ class Screen {
: enabled(enabled), lenght(lenght), delay(delay), counter(lenght), color(color) {}
void update() { (enabled && counter > 0) ? counter-- : static_cast<int>(enabled = false); }
auto isRendarable() const -> bool { return enabled && counter < lenght - delay; }
[[nodiscard]] auto isRendarable() const -> bool { return enabled && counter < lenght - delay; }
};
// Efecto de sacudida/agitación de pantalla: mueve la imagen para simular un temblor

View File

@@ -42,7 +42,7 @@ Credits::Credits()
fade_out_(std::make_unique<Fade>()),
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
canvas_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)) {
if (!text_texture_) {
if (text_texture_ == nullptr) {
throw std::runtime_error("Failed to create SDL texture for text.");
}
Section::name = Section::Name::CREDITS;
@@ -133,7 +133,7 @@ void Credits::checkInput() {
if (!ServiceMenu::get()->isEnabled()) {
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT)) {
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT) != 0) {
want_to_pass_ = true;
fading_ = mini_logo_on_position_;
} else {
@@ -235,7 +235,7 @@ void Credits::fillTextTexture() {
// Dibuja todos los sprites en la textura
void Credits::fillCanvas() {
// Cambia el destino del renderizador
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
auto *temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
SDL_SetRenderTarget(Screen::get()->getRenderer(), canvas_);
// Dibuja el fondo, los globos y los jugadores
@@ -378,7 +378,7 @@ void Credits::updateBlackRects() {
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_));
setVolume((initial_volume_ * current_step_ / steps_));
}
} else {
// Si los rectangulos superior e inferior han llegado al centro
@@ -393,7 +393,7 @@ void Credits::updateBlackRects() {
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_));
setVolume((initial_volume_ * current_step_ / steps_));
} else {
// Si los rectangulos izquierdo y derecho han llegado al centro
setVolume(0);
@@ -440,7 +440,7 @@ void Credits::setVolume(int amount) {
}
// Reestablece el nivel de volumen
void Credits::resetVolume() {
void Credits::resetVolume() const {
Options::audio.music.volume = initial_volume_;
Audio::get()->setMusicVolume(Options::audio.music.volume);
}
@@ -456,9 +456,9 @@ void Credits::cycleColors() {
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;
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_ += step_r_;

View File

@@ -103,7 +103,7 @@ class Credits {
// --- Métodos del bucle principal ---
void update(); // Actualización principal de la lógica
void render(); // Renderizado de la escena
void checkEvents(); // Manejo de eventos
static void checkEvents(); // Manejo de eventos
void checkInput(); // Procesamiento de entrada
// --- Métodos de renderizado ---
@@ -124,6 +124,6 @@ class Credits {
void updateRedRect(); // Actualizar rectángulo rojo (borde)
// --- Métodos de audio ---
void setVolume(int amount); // Establecer volumen
void resetVolume(); // Restablecer volumen
static void setVolume(int amount); // Establecer volumen
void resetVolume() const; // Restablecer volumen
};

View File

@@ -90,10 +90,11 @@ Game::Game(int player_id, int current_stage, bool demo)
#ifdef DEBUG
// Si se empieza en una fase que no es la primera
if (!demo_.enabled)
if (!demo_.enabled) {
for (int i = 0; i < Stage::number; ++i) {
Stage::total_power += Stage::get(i).power_to_complete;
}
}
#endif
}
@@ -184,7 +185,7 @@ void Game::updateHiScore() {
hi_score_.name.clear();
// Si se supera la máxima puntuación emite sonido
if (hi_score_achieved_ == false) {
if (!hi_score_achieved_) {
hi_score_achieved_ = true;
playSound("hi_score_achieved.wav");
}
@@ -299,7 +300,7 @@ void Game::updateGameStateGameOver() {
if (fade_out_->isEnabled()) {
if (Options::audio.enabled) {
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0f;
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0F;
Audio::get()->setSoundVolume(static_cast<int>(VOL), Audio::Group::GAME);
}
}
@@ -353,13 +354,14 @@ void Game::updateGameStateCompleted() {
createMessage({paths_.at(4), paths_.at(5)}, Resource::get()->getTexture("game_text_congratulations"));
createMessage({paths_.at(6), paths_.at(7)}, Resource::get()->getTexture("game_text_1000000_points"));
for (auto &player : players_)
for (auto &player : players_) {
if (player->isPlaying()) {
player->addScore(1000000);
player->setPlayingState(PlayerState::CELEBRATING);
} else {
player->setPlayingState(PlayerState::GAME_OVER);
}
}
updateHiScore();
}
@@ -374,7 +376,7 @@ void Game::updateGameStateCompleted() {
}
// Si los jugadores ya no estan y no quedan mensajes en pantalla
if (allPlayersAreGameOver() && path_sprites_.size() == 0) {
if (allPlayersAreGameOver() && path_sprites_.empty()) {
setState(GameState::GAME_OVER);
}
@@ -395,8 +397,9 @@ void Game::checkState() {
// Destruye todos los items
void Game::destroyAllItems() {
for (auto &item : items_)
for (auto &item : items_) {
item->disable();
}
}
// Comprueba la colisión entre el jugador y los globos activos
@@ -414,8 +417,9 @@ auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::
// Comprueba la colisión entre el jugador y los items
void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
if (!player->isPlaying())
if (!player->isPlaying()) {
return;
}
for (auto &item : items_) {
if (item->isEnabled()) {
@@ -492,7 +496,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
void Game::checkBulletCollision() {
for (auto &bullet : bullets_) {
// Comprueba la colisión con el Tabe
if (bullet->isEnabled() && tabe_->isEnabled())
if (bullet->isEnabled() && tabe_->isEnabled()) {
if (checkCollision(bullet->getCollider(), tabe_->getCollider())) {
tabe_->setState(TabeState::HIT);
bullet->disable();
@@ -508,6 +512,7 @@ void Game::checkBulletCollision() {
}
break;
}
}
// Comprueba la colisión con los globos
for (auto &balloon : balloon_manager_->getBalloons()) {
@@ -559,8 +564,9 @@ void Game::updateBullets() {
// Pinta las balas activas
void Game::renderBullets() {
for (auto &bullet : bullets_)
for (auto &bullet : bullets_) {
bullet->render();
}
}
// Crea un objeto bala
@@ -570,15 +576,18 @@ void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owne
// Vacia el vector de balas
void Game::freeBullets() {
if (!bullets_.empty())
for (int i = bullets_.size() - 1; i >= 0; --i)
if (!bullets_[i]->isEnabled())
if (!bullets_.empty()) {
for (int i = bullets_.size() - 1; i >= 0; --i) {
if (!bullets_[i]->isEnabled()) {
bullets_.erase(bullets_.begin() + i);
}
}
}
}
// Actualiza los items
void Game::updateItems() {
for (auto &item : items_)
for (auto &item : items_) {
if (item->isEnabled()) {
item->update();
if (item->isOnFloor()) {
@@ -586,12 +595,14 @@ void Game::updateItems() {
screen_->shake(1, 2, 4);
}
}
}
}
// Pinta los items activos
void Game::renderItems() {
for (auto &item : items_)
for (auto &item : items_) {
item->render();
}
}
// Devuelve un item al azar y luego segun sus probabilidades
@@ -657,10 +668,13 @@ void Game::createItem(ItemType type, float x, float y) {
// Vacia el vector de items
void Game::freeItems() {
if (!items_.empty())
for (int i = items_.size() - 1; i >= 0; --i)
if (!items_[i]->isEnabled())
if (!items_.empty()) {
for (int i = items_.size() - 1; i >= 0; --i) {
if (!items_[i]->isEnabled()) {
items_.erase(items_.begin() + i);
}
}
}
}
// Crea un objeto PathSprite
@@ -699,18 +713,24 @@ void Game::createMessage(const std::vector<Path> &paths, std::shared_ptr<Texture
// Vacia el vector de smartsprites
void Game::freeSmartSprites() {
if (!smart_sprites_.empty())
for (int i = smart_sprites_.size() - 1; i >= 0; --i)
if (smart_sprites_[i]->hasFinished())
if (!smart_sprites_.empty()) {
for (int i = smart_sprites_.size() - 1; i >= 0; --i) {
if (smart_sprites_[i]->hasFinished()) {
smart_sprites_.erase(smart_sprites_.begin() + i);
}
}
}
}
// Vacia el vector de pathsprites
void Game::freePathSprites() {
if (!path_sprites_.empty())
for (int i = path_sprites_.size() - 1; i >= 0; --i)
if (path_sprites_[i]->hasFinished())
if (!path_sprites_.empty()) {
for (int i = path_sprites_.size() - 1; i >= 0; --i) {
if (path_sprites_[i]->hasFinished()) {
path_sprites_.erase(path_sprites_.begin() + i);
}
}
}
}
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
@@ -721,10 +741,10 @@ void Game::throwCoffee(int x, int y) {
smart_sprites_.back()->setPosY(y - 8);
smart_sprites_.back()->setWidth(param.game.item_size);
smart_sprites_.back()->setHeight(param.game.item_size);
smart_sprites_.back()->setVelX(-1.0f + ((rand() % 5) * 0.5f));
smart_sprites_.back()->setVelY(-4.0f);
smart_sprites_.back()->setAccelX(0.0f);
smart_sprites_.back()->setAccelY(0.2f);
smart_sprites_.back()->setVelX(-1.0F + ((rand() % 5) * 0.5F));
smart_sprites_.back()->setVelY(-4.0F);
smart_sprites_.back()->setAccelX(0.0F);
smart_sprites_.back()->setAccelY(0.2F);
smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50));
smart_sprites_.back()->setDestY(param.game.height + 1);
smart_sprites_.back()->setEnabled(true);
@@ -865,14 +885,14 @@ 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;
constexpr float CLOUDS_INITIAL_SPEED = 0.05F;
constexpr float CLOUDS_FINAL_SPEED = 2.00F - CLOUDS_INITIAL_SPEED;
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);
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);
@@ -889,7 +909,7 @@ void Game::updateBackground() {
// Dibuja los elementos de la zona de juego en su textura
void Game::fillCanvas() {
// Dibujamos el contenido de la zona de juego en su textura
auto temp = SDL_GetRenderTarget(renderer_);
auto *temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, canvas_);
// Dibuja los objetos
@@ -1024,8 +1044,9 @@ void Game::updateHelper() {
// Comprueba si todos los jugadores han terminado de jugar
auto Game::allPlayersAreWaitingOrGameOver() -> bool {
auto success = true;
for (const auto &player : players_)
for (const auto &player : players_) {
success &= player->isWaiting() || player->isGameOver();
}
return success;
}
@@ -1033,8 +1054,9 @@ auto Game::allPlayersAreWaitingOrGameOver() -> bool {
// Comprueba si todos los jugadores han terminado de jugar
auto Game::allPlayersAreGameOver() -> bool {
auto success = true;
for (const auto &player : players_)
for (const auto &player : players_) {
success &= player->isGameOver();
}
return success;
}
@@ -1042,8 +1064,9 @@ auto Game::allPlayersAreGameOver() -> bool {
// Comprueba si todos los jugadores han terminado de jugar
auto Game::allPlayersAreNotPlaying() -> bool {
auto success = true;
for (const auto &player : players_)
for (const auto &player : players_) {
success &= !player->isPlaying();
}
return success;
}
@@ -1190,7 +1213,7 @@ void Game::checkPauseInput() {
// Gestiona las entradas de los jugadores en el modo demo para saltarse la demo.
void Game::demoHandlePassInput() {
if (input_->checkAnyButton()) {
if (input_->checkAnyButton() != 0) {
Section::name = Section::Name::TITLE; // Salir del modo demo y regresar al menú principal.
Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO; // El juego volverá a mostrar la demo
return;
@@ -1423,8 +1446,9 @@ void Game::initDemo(int player_id) {
// Asigna cafes a los jugadores
for (auto &player : players_) {
for (int i = 0; i < rand() % 3; ++i)
for (int i = 0; i < rand() % 3; ++i) {
player->giveExtraHit();
}
player->setInvulnerable(true);
}
@@ -1472,21 +1496,21 @@ void Game::initDifficultyVars() {
switch (difficulty_) {
case Options::DifficultyCode::EASY: {
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
difficulty_score_multiplier_ = 0.5f;
difficulty_score_multiplier_ = 0.5F;
scoreboard_->setColor(param.scoreboard.easy_color);
break;
}
case Options::DifficultyCode::NORMAL: {
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
difficulty_score_multiplier_ = 1.0f;
difficulty_score_multiplier_ = 1.0F;
scoreboard_->setColor(param.scoreboard.normal_color);
break;
}
case Options::DifficultyCode::HARD: {
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[4]);
difficulty_score_multiplier_ = 1.5f;
difficulty_score_multiplier_ = 1.5F;
scoreboard_->setColor(param.scoreboard.hard_color);
break;
}
@@ -1530,7 +1554,7 @@ void Game::playMusic() {
}
// Detiene la música
void Game::stopMusic() {
void Game::stopMusic() const {
if (!demo_.enabled) {
Audio::get()->stopMusic();
}
@@ -1539,7 +1563,7 @@ void Game::stopMusic() {
// Actualiza las variables durante el modo demo
void Game::updateDemo() {
if (demo_.enabled) {
balloon_manager_->setCreationTimeEnabled((balloon_manager_->getNumBalloons() == 0) ? false : true);
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
// Actualiza ambos fades
fade_in_->update();
@@ -1618,7 +1642,7 @@ void Game::updateGameStateShowingGetReadyMessage() {
updateScoreboard();
updateBackground();
freePathSprites();
if (path_sprites_.size() == 0) {
if (path_sprites_.empty()) {
setState(GameState::PLAYING);
}
if (counter_ == 100) {
@@ -1692,11 +1716,12 @@ void Game::evaluateAndSetMenace() {
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
void Game::checkAndUpdateBalloonSpeed() {
if (difficulty_ != Options::DifficultyCode::NORMAL)
if (difficulty_ != Options::DifficultyCode::NORMAL) {
return;
}
const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
constexpr std::array<float, 4> THRESHOLDS = {0.2f, 0.4f, 0.6f, 0.8f};
constexpr std::array<float, 4> 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]) {
@@ -1712,18 +1737,20 @@ void Game::setState(GameState state) {
counter_ = 0;
}
void Game::playSound(const std::string &name) {
if (demo_.enabled)
void Game::playSound(const std::string &name) const {
if (demo_.enabled) {
return;
}
static auto audio_ = Audio::get();
static auto *audio_ = Audio::get();
audio_->playSound(name);
}
// Organiza los jugadores para que los vivos se pinten sobre los muertos
void Game::movePlayersToFront() {
if (players_to_reorder_.empty())
if (players_to_reorder_.empty()) {
return;
}
for (auto &player : players_to_reorder_) {
auto it = std::find(players_.begin(), players_.end(), player);
@@ -1738,8 +1765,9 @@ void Game::movePlayersToFront() {
// Comprueba si está activo el menu de servicio para poner el juego en pausa
void Game::checkServiceMenu() {
if (demo_.enabled)
if (demo_.enabled) {
return;
}
static bool was_paused_before_service_menu_ = false;
static bool service_menu_was_active_ = false;
@@ -1761,7 +1789,7 @@ void Game::checkServiceMenu() {
#ifdef DEBUG
// Comprueba los eventos en el modo DEBUG
void Game::checkDebugEvents(const SDL_Event &event) {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0) {
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
switch (event.key.key) {
case SDLK_1: // Crea una powerball
{

View File

@@ -205,7 +205,7 @@ class Game {
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
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
static 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.
@@ -222,9 +222,9 @@ class Game {
void initScoreboard(); // Inicializa el marcador
void initDifficultyVars(); // Inicializa las opciones relacionadas con la dificultad
void initPlayers(int player_id); // Inicializa los jugadores
void playMusic(); // Hace sonar la música
void stopMusic(); // Detiene la música
void playSound(const std::string &name); // Hace sonar un sonido
static void playMusic(); // Hace sonar la música
void stopMusic() const; // Detiene la música
void playSound(const std::string &name) const; // Hace sonar un sonido
void updateDemo(); // Actualiza las variables durante el modo demo
void updateGameStateFadeIn(); // Actualiza las variables durante dicho estado
void updateGameStateEnteringPlayer(); // Actualiza las variables durante dicho estado

View File

@@ -108,55 +108,67 @@ void Title::checkEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
#ifdef DEBUG
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 1) {
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 1) {
static Color color_ = param.title.bg_color;
switch (event.key.key) {
case SDLK_A:
if (color_.r < 255)
if (color_.r < 255) {
++color_.r;
}
break;
case SDLK_Z:
if (color_.r > 0)
if (color_.r > 0) {
--color_.r;
}
break;
case SDLK_S:
if (color_.g < 255)
if (color_.g < 255) {
++color_.g;
}
break;
case SDLK_X:
if (color_.g > 0)
if (color_.g > 0) {
--color_.g;
}
break;
case SDLK_D:
if (color_.b < 255)
if (color_.b < 255) {
++color_.b;
}
break;
case SDLK_C:
if (color_.b > 0)
if (color_.b > 0) {
--color_.b;
}
break;
case SDLK_F:
if (color_.r < 255)
if (color_.r < 255) {
++color_.r;
if (color_.g < 255)
}
if (color_.g < 255) {
++color_.g;
if (color_.b < 255)
}
if (color_.b < 255) {
++color_.b;
}
break;
case SDLK_V:
if (color_.r > 0)
if (color_.r > 0) {
--color_.r;
if (color_.g > 0)
}
if (color_.g > 0) {
--color_.g;
if (color_.b > 0)
}
if (color_.b > 0) {
--color_.b;
}
break;
default:
@@ -171,7 +183,7 @@ void Title::checkEvents() {
<< std::endl;
}
#endif
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0) {
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
switch (event.key.key) {
case SDLK_1: // Redefine los botones del mando #0
define_buttons_->enable(0);
@@ -211,8 +223,9 @@ void Title::checkEvents() {
// Comprueba las entradas
void Title::checkInput() {
// Comprueba las entradas solo si no se estan definiendo los botones
if (define_buttons_->isEnabled())
if (define_buttons_->isEnabled()) {
return;
}
Input::get()->update();
@@ -263,8 +276,9 @@ void Title::resetCounter() { counter_ = 0; }
// Intercambia la asignación de mandos a los jugadores
void Title::swapControllers() {
if (Input::get()->getNumControllers() == 0)
if (Input::get()->getNumControllers() == 0) {
return;
}
Options::swapControllers();
showControllers();
@@ -443,8 +457,9 @@ void Title::renderCopyright() {
// Cambia el estado
void Title::setState(TitleState state) {
if (state_ == state)
if (state_ == state) {
return;
}
state_ = state;
switch (state_) {

View File

@@ -83,8 +83,8 @@ class Title {
void checkInput(); // Comprueba las entradas
void resetCounter(); // Reinicia el contador interno
void swapControllers(); // Intercambia la asignación de mandos a los jugadores
void swapKeyboard(); // Intercambia el teclado de jugador
void showControllers(); // Muestra información sobre los controles y los jugadores
static void swapKeyboard(); // Intercambia el teclado de jugador
static void showControllers(); // Muestra información sobre los controles y los jugadores
void updateFade(); // Actualiza el efecto de fundido (fade in/out)
void updateState(); // Actualiza el estado actual del título
void updateStartPrompt(); // Actualiza el mensaje de "Pulsa Start"

View File

@@ -67,7 +67,7 @@ class MenuRenderer {
void updateResizeAnimation();
void precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>> &all_options, const ServiceMenu *menu_state);
[[nodiscard]] auto getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const -> int;
auto getAnimatedSelectedColor() const -> Color;
[[nodiscard]] auto getAnimatedSelectedColor() const -> Color;
void updateColorCounter();
auto setRect(SDL_FRect rect) -> SDL_FRect;
};