clang-tidy readability-function-cognitive-complexity
This commit is contained in:
@@ -97,7 +97,7 @@ class Balloon {
|
|||||||
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; }
|
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; }
|
||||||
[[nodiscard]] auto isBeingCreated() const -> bool { return being_created_; }
|
[[nodiscard]] auto isBeingCreated() const -> bool { return being_created_; }
|
||||||
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
|
[[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(); }
|
[[nodiscard]] auto canBePopped() const -> bool { return !isBeingCreated(); }
|
||||||
|
|
||||||
// --- Setters ---
|
// --- Setters ---
|
||||||
|
|||||||
@@ -13,30 +13,45 @@ Bullet::Bullet(float x, float y, BulletType bullet_type, bool powered, int owner
|
|||||||
pos_y_(y),
|
pos_y_(y),
|
||||||
bullet_type_(bullet_type),
|
bullet_type_(bullet_type),
|
||||||
owner_(owner) {
|
owner_(owner) {
|
||||||
vel_x_ = (bullet_type_ == BulletType::LEFT) ? VEL_X_LEFT
|
|
||||||
: (bullet_type_ == BulletType::RIGHT) ? VEL_X_RIGHT
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
std::string powered_type = powered ? "powered_" : "normal_";
|
vel_x_ = calculateVelocity(bullet_type_);
|
||||||
|
sprite_->setCurrentAnimation(buildAnimationString(bullet_type_, powered));
|
||||||
|
|
||||||
|
collider_.r = WIDTH / 2;
|
||||||
|
shiftColliders();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
switch (bullet_type) {
|
||||||
case BulletType::UP:
|
case BulletType::UP:
|
||||||
sprite_->setCurrentAnimation(powered_type + "up");
|
animation_string += "up";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BulletType::LEFT:
|
case BulletType::LEFT:
|
||||||
sprite_->setCurrentAnimation(powered_type + "left");
|
animation_string += "left";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BulletType::RIGHT:
|
case BulletType::RIGHT:
|
||||||
sprite_->setCurrentAnimation(powered_type + "right");
|
animation_string += "right";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
collider_.r = WIDTH / 2;
|
return animation_string;
|
||||||
shiftColliders();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementación de render (llama al render del sprite_)
|
// Implementación de render (llama al render del sprite_)
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class Bullet {
|
|||||||
static constexpr float VEL_Y = -3.0F;
|
static constexpr float VEL_Y = -3.0F;
|
||||||
static constexpr float VEL_X_LEFT = -2.0F;
|
static constexpr float VEL_X_LEFT = -2.0F;
|
||||||
static constexpr float VEL_X_RIGHT = 2.0F;
|
static constexpr float VEL_X_RIGHT = 2.0F;
|
||||||
|
static constexpr float VEL_X_CENTER = 0.0F;
|
||||||
|
|
||||||
// Propiedades
|
// Propiedades
|
||||||
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los gráficos
|
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los gráficos
|
||||||
@@ -65,4 +66,6 @@ class Bullet {
|
|||||||
void shiftColliders(); // Ajusta el círculo de colisión
|
void shiftColliders(); // Ajusta el círculo de colisión
|
||||||
void shiftSprite(); // Ajusta el sprite
|
void shiftSprite(); // Ajusta el sprite
|
||||||
auto move() -> BulletMoveStatus; // Mueve la bala y devuelve su estado
|
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
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -588,7 +588,7 @@ void Director::reset() {
|
|||||||
Lang::setLanguage(Options::settings.language);
|
Lang::setLanguage(Options::settings.language);
|
||||||
Audio::get()->stopMusic();
|
Audio::get()->stopMusic();
|
||||||
Audio::get()->stopAllSounds();
|
Audio::get()->stopAllSounds();
|
||||||
if (Section::options == Section::Options::RELOAD || true) {
|
if (true) {
|
||||||
Resource::get()->reload();
|
Resource::get()->reload();
|
||||||
}
|
}
|
||||||
Input::get()->discoverGameControllers();
|
Input::get()->discoverGameControllers();
|
||||||
|
|||||||
@@ -26,29 +26,29 @@ private:
|
|||||||
void close(); // Cierra y libera recursos
|
void close(); // Cierra y libera recursos
|
||||||
|
|
||||||
// --- Configuración inicial ---
|
// --- Configuración inicial ---
|
||||||
void loadParams(); // Carga los parámetros del programa
|
static void loadParams(); // Carga los parámetros del programa
|
||||||
void loadScoreFile(); // Carga el fichero de puntuaciones
|
static void loadScoreFile(); // Carga el fichero de puntuaciones
|
||||||
void createSystemFolder(const std::string &folder); // Crea la carpeta del sistema
|
void createSystemFolder(const std::string &folder); // Crea la carpeta del sistema
|
||||||
|
|
||||||
// --- Gestión de entrada y archivos ---
|
// --- 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 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)
|
void checkProgramArguments(int argc, std::span<char*> argv); // Verifica los parámetros del programa // NOLINT(modernize-avoid-c-arrays)
|
||||||
|
|
||||||
// --- Secciones del programa ---
|
// --- Secciones del programa ---
|
||||||
void runLogo(); // Ejecuta la pantalla con el logo
|
static void runLogo(); // Ejecuta la pantalla con el logo
|
||||||
void runIntro(); // Ejecuta la introducción del juego
|
static void runIntro(); // Ejecuta la introducción del juego
|
||||||
void runTitle(); // Ejecuta la pantalla de título
|
static void runTitle(); // Ejecuta la pantalla de título
|
||||||
void runGame(); // Inicia el juego
|
static void runGame(); // Inicia el juego
|
||||||
void runInstructions(); // Muestra las instrucciones
|
static void runInstructions(); // Muestra las instrucciones
|
||||||
void runCredits(); // Muestra los créditos del juego
|
static void runCredits(); // Muestra los créditos del juego
|
||||||
void runHiScoreTable(); // Muestra la tabla de puntuaciones
|
static void runHiScoreTable(); // Muestra la tabla de puntuaciones
|
||||||
void runDemoGame(); // Ejecuta el modo demo
|
static void runDemoGame(); // Ejecuta el modo demo
|
||||||
void reset(); // Reinicia objetos y vuelve a la sección inicial
|
void reset(); // Reinicia objetos y vuelve a la sección inicial
|
||||||
|
|
||||||
// --- Gestión de archivos de idioma ---
|
// --- Gestión de archivos de idioma ---
|
||||||
auto getLangFile(Lang::Code code) -> std::string; // Obtiene un fichero de idioma según el código
|
auto getLangFile(Lang::Code code) -> std::string; // Obtiene un fichero de idioma según el código
|
||||||
|
|
||||||
// --- Apagado del sistema ---
|
// --- Apagado del sistema ---
|
||||||
void shutdownSystem(bool should_shutdown); // Apaga el sistema
|
static void shutdownSystem(bool should_shutdown); // Apaga el sistema
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -78,5 +78,5 @@ private:
|
|||||||
|
|
||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
void init(); // Inicializa las variables
|
void init(); // Inicializa las variables
|
||||||
auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
|
[[nodiscard]] auto getInitialVerticalDesp() const -> int; // Calcula el desplazamiento vertical inicial
|
||||||
};
|
};
|
||||||
@@ -321,7 +321,8 @@ auto Input::checkAxisInput(InputAction input, int controller_index, bool repeat)
|
|||||||
// Transición de inactivo a activo
|
// Transición de inactivo a activo
|
||||||
binding.axis_active = true;
|
binding.axis_active = true;
|
||||||
return true;
|
return true;
|
||||||
} else if (!axis_active_now && binding.axis_active) {
|
}
|
||||||
|
if (!axis_active_now && binding.axis_active) {
|
||||||
// Transición de activo a inactivo
|
// Transición de activo a inactivo
|
||||||
binding.axis_active = false;
|
binding.axis_active = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class Input {
|
|||||||
|
|
||||||
// --- Métodos de gestión de mandos ---
|
// --- Métodos de gestión de mandos ---
|
||||||
auto discoverGameControllers() -> bool; // Busca si hay mandos conectados
|
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 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 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
|
[[nodiscard]] auto getJoyIndex(SDL_JoystickID id) const -> int; // Obtiene el índice del controlador a partir de un event.id
|
||||||
|
|||||||
@@ -185,7 +185,8 @@ auto Item::getCoffeeMachineSpawn(int player_x, int item_width, int area_width, i
|
|||||||
} // Lado derecho
|
} // Lado derecho
|
||||||
return rand() % (RIGHT_BOUND - exclude_right) + exclude_right;
|
return rand() % (RIGHT_BOUND - exclude_right) + exclude_right;
|
||||||
|
|
||||||
} else if (can_spawn_left) {
|
}
|
||||||
|
if (can_spawn_left) {
|
||||||
// Solo lado izquierdo disponible
|
// Solo lado izquierdo disponible
|
||||||
return rand() % (exclude_left - LEFT_BOUND) + LEFT_BOUND;
|
return rand() % (exclude_left - LEFT_BOUND) + LEFT_BOUND;
|
||||||
} else if (can_spawn_right) {
|
} else if (can_spawn_right) {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ struct VideoOptions {
|
|||||||
std::string info; // Información sobre el modo de vídeo
|
std::string info; // Información sobre el modo de vídeo
|
||||||
|
|
||||||
// Constructor por defecto con valores iniciales
|
// Constructor por defecto con valores iniciales
|
||||||
VideoOptions() {}
|
VideoOptions() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Opciones de música ---
|
// --- Opciones de música ---
|
||||||
@@ -79,9 +79,7 @@ struct AudioOptions {
|
|||||||
int volume{100}; // Volumen general del audio
|
int volume{100}; // Volumen general del audio
|
||||||
|
|
||||||
// Constructor por defecto
|
// Constructor por defecto
|
||||||
AudioOptions()
|
AudioOptions() = default;
|
||||||
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Opciones de configuración ---
|
// --- Opciones de configuración ---
|
||||||
@@ -119,7 +117,6 @@ struct GamepadOptions {
|
|||||||
GamepadOptions()
|
GamepadOptions()
|
||||||
: index(INVALID_INDEX),
|
: index(INVALID_INDEX),
|
||||||
player_id(INVALID_INDEX),
|
player_id(INVALID_INDEX),
|
||||||
|
|
||||||
inputs{
|
inputs{
|
||||||
InputAction::FIRE_LEFT,
|
InputAction::FIRE_LEFT,
|
||||||
InputAction::FIRE_CENTER,
|
InputAction::FIRE_CENTER,
|
||||||
|
|||||||
365
source/param.cpp
365
source/param.cpp
@@ -3,9 +3,11 @@
|
|||||||
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogError, SDL_LogInfo
|
#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 <sstream> // Para basic_istringstream
|
||||||
#include <stdexcept> // Para runtime_error
|
#include <stdexcept> // Para runtime_error
|
||||||
#include <string> // Para operator==, stoi, char_traits, string, ope...
|
#include <string> // Para operator==, stoi, char_traits, string, ope...
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "utils.h" // Para Zone, Color, NotifyPosition, getFileName
|
#include "utils.h" // Para Zone, Color, NotifyPosition, getFileName
|
||||||
|
|
||||||
@@ -128,219 +130,97 @@ void loadParamsFromFile(const std::string &file_path) {
|
|||||||
precalculateZones();
|
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 {
|
||||||
// Indicador de éxito en la asignación
|
static const std::unordered_map<std::string, std::function<void(const std::string&)>> intParams = {
|
||||||
auto success = true;
|
{"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
|
static const std::unordered_map<std::string, std::function<void(const std::string&)>> colorParams = {
|
||||||
if (var == "game.width") {
|
{"fade.color", [](const std::string& v) { param.fade.color = Color::fromHex(v); }},
|
||||||
param.game.width = std::stoi(value);
|
{"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") {
|
// Casos especiales que necesitan lógica personalizada
|
||||||
param.game.height = std::stoi(value);
|
if (var == "notification.pos_h") {
|
||||||
}
|
|
||||||
|
|
||||||
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") {
|
|
||||||
if (value == "LEFT") {
|
if (value == "LEFT") {
|
||||||
param.notification.pos_h = NotifyPosition::LEFT;
|
param.notification.pos_h = NotifyPosition::LEFT;
|
||||||
} else if (value == "MIDDLE") {
|
} else if (value == "MIDDLE") {
|
||||||
@@ -348,74 +228,15 @@ auto setParams(const std::string &var, const std::string &value) -> bool {
|
|||||||
} else {
|
} else {
|
||||||
param.notification.pos_h = NotifyPosition::RIGHT;
|
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;
|
param.notification.pos_v = value == "TOP" ? NotifyPosition::TOP : NotifyPosition::BOTTOM;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (var == "notification.sound") {
|
return false; // Parámetro no encontrado
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula variables a partir de otras variables
|
// Calcula variables a partir de otras variables
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ void Resource::load() {
|
|||||||
|
|
||||||
// Muerstra la ventana y desactiva el sincronismo vertical
|
// Muerstra la ventana y desactiva el sincronismo vertical
|
||||||
auto *screen = Screen::get();
|
auto *screen = Screen::get();
|
||||||
auto vsync = screen->getVSync();
|
auto vsync = Screen::getVSync();
|
||||||
screen->setVSync(false);
|
screen->setVSync(false);
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class Screen {
|
|||||||
: enabled(enabled), lenght(lenght), delay(delay), counter(lenght), color(color) {}
|
: enabled(enabled), lenght(lenght), delay(delay), counter(lenght), color(color) {}
|
||||||
|
|
||||||
void update() { (enabled && counter > 0) ? counter-- : static_cast<int>(enabled = false); }
|
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
|
// Efecto de sacudida/agitación de pantalla: mueve la imagen para simular un temblor
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Credits::Credits()
|
|||||||
fade_out_(std::make_unique<Fade>()),
|
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)),
|
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)) {
|
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.");
|
throw std::runtime_error("Failed to create SDL texture for text.");
|
||||||
}
|
}
|
||||||
Section::name = Section::Name::CREDITS;
|
Section::name = Section::Name::CREDITS;
|
||||||
@@ -133,7 +133,7 @@ void Credits::checkInput() {
|
|||||||
|
|
||||||
if (!ServiceMenu::get()->isEnabled()) {
|
if (!ServiceMenu::get()->isEnabled()) {
|
||||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
// 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;
|
want_to_pass_ = true;
|
||||||
fading_ = mini_logo_on_position_;
|
fading_ = mini_logo_on_position_;
|
||||||
} else {
|
} else {
|
||||||
@@ -235,7 +235,7 @@ void Credits::fillTextTexture() {
|
|||||||
// Dibuja todos los sprites en la textura
|
// Dibuja todos los sprites en la textura
|
||||||
void Credits::fillCanvas() {
|
void Credits::fillCanvas() {
|
||||||
// Cambia el destino del renderizador
|
// 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_);
|
SDL_SetRenderTarget(Screen::get()->getRenderer(), canvas_);
|
||||||
|
|
||||||
// Dibuja el fondo, los globos y los jugadores
|
// 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);
|
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1);
|
||||||
|
|
||||||
--current_step_;
|
--current_step_;
|
||||||
setVolume(static_cast<int>(initial_volume_ * current_step_ / steps_));
|
setVolume((initial_volume_ * current_step_ / steps_));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Si los rectangulos superior e inferior han llegado al centro
|
// 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);
|
right_black_rect_.x = std::max(right_black_rect_.x - SPEED, param.game.game_area.center_x);
|
||||||
|
|
||||||
--current_step_;
|
--current_step_;
|
||||||
setVolume(static_cast<int>(initial_volume_ * current_step_ / steps_));
|
setVolume((initial_volume_ * current_step_ / steps_));
|
||||||
} else {
|
} else {
|
||||||
// Si los rectangulos izquierdo y derecho han llegado al centro
|
// Si los rectangulos izquierdo y derecho han llegado al centro
|
||||||
setVolume(0);
|
setVolume(0);
|
||||||
@@ -440,7 +440,7 @@ void Credits::setVolume(int amount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reestablece el nivel de volumen
|
// Reestablece el nivel de volumen
|
||||||
void Credits::resetVolume() {
|
void Credits::resetVolume() const {
|
||||||
Options::audio.music.volume = initial_volume_;
|
Options::audio.music.volume = initial_volume_;
|
||||||
Audio::get()->setMusicVolume(Options::audio.music.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 r_ = static_cast<float>(UPPER_LIMIT);
|
||||||
static auto g_ = static_cast<float>(LOWER_LIMIT);
|
static auto g_ = static_cast<float>(LOWER_LIMIT);
|
||||||
static auto b_ = 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_r_ = -0.5F; // Paso flotante para transiciones suaves
|
||||||
static float step_g_ = 0.3f;
|
static float step_g_ = 0.3F;
|
||||||
static float step_b_ = 0.1f;
|
static float step_b_ = 0.1F;
|
||||||
|
|
||||||
// Ajustar valores de R
|
// Ajustar valores de R
|
||||||
r_ += step_r_;
|
r_ += step_r_;
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class Credits {
|
|||||||
// --- Métodos del bucle principal ---
|
// --- Métodos del bucle principal ---
|
||||||
void update(); // Actualización principal de la lógica
|
void update(); // Actualización principal de la lógica
|
||||||
void render(); // Renderizado de la escena
|
void render(); // Renderizado de la escena
|
||||||
void checkEvents(); // Manejo de eventos
|
static void checkEvents(); // Manejo de eventos
|
||||||
void checkInput(); // Procesamiento de entrada
|
void checkInput(); // Procesamiento de entrada
|
||||||
|
|
||||||
// --- Métodos de renderizado ---
|
// --- Métodos de renderizado ---
|
||||||
@@ -124,6 +124,6 @@ class Credits {
|
|||||||
void updateRedRect(); // Actualizar rectángulo rojo (borde)
|
void updateRedRect(); // Actualizar rectángulo rojo (borde)
|
||||||
|
|
||||||
// --- Métodos de audio ---
|
// --- Métodos de audio ---
|
||||||
void setVolume(int amount); // Establecer volumen
|
static void setVolume(int amount); // Establecer volumen
|
||||||
void resetVolume(); // Restablecer volumen
|
void resetVolume() const; // Restablecer volumen
|
||||||
};
|
};
|
||||||
@@ -90,10 +90,11 @@ Game::Game(int player_id, int current_stage, bool demo)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Si se empieza en una fase que no es la primera
|
// 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) {
|
for (int i = 0; i < Stage::number; ++i) {
|
||||||
Stage::total_power += Stage::get(i).power_to_complete;
|
Stage::total_power += Stage::get(i).power_to_complete;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +185,7 @@ void Game::updateHiScore() {
|
|||||||
hi_score_.name.clear();
|
hi_score_.name.clear();
|
||||||
|
|
||||||
// Si se supera la máxima puntuación emite sonido
|
// Si se supera la máxima puntuación emite sonido
|
||||||
if (hi_score_achieved_ == false) {
|
if (!hi_score_achieved_) {
|
||||||
hi_score_achieved_ = true;
|
hi_score_achieved_ = true;
|
||||||
playSound("hi_score_achieved.wav");
|
playSound("hi_score_achieved.wav");
|
||||||
}
|
}
|
||||||
@@ -299,7 +300,7 @@ void Game::updateGameStateGameOver() {
|
|||||||
|
|
||||||
if (fade_out_->isEnabled()) {
|
if (fade_out_->isEnabled()) {
|
||||||
if (Options::audio.enabled) {
|
if (Options::audio.enabled) {
|
||||||
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0f;
|
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0F;
|
||||||
Audio::get()->setSoundVolume(static_cast<int>(VOL), Audio::Group::GAME);
|
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(4), paths_.at(5)}, Resource::get()->getTexture("game_text_congratulations"));
|
||||||
createMessage({paths_.at(6), paths_.at(7)}, Resource::get()->getTexture("game_text_1000000_points"));
|
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()) {
|
if (player->isPlaying()) {
|
||||||
player->addScore(1000000);
|
player->addScore(1000000);
|
||||||
player->setPlayingState(PlayerState::CELEBRATING);
|
player->setPlayingState(PlayerState::CELEBRATING);
|
||||||
} else {
|
} else {
|
||||||
player->setPlayingState(PlayerState::GAME_OVER);
|
player->setPlayingState(PlayerState::GAME_OVER);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateHiScore();
|
updateHiScore();
|
||||||
}
|
}
|
||||||
@@ -374,7 +376,7 @@ void Game::updateGameStateCompleted() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si los jugadores ya no estan y no quedan mensajes en pantalla
|
// 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);
|
setState(GameState::GAME_OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,9 +397,10 @@ void Game::checkState() {
|
|||||||
|
|
||||||
// Destruye todos los items
|
// Destruye todos los items
|
||||||
void Game::destroyAllItems() {
|
void Game::destroyAllItems() {
|
||||||
for (auto &item : items_)
|
for (auto &item : items_) {
|
||||||
item->disable();
|
item->disable();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los globos activos
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::shared_ptr<Balloon> {
|
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::shared_ptr<Balloon> {
|
||||||
@@ -414,8 +417,9 @@ auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::
|
|||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los items
|
// Comprueba la colisión entre el jugador y los items
|
||||||
void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
|
void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
|
||||||
if (!player->isPlaying())
|
if (!player->isPlaying()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &item : items_) {
|
for (auto &item : items_) {
|
||||||
if (item->isEnabled()) {
|
if (item->isEnabled()) {
|
||||||
@@ -492,7 +496,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
|
|||||||
void Game::checkBulletCollision() {
|
void Game::checkBulletCollision() {
|
||||||
for (auto &bullet : bullets_) {
|
for (auto &bullet : bullets_) {
|
||||||
// Comprueba la colisión con el Tabe
|
// Comprueba la colisión con el Tabe
|
||||||
if (bullet->isEnabled() && tabe_->isEnabled())
|
if (bullet->isEnabled() && tabe_->isEnabled()) {
|
||||||
if (checkCollision(bullet->getCollider(), tabe_->getCollider())) {
|
if (checkCollision(bullet->getCollider(), tabe_->getCollider())) {
|
||||||
tabe_->setState(TabeState::HIT);
|
tabe_->setState(TabeState::HIT);
|
||||||
bullet->disable();
|
bullet->disable();
|
||||||
@@ -508,6 +512,7 @@ void Game::checkBulletCollision() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba la colisión con los globos
|
// Comprueba la colisión con los globos
|
||||||
for (auto &balloon : balloon_manager_->getBalloons()) {
|
for (auto &balloon : balloon_manager_->getBalloons()) {
|
||||||
@@ -559,9 +564,10 @@ void Game::updateBullets() {
|
|||||||
|
|
||||||
// Pinta las balas activas
|
// Pinta las balas activas
|
||||||
void Game::renderBullets() {
|
void Game::renderBullets() {
|
||||||
for (auto &bullet : bullets_)
|
for (auto &bullet : bullets_) {
|
||||||
bullet->render();
|
bullet->render();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Crea un objeto bala
|
// Crea un objeto bala
|
||||||
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner) {
|
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner) {
|
||||||
@@ -570,15 +576,18 @@ void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owne
|
|||||||
|
|
||||||
// Vacia el vector de balas
|
// Vacia el vector de balas
|
||||||
void Game::freeBullets() {
|
void Game::freeBullets() {
|
||||||
if (!bullets_.empty())
|
if (!bullets_.empty()) {
|
||||||
for (int i = bullets_.size() - 1; i >= 0; --i)
|
for (int i = bullets_.size() - 1; i >= 0; --i) {
|
||||||
if (!bullets_[i]->isEnabled())
|
if (!bullets_[i]->isEnabled()) {
|
||||||
bullets_.erase(bullets_.begin() + i);
|
bullets_.erase(bullets_.begin() + i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Actualiza los items
|
// Actualiza los items
|
||||||
void Game::updateItems() {
|
void Game::updateItems() {
|
||||||
for (auto &item : items_)
|
for (auto &item : items_) {
|
||||||
if (item->isEnabled()) {
|
if (item->isEnabled()) {
|
||||||
item->update();
|
item->update();
|
||||||
if (item->isOnFloor()) {
|
if (item->isOnFloor()) {
|
||||||
@@ -587,12 +596,14 @@ void Game::updateItems() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pinta los items activos
|
// Pinta los items activos
|
||||||
void Game::renderItems() {
|
void Game::renderItems() {
|
||||||
for (auto &item : items_)
|
for (auto &item : items_) {
|
||||||
item->render();
|
item->render();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Devuelve un item al azar y luego segun sus probabilidades
|
// Devuelve un item al azar y luego segun sus probabilidades
|
||||||
auto Game::dropItem() -> ItemType {
|
auto Game::dropItem() -> ItemType {
|
||||||
@@ -657,11 +668,14 @@ void Game::createItem(ItemType type, float x, float y) {
|
|||||||
|
|
||||||
// Vacia el vector de items
|
// Vacia el vector de items
|
||||||
void Game::freeItems() {
|
void Game::freeItems() {
|
||||||
if (!items_.empty())
|
if (!items_.empty()) {
|
||||||
for (int i = items_.size() - 1; i >= 0; --i)
|
for (int i = items_.size() - 1; i >= 0; --i) {
|
||||||
if (!items_[i]->isEnabled())
|
if (!items_[i]->isEnabled()) {
|
||||||
items_.erase(items_.begin() + i);
|
items_.erase(items_.begin() + i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Crea un objeto PathSprite
|
// Crea un objeto PathSprite
|
||||||
void Game::createItemText(int x, std::shared_ptr<Texture> texture) {
|
void Game::createItemText(int x, std::shared_ptr<Texture> texture) {
|
||||||
@@ -699,19 +713,25 @@ void Game::createMessage(const std::vector<Path> &paths, std::shared_ptr<Texture
|
|||||||
|
|
||||||
// Vacia el vector de smartsprites
|
// Vacia el vector de smartsprites
|
||||||
void Game::freeSmartSprites() {
|
void Game::freeSmartSprites() {
|
||||||
if (!smart_sprites_.empty())
|
if (!smart_sprites_.empty()) {
|
||||||
for (int i = smart_sprites_.size() - 1; i >= 0; --i)
|
for (int i = smart_sprites_.size() - 1; i >= 0; --i) {
|
||||||
if (smart_sprites_[i]->hasFinished())
|
if (smart_sprites_[i]->hasFinished()) {
|
||||||
smart_sprites_.erase(smart_sprites_.begin() + i);
|
smart_sprites_.erase(smart_sprites_.begin() + i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Vacia el vector de pathsprites
|
// Vacia el vector de pathsprites
|
||||||
void Game::freePathSprites() {
|
void Game::freePathSprites() {
|
||||||
if (!path_sprites_.empty())
|
if (!path_sprites_.empty()) {
|
||||||
for (int i = path_sprites_.size() - 1; i >= 0; --i)
|
for (int i = path_sprites_.size() - 1; i >= 0; --i) {
|
||||||
if (path_sprites_[i]->hasFinished())
|
if (path_sprites_[i]->hasFinished()) {
|
||||||
path_sprites_.erase(path_sprites_.begin() + i);
|
path_sprites_.erase(path_sprites_.begin() + i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
|
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
|
||||||
void Game::throwCoffee(int x, int y) {
|
void Game::throwCoffee(int x, int y) {
|
||||||
@@ -721,10 +741,10 @@ void Game::throwCoffee(int x, int y) {
|
|||||||
smart_sprites_.back()->setPosY(y - 8);
|
smart_sprites_.back()->setPosY(y - 8);
|
||||||
smart_sprites_.back()->setWidth(param.game.item_size);
|
smart_sprites_.back()->setWidth(param.game.item_size);
|
||||||
smart_sprites_.back()->setHeight(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()->setVelX(-1.0F + ((rand() % 5) * 0.5F));
|
||||||
smart_sprites_.back()->setVelY(-4.0f);
|
smart_sprites_.back()->setVelY(-4.0F);
|
||||||
smart_sprites_.back()->setAccelX(0.0f);
|
smart_sprites_.back()->setAccelX(0.0F);
|
||||||
smart_sprites_.back()->setAccelY(0.2f);
|
smart_sprites_.back()->setAccelY(0.2F);
|
||||||
smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50));
|
smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50));
|
||||||
smart_sprites_.back()->setDestY(param.game.height + 1);
|
smart_sprites_.back()->setDestY(param.game.height + 1);
|
||||||
smart_sprites_.back()->setEnabled(true);
|
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
|
// 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_INITIAL_SPEED = 0.05F;
|
||||||
constexpr float CLOUDS_FINAL_SPEED = 2.00f - CLOUDS_INITIAL_SPEED;
|
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_));
|
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);
|
background_->setCloudsSpeed(CLOUDS_SPEED);
|
||||||
|
|
||||||
// Calcula la transición de los diferentes fondos
|
// Calcula la transición de los diferentes fondos
|
||||||
constexpr float NUM = 1525.0f; // total_power_to_complete div 4
|
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 GRADIENT_NUMBER = std::min(Stage::total_power / NUM, 3.0F);
|
||||||
const float PERCENT = GRADIENT_NUMBER - static_cast<int>(GRADIENT_NUMBER);
|
const float PERCENT = GRADIENT_NUMBER - static_cast<int>(GRADIENT_NUMBER);
|
||||||
background_->setGradientNumber(static_cast<int>(GRADIENT_NUMBER));
|
background_->setGradientNumber(static_cast<int>(GRADIENT_NUMBER));
|
||||||
background_->setTransition(PERCENT);
|
background_->setTransition(PERCENT);
|
||||||
@@ -889,7 +909,7 @@ void Game::updateBackground() {
|
|||||||
// Dibuja los elementos de la zona de juego en su textura
|
// Dibuja los elementos de la zona de juego en su textura
|
||||||
void Game::fillCanvas() {
|
void Game::fillCanvas() {
|
||||||
// Dibujamos el contenido de la zona de juego en su textura
|
// 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_);
|
SDL_SetRenderTarget(renderer_, canvas_);
|
||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
@@ -1024,8 +1044,9 @@ void Game::updateHelper() {
|
|||||||
// Comprueba si todos los jugadores han terminado de jugar
|
// Comprueba si todos los jugadores han terminado de jugar
|
||||||
auto Game::allPlayersAreWaitingOrGameOver() -> bool {
|
auto Game::allPlayersAreWaitingOrGameOver() -> bool {
|
||||||
auto success = true;
|
auto success = true;
|
||||||
for (const auto &player : players_)
|
for (const auto &player : players_) {
|
||||||
success &= player->isWaiting() || player->isGameOver();
|
success &= player->isWaiting() || player->isGameOver();
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -1033,8 +1054,9 @@ auto Game::allPlayersAreWaitingOrGameOver() -> bool {
|
|||||||
// Comprueba si todos los jugadores han terminado de jugar
|
// Comprueba si todos los jugadores han terminado de jugar
|
||||||
auto Game::allPlayersAreGameOver() -> bool {
|
auto Game::allPlayersAreGameOver() -> bool {
|
||||||
auto success = true;
|
auto success = true;
|
||||||
for (const auto &player : players_)
|
for (const auto &player : players_) {
|
||||||
success &= player->isGameOver();
|
success &= player->isGameOver();
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -1042,8 +1064,9 @@ auto Game::allPlayersAreGameOver() -> bool {
|
|||||||
// Comprueba si todos los jugadores han terminado de jugar
|
// Comprueba si todos los jugadores han terminado de jugar
|
||||||
auto Game::allPlayersAreNotPlaying() -> bool {
|
auto Game::allPlayersAreNotPlaying() -> bool {
|
||||||
auto success = true;
|
auto success = true;
|
||||||
for (const auto &player : players_)
|
for (const auto &player : players_) {
|
||||||
success &= !player->isPlaying();
|
success &= !player->isPlaying();
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -1190,7 +1213,7 @@ void Game::checkPauseInput() {
|
|||||||
|
|
||||||
// Gestiona las entradas de los jugadores en el modo demo para saltarse la demo.
|
// Gestiona las entradas de los jugadores en el modo demo para saltarse la demo.
|
||||||
void Game::demoHandlePassInput() {
|
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::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
|
Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO; // El juego volverá a mostrar la demo
|
||||||
return;
|
return;
|
||||||
@@ -1423,8 +1446,9 @@ void Game::initDemo(int player_id) {
|
|||||||
|
|
||||||
// Asigna cafes a los jugadores
|
// Asigna cafes a los jugadores
|
||||||
for (auto &player : players_) {
|
for (auto &player : players_) {
|
||||||
for (int i = 0; i < rand() % 3; ++i)
|
for (int i = 0; i < rand() % 3; ++i) {
|
||||||
player->giveExtraHit();
|
player->giveExtraHit();
|
||||||
|
}
|
||||||
|
|
||||||
player->setInvulnerable(true);
|
player->setInvulnerable(true);
|
||||||
}
|
}
|
||||||
@@ -1472,21 +1496,21 @@ void Game::initDifficultyVars() {
|
|||||||
switch (difficulty_) {
|
switch (difficulty_) {
|
||||||
case Options::DifficultyCode::EASY: {
|
case Options::DifficultyCode::EASY: {
|
||||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
||||||
difficulty_score_multiplier_ = 0.5f;
|
difficulty_score_multiplier_ = 0.5F;
|
||||||
scoreboard_->setColor(param.scoreboard.easy_color);
|
scoreboard_->setColor(param.scoreboard.easy_color);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Options::DifficultyCode::NORMAL: {
|
case Options::DifficultyCode::NORMAL: {
|
||||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
||||||
difficulty_score_multiplier_ = 1.0f;
|
difficulty_score_multiplier_ = 1.0F;
|
||||||
scoreboard_->setColor(param.scoreboard.normal_color);
|
scoreboard_->setColor(param.scoreboard.normal_color);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Options::DifficultyCode::HARD: {
|
case Options::DifficultyCode::HARD: {
|
||||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[4]);
|
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[4]);
|
||||||
difficulty_score_multiplier_ = 1.5f;
|
difficulty_score_multiplier_ = 1.5F;
|
||||||
scoreboard_->setColor(param.scoreboard.hard_color);
|
scoreboard_->setColor(param.scoreboard.hard_color);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1530,7 +1554,7 @@ void Game::playMusic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Detiene la música
|
// Detiene la música
|
||||||
void Game::stopMusic() {
|
void Game::stopMusic() const {
|
||||||
if (!demo_.enabled) {
|
if (!demo_.enabled) {
|
||||||
Audio::get()->stopMusic();
|
Audio::get()->stopMusic();
|
||||||
}
|
}
|
||||||
@@ -1539,7 +1563,7 @@ void Game::stopMusic() {
|
|||||||
// Actualiza las variables durante el modo demo
|
// Actualiza las variables durante el modo demo
|
||||||
void Game::updateDemo() {
|
void Game::updateDemo() {
|
||||||
if (demo_.enabled) {
|
if (demo_.enabled) {
|
||||||
balloon_manager_->setCreationTimeEnabled((balloon_manager_->getNumBalloons() == 0) ? false : true);
|
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
|
||||||
|
|
||||||
// Actualiza ambos fades
|
// Actualiza ambos fades
|
||||||
fade_in_->update();
|
fade_in_->update();
|
||||||
@@ -1618,7 +1642,7 @@ void Game::updateGameStateShowingGetReadyMessage() {
|
|||||||
updateScoreboard();
|
updateScoreboard();
|
||||||
updateBackground();
|
updateBackground();
|
||||||
freePathSprites();
|
freePathSprites();
|
||||||
if (path_sprites_.size() == 0) {
|
if (path_sprites_.empty()) {
|
||||||
setState(GameState::PLAYING);
|
setState(GameState::PLAYING);
|
||||||
}
|
}
|
||||||
if (counter_ == 100) {
|
if (counter_ == 100) {
|
||||||
@@ -1692,11 +1716,12 @@ void Game::evaluateAndSetMenace() {
|
|||||||
|
|
||||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||||
void Game::checkAndUpdateBalloonSpeed() {
|
void Game::checkAndUpdateBalloonSpeed() {
|
||||||
if (difficulty_ != Options::DifficultyCode::NORMAL)
|
if (difficulty_ != Options::DifficultyCode::NORMAL) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
|
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) {
|
for (size_t i = 0; i < std::size(THRESHOLDS); ++i) {
|
||||||
if (balloon_manager_->getBalloonSpeed() == BALLOON_SPEED[i] && PERCENT > THRESHOLDS[i]) {
|
if (balloon_manager_->getBalloonSpeed() == BALLOON_SPEED[i] && PERCENT > THRESHOLDS[i]) {
|
||||||
@@ -1712,18 +1737,20 @@ void Game::setState(GameState state) {
|
|||||||
counter_ = 0;
|
counter_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::playSound(const std::string &name) {
|
void Game::playSound(const std::string &name) const {
|
||||||
if (demo_.enabled)
|
if (demo_.enabled) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static auto audio_ = Audio::get();
|
static auto *audio_ = Audio::get();
|
||||||
audio_->playSound(name);
|
audio_->playSound(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Organiza los jugadores para que los vivos se pinten sobre los muertos
|
// Organiza los jugadores para que los vivos se pinten sobre los muertos
|
||||||
void Game::movePlayersToFront() {
|
void Game::movePlayersToFront() {
|
||||||
if (players_to_reorder_.empty())
|
if (players_to_reorder_.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &player : players_to_reorder_) {
|
for (auto &player : players_to_reorder_) {
|
||||||
auto it = std::find(players_.begin(), players_.end(), player);
|
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
|
// Comprueba si está activo el menu de servicio para poner el juego en pausa
|
||||||
void Game::checkServiceMenu() {
|
void Game::checkServiceMenu() {
|
||||||
if (demo_.enabled)
|
if (demo_.enabled) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static bool was_paused_before_service_menu_ = false;
|
static bool was_paused_before_service_menu_ = false;
|
||||||
static bool service_menu_was_active_ = false;
|
static bool service_menu_was_active_ = false;
|
||||||
@@ -1761,7 +1789,7 @@ void Game::checkServiceMenu() {
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Comprueba los eventos en el modo DEBUG
|
// Comprueba los eventos en el modo DEBUG
|
||||||
void Game::checkDebugEvents(const SDL_Event &event) {
|
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) {
|
switch (event.key.key) {
|
||||||
case SDLK_1: // Crea una powerball
|
case SDLK_1: // Crea una powerball
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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 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
|
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 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 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 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.
|
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 initScoreboard(); // Inicializa el marcador
|
||||||
void initDifficultyVars(); // Inicializa las opciones relacionadas con la dificultad
|
void initDifficultyVars(); // Inicializa las opciones relacionadas con la dificultad
|
||||||
void initPlayers(int player_id); // Inicializa los jugadores
|
void initPlayers(int player_id); // Inicializa los jugadores
|
||||||
void playMusic(); // Hace sonar la música
|
static void playMusic(); // Hace sonar la música
|
||||||
void stopMusic(); // Detiene la música
|
void stopMusic() const; // Detiene la música
|
||||||
void playSound(const std::string &name); // Hace sonar un sonido
|
void playSound(const std::string &name) const; // Hace sonar un sonido
|
||||||
void updateDemo(); // Actualiza las variables durante el modo demo
|
void updateDemo(); // Actualiza las variables durante el modo demo
|
||||||
void updateGameStateFadeIn(); // Actualiza las variables durante dicho estado
|
void updateGameStateFadeIn(); // Actualiza las variables durante dicho estado
|
||||||
void updateGameStateEnteringPlayer(); // Actualiza las variables durante dicho estado
|
void updateGameStateEnteringPlayer(); // Actualiza las variables durante dicho estado
|
||||||
|
|||||||
@@ -108,55 +108,67 @@ void Title::checkEvents() {
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
#ifdef DEBUG
|
#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;
|
static Color color_ = param.title.bg_color;
|
||||||
switch (event.key.key) {
|
switch (event.key.key) {
|
||||||
case SDLK_A:
|
case SDLK_A:
|
||||||
if (color_.r < 255)
|
if (color_.r < 255) {
|
||||||
++color_.r;
|
++color_.r;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_Z:
|
case SDLK_Z:
|
||||||
if (color_.r > 0)
|
if (color_.r > 0) {
|
||||||
--color_.r;
|
--color_.r;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_S:
|
case SDLK_S:
|
||||||
if (color_.g < 255)
|
if (color_.g < 255) {
|
||||||
++color_.g;
|
++color_.g;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_X:
|
case SDLK_X:
|
||||||
if (color_.g > 0)
|
if (color_.g > 0) {
|
||||||
--color_.g;
|
--color_.g;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_D:
|
case SDLK_D:
|
||||||
if (color_.b < 255)
|
if (color_.b < 255) {
|
||||||
++color_.b;
|
++color_.b;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_C:
|
case SDLK_C:
|
||||||
if (color_.b > 0)
|
if (color_.b > 0) {
|
||||||
--color_.b;
|
--color_.b;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_F:
|
case SDLK_F:
|
||||||
if (color_.r < 255)
|
if (color_.r < 255) {
|
||||||
++color_.r;
|
++color_.r;
|
||||||
if (color_.g < 255)
|
}
|
||||||
|
if (color_.g < 255) {
|
||||||
++color_.g;
|
++color_.g;
|
||||||
if (color_.b < 255)
|
}
|
||||||
|
if (color_.b < 255) {
|
||||||
++color_.b;
|
++color_.b;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_V:
|
case SDLK_V:
|
||||||
if (color_.r > 0)
|
if (color_.r > 0) {
|
||||||
--color_.r;
|
--color_.r;
|
||||||
if (color_.g > 0)
|
}
|
||||||
|
if (color_.g > 0) {
|
||||||
--color_.g;
|
--color_.g;
|
||||||
if (color_.b > 0)
|
}
|
||||||
|
if (color_.b > 0) {
|
||||||
--color_.b;
|
--color_.b;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -171,7 +183,7 @@ void Title::checkEvents() {
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
#endif
|
#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) {
|
switch (event.key.key) {
|
||||||
case SDLK_1: // Redefine los botones del mando #0
|
case SDLK_1: // Redefine los botones del mando #0
|
||||||
define_buttons_->enable(0);
|
define_buttons_->enable(0);
|
||||||
@@ -211,8 +223,9 @@ void Title::checkEvents() {
|
|||||||
// Comprueba las entradas
|
// Comprueba las entradas
|
||||||
void Title::checkInput() {
|
void Title::checkInput() {
|
||||||
// Comprueba las entradas solo si no se estan definiendo los botones
|
// Comprueba las entradas solo si no se estan definiendo los botones
|
||||||
if (define_buttons_->isEnabled())
|
if (define_buttons_->isEnabled()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Input::get()->update();
|
Input::get()->update();
|
||||||
|
|
||||||
@@ -263,8 +276,9 @@ void Title::resetCounter() { counter_ = 0; }
|
|||||||
|
|
||||||
// Intercambia la asignación de mandos a los jugadores
|
// Intercambia la asignación de mandos a los jugadores
|
||||||
void Title::swapControllers() {
|
void Title::swapControllers() {
|
||||||
if (Input::get()->getNumControllers() == 0)
|
if (Input::get()->getNumControllers() == 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Options::swapControllers();
|
Options::swapControllers();
|
||||||
showControllers();
|
showControllers();
|
||||||
@@ -443,8 +457,9 @@ void Title::renderCopyright() {
|
|||||||
|
|
||||||
// Cambia el estado
|
// Cambia el estado
|
||||||
void Title::setState(TitleState state) {
|
void Title::setState(TitleState state) {
|
||||||
if (state_ == state)
|
if (state_ == state) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
state_ = state;
|
state_ = state;
|
||||||
switch (state_) {
|
switch (state_) {
|
||||||
|
|||||||
@@ -83,8 +83,8 @@ class Title {
|
|||||||
void checkInput(); // Comprueba las entradas
|
void checkInput(); // Comprueba las entradas
|
||||||
void resetCounter(); // Reinicia el contador interno
|
void resetCounter(); // Reinicia el contador interno
|
||||||
void swapControllers(); // Intercambia la asignación de mandos a los jugadores
|
void swapControllers(); // Intercambia la asignación de mandos a los jugadores
|
||||||
void swapKeyboard(); // Intercambia el teclado de jugador
|
static void swapKeyboard(); // Intercambia el teclado de jugador
|
||||||
void showControllers(); // Muestra información sobre los controles y los jugadores
|
static void showControllers(); // Muestra información sobre los controles y los jugadores
|
||||||
void updateFade(); // Actualiza el efecto de fundido (fade in/out)
|
void updateFade(); // Actualiza el efecto de fundido (fade in/out)
|
||||||
void updateState(); // Actualiza el estado actual del título
|
void updateState(); // Actualiza el estado actual del título
|
||||||
void updateStartPrompt(); // Actualiza el mensaje de "Pulsa Start"
|
void updateStartPrompt(); // Actualiza el mensaje de "Pulsa Start"
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class MenuRenderer {
|
|||||||
void updateResizeAnimation();
|
void updateResizeAnimation();
|
||||||
void precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>> &all_options, const ServiceMenu *menu_state);
|
void precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>> &all_options, const ServiceMenu *menu_state);
|
||||||
[[nodiscard]] auto getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const -> int;
|
[[nodiscard]] auto getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const -> int;
|
||||||
auto getAnimatedSelectedColor() const -> Color;
|
[[nodiscard]] auto getAnimatedSelectedColor() const -> Color;
|
||||||
void updateColorCounter();
|
void updateColorCounter();
|
||||||
auto setRect(SDL_FRect rect) -> SDL_FRect;
|
auto setRect(SDL_FRect rect) -> SDL_FRect;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user