afegit defaults.h amb els valors per defecte de Param

This commit is contained in:
2025-08-16 10:29:30 +02:00
parent 0c10898bdc
commit 81d486f2d3
6 changed files with 316 additions and 231 deletions

View File

@@ -5,141 +5,167 @@
#include <array> // Para array
#include <string> // Para basic_string, string
#include "color.h" // Para Color, NotifyPosition (ptr only), Zone
#include "utils.h"
#include "color.h" // Para Color
#include "defaults.h" // Para los valores por defecto
#include "utils.h" // Para NotifyPosition, Zone
// --- Parámetros del juego ---
struct ParamGame {
float width; // Ancho de la resolución nativa del juego
float height; // Alto de la resolución nativa del juego
float item_size; // Tamaño de los ítems del juego
Zone play_area; // Rectángulo con la posición de la zona de juego
Zone game_area; // Rectángulo con las dimensiones del juego
int name_entry_idle_time; // Segundos para introducir el nombre al finalizar la partida si no se pulsa nada
int name_entry_total_time; // Segundos totales para introducir el nombre al finalizar la partida
Uint32 speed; // Velocidad a la que transcurre el juego
bool hit_stop; // Indica si debe haber un paro cuando el jugador es golpeado por un globo
Uint32 hit_stop_ms; // Cantidad de milisegundos que dura el hit_stop
float width = GameDefaults::Game::WIDTH;
float height = GameDefaults::Game::HEIGHT;
float item_size = GameDefaults::Game::ITEM_SIZE;
Zone play_area{}; // Se inicializa en el constructor de Param
Zone game_area{}; // Se inicializa en el constructor de Param
int name_entry_idle_time = GameDefaults::Game::NAME_ENTRY_IDLE_TIME;
int name_entry_total_time = GameDefaults::Game::NAME_ENTRY_TOTAL_TIME;
Uint32 speed = 15; // Este valor no estaba en el archivo de configuración
bool hit_stop = GameDefaults::Game::HIT_STOP;
Uint32 hit_stop_ms = GameDefaults::Game::HIT_STOP_MS;
};
// --- Parámetros del fade ---
struct ParamFade {
Color color; // Color del fade
float num_squares_width; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE
float num_squares_height; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE
int random_squares_delay; // Duración entre cada pintado de cuadrados
int random_squares_mult; // Cantidad de cuadrados que se pintarán cada vez
int post_duration; // Duración final del fade
float venetian_size; // Altura de los rectángulos para FadeType::VENETIAN
Color color = Color::fromHex(GameDefaults::Fade::COLOR);
float num_squares_width = GameDefaults::Fade::NUM_SQUARES_WIDTH;
float num_squares_height = GameDefaults::Fade::NUM_SQUARES_HEIGHT;
int random_squares_delay = GameDefaults::Fade::RANDOM_SQUARES_DELAY;
int random_squares_mult = GameDefaults::Fade::RANDOM_SQUARES_MULT;
int post_duration = GameDefaults::Fade::POST_DURATION;
float venetian_size = GameDefaults::Fade::VENETIAN_SIZE;
};
// --- Parámetros de la pantalla de título ---
struct ParamTitle {
int press_start_position; // Posición del texto para empezar a jugar
int title_duration; // Tiempo de inactividad del título
int arcade_edition_position; // Posición del bitmap "Arcade Edition"
int title_c_c_position; // Posición del bitmap "Coffee Crisis"
Color bg_color; // Color para los tiles de fondo
int press_start_position = GameDefaults::Title::PRESS_START_POSITION;
int title_duration = GameDefaults::Title::DURATION;
int arcade_edition_position = GameDefaults::Title::ARCADE_EDITION_POSITION;
int title_c_c_position = GameDefaults::Title::TITLE_C_C_POSITION;
Color bg_color = Color::fromHex(GameDefaults::Title::BG_COLOR);
};
// --- Parámetros del fondo ---
struct ParamBackground {
Color attenuate_color; // Color para atenuar el fondo
Color attenuate_color = Color::fromHex(GameDefaults::Background::ATTENUATE_COLOR);
};
// --- Parámetros de los globos ---
struct ParamBalloon {
struct Settings {
float grav; // Aceleración en el eje Y. Modifica la velocidad
float vel; // Velocidad inicial al rebotar contra el suelo
float grav;
float vel;
// Constructor
explicit Settings(float grav_val = 0.0F, float vel_val = 0.0F)
// Constructor por defecto
constexpr Settings(float grav_val = 0.0f, float vel_val = 0.0f)
: grav(grav_val), vel(vel_val) {}
};
std::array<Settings, 4> settings;
std::array<std::string, 4> color;
bool bouncing_sound; // Indica si los globos hacer sonido al rebotar
// Inicialización con los valores por defecto desde GameDefaults
std::array<Settings, 4> settings = {{Settings(GameDefaults::Balloon::SETTINGS[0].grav, GameDefaults::Balloon::SETTINGS[0].vel),
Settings(GameDefaults::Balloon::SETTINGS[1].grav, GameDefaults::Balloon::SETTINGS[1].vel),
Settings(GameDefaults::Balloon::SETTINGS[2].grav, GameDefaults::Balloon::SETTINGS[2].vel),
Settings(GameDefaults::Balloon::SETTINGS[3].grav, GameDefaults::Balloon::SETTINGS[3].vel)}};
std::array<std::string, 4> color = {{GameDefaults::Balloon::COLORS[0],
GameDefaults::Balloon::COLORS[1],
GameDefaults::Balloon::COLORS[2],
GameDefaults::Balloon::COLORS[3]}};
bool bouncing_sound = GameDefaults::Balloon::BOUNCING_SOUND;
};
// --- Parámetros de las notificaciones ---
struct ParamNotification {
NotifyPosition pos_h; // Ubicación horizontal de las notificaciones en pantalla
NotifyPosition pos_v; // Ubicación vertical de las notificaciones en pantalla
bool sound; // Indica si las notificaciones suenan
Color color; // Color de las notificaciones
Notifier::Position pos_h = GameDefaults::Notification::POS_H;
Notifier::Position pos_v = GameDefaults::Notification::POS_V;
bool sound = GameDefaults::Notification::SOUND;
Color color = Color::fromHex(GameDefaults::Notification::COLOR);
};
// --- Parámetros del marcador ---
struct ParamScoreboard {
SDL_FRect rect; // Posición y tamaño del marcador
bool separator_autocolor; // El separado establece su color de forma automatica
Color separator_color; // Color del separador si se pone de forma manual
Color easy_color; // Color del marcador segun la dificultad
Color normal_color; // Color del marcador segun la dificultad
Color hard_color; // Color del marcador segun la dificultad
bool text_autocolor; // El texto establece su color de forma automatica
Color text_color1; // Color del texto
Color text_color2; // Color del texto
int skip_countdown_value; // Valor a partir del cual se puede saltar la cuenta atras
SDL_FRect rect = {
GameDefaults::Scoreboard::RECT_X,
GameDefaults::Scoreboard::RECT_Y,
GameDefaults::Scoreboard::RECT_W,
GameDefaults::Scoreboard::RECT_H};
bool separator_autocolor = GameDefaults::Scoreboard::SEPARATOR_AUTOCOLOR;
Color separator_color = Color::fromHex(GameDefaults::Scoreboard::SEPARATOR_COLOR);
Color easy_color = Color::fromHex(GameDefaults::Scoreboard::EASY_COLOR);
Color normal_color = Color::fromHex(GameDefaults::Scoreboard::NORMAL_COLOR);
Color hard_color = Color::fromHex(GameDefaults::Scoreboard::HARD_COLOR);
bool text_autocolor = GameDefaults::Scoreboard::TEXT_AUTOCOLOR;
Color text_color1 = Color::fromHex(GameDefaults::Scoreboard::TEXT_COLOR1);
Color text_color2 = Color::fromHex(GameDefaults::Scoreboard::TEXT_COLOR2);
int skip_countdown_value = GameDefaults::Scoreboard::SKIP_COUNTDOWN_VALUE;
};
// --- Parámetros del menú de servicio ---
struct ParamServiceMenu {
Color title_color;
Color text_color;
Color selected_color;
Color bg_color;
bool drop_shadow;
Color title_color = Color::fromHex(GameDefaults::ServiceMenu::TITLE_COLOR);
Color text_color = Color::fromHex(GameDefaults::ServiceMenu::TEXT_COLOR);
Color selected_color = Color::fromHex(GameDefaults::ServiceMenu::SELECTED_COLOR);
Color bg_color = Color::fromHex(GameDefaults::ServiceMenu::BG_COLOR);
bool drop_shadow = GameDefaults::ServiceMenu::DROP_SHADOW;
};
// --- Parámetros de la intro ---
struct ParamIntro {
Color bg_color;
Color card_color;
Color shadow_color;
int text_distance_from_bottom;
Color bg_color = Color::fromHex(GameDefaults::Intro::BG_COLOR);
Color card_color = Color::fromHex(GameDefaults::Intro::CARD_COLOR);
Color shadow_color = Color::fromHex(GameDefaults::Intro::SHADOW_COLOR);
int text_distance_from_bottom = GameDefaults::Intro::TEXT_DISTANCE_FROM_BOTTOM;
};
// --- Parámetros para Debug ---
struct ParamDebug {
Color color;
Color color = Color::fromHex(GameDefaults::Debug::COLOR);
};
// --- Parámetros para Resource ---
struct ParamResource {
Color color;
Color color = Color::fromHex(GameDefaults::Resource::COLOR);
};
// --- Parámetros para Tabe ---
struct ParamTabe {
float min_spawn_time;
float max_spawn_time;
float min_spawn_time = GameDefaults::Tabe::MIN_SPAWN_TIME;
float max_spawn_time = GameDefaults::Tabe::MAX_SPAWN_TIME;
};
// --- Estructura principal para almacenar todos los parámetros del juego ---
struct Param {
ParamGame game; // Parámetros del juego
ParamFade fade; // Parámetros del fade
ParamScoreboard scoreboard; // Rectángulo del marcador
ParamTitle title; // Parámetros de la pantalla de título
ParamBackground background; // Parámetros del fondo
ParamBalloon balloon; // Parámetros de los globos
ParamNotification notification; // Parámetros de las notificaciones
ParamServiceMenu service_menu; // Parámetros del menú de servicio
ParamIntro intro; // Parámetros de la intro
ParamDebug debug; // Parámetros para Debug
ParamResource resource; // Parámetros para Resource
ParamTabe tabe; // Parametros para Tabe
ParamGame game;
ParamFade fade;
ParamScoreboard scoreboard;
ParamTitle title;
ParamBackground background;
ParamBalloon balloon;
ParamNotification notification;
ParamServiceMenu service_menu;
ParamIntro intro;
ParamDebug debug;
ParamResource resource;
ParamTabe tabe;
// Constructor
Param()
: game(), fade(), scoreboard(), title(), background(), balloon(), notification(), service_menu(), intro(), debug(), resource() {}
// Constructor que inicializa las zonas que dependen de otros valores
Param() {
// Inicializar play_area usando los valores por defecto
game.play_area.rect = {
GameDefaults::Game::PLAY_AREA_X,
GameDefaults::Game::PLAY_AREA_Y,
GameDefaults::Game::PLAY_AREA_W,
GameDefaults::Game::PLAY_AREA_H};
// Las zonas calculadas se inicializarán en precalculateZones()
precalculateZones();
}
// Función pública para recalcular zonas (necesaria después de cambiar parámetros)
void precalculateZones();
};
// --- Variable global con los parámetros del juego ---
extern Param param;
// --- Funciones globales ---
void loadParamsFromFile(const std::string &file_path); // Establece valores para los parámetros a partir de un fichero de texto
void loadParamsFromFile(const std::string& file_path);