diff --git a/source/balloon_formations.cpp b/source/balloon_formations.cpp index 76d3703..55fefac 100644 --- a/source/balloon_formations.cpp +++ b/source/balloon_formations.cpp @@ -9,23 +9,23 @@ #include #include -void BalloonFormations::initBalloonFormations() { +void BalloonFormations::initFormations() { // Calcular posiciones base const int DEFAULT_POS_Y = param.game.play_area.rect.h - BALLOON_SPAWN_HEIGHT; const int X4_0 = param.game.play_area.rect.x; - const int X4_100 = param.game.play_area.rect.w - BALLOON_SIZE[3]; + const int X4_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(3); const int X3_0 = param.game.play_area.rect.x; - const int X3_100 = param.game.play_area.rect.w - BALLOON_SIZE[2]; + const int X3_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(2); const int X2_0 = param.game.play_area.rect.x; - const int X2_100 = param.game.play_area.rect.w - BALLOON_SIZE[1]; + const int X2_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(1); const int X1_0 = param.game.play_area.rect.x; - const int X1_50 = param.game.play_area.center_x - (BALLOON_SIZE[0] / 2); - const int X1_100 = param.game.play_area.rect.w - BALLOON_SIZE[0]; + const int X1_50 = param.game.play_area.center_x - (BALLOON_SIZE.at(0) / 2); + const int X1_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(0); // Variables calculadas para posiciones especiales - const int QUARTER1_X4 = param.game.play_area.first_quarter_x - (BALLOON_SIZE[3] / 2); - const int QUARTER3_X4 = param.game.play_area.third_quarter_x - (BALLOON_SIZE[3] / 2); + const int QUARTER1_X4 = param.game.play_area.first_quarter_x - (BALLOON_SIZE.at(3) / 2); + const int QUARTER3_X4 = param.game.play_area.third_quarter_x - (BALLOON_SIZE.at(3) / 2); // Mapa de variables para reemplazar en el archivo std::map variables = { @@ -41,10 +41,10 @@ void BalloonFormations::initBalloonFormations() { {"QUARTER1_X4", QUARTER1_X4}, {"QUARTER3_X4", QUARTER3_X4}, {"DEFAULT_POS_Y", DEFAULT_POS_Y}, - {"BALLOON_SIZE_0", BALLOON_SIZE[0]}, - {"BALLOON_SIZE_1", BALLOON_SIZE[1]}, - {"BALLOON_SIZE_2", BALLOON_SIZE[2]}, - {"BALLOON_SIZE_3", BALLOON_SIZE[3]}, + {"BALLOON_SIZE_0", BALLOON_SIZE.at(0)}, + {"BALLOON_SIZE_1", BALLOON_SIZE.at(1)}, + {"BALLOON_SIZE_2", BALLOON_SIZE.at(2)}, + {"BALLOON_SIZE_3", BALLOON_SIZE.at(3)}, {"RIGHT", BALLOON_VELX_POSITIVE}, {"LEFT", BALLOON_VELX_NEGATIVE}}; @@ -71,7 +71,7 @@ auto BalloonFormations::loadFormationsFromFile(const std::string& filename, cons line = trim(line); // Saltar líneas vacías y comentarios - if (line.empty() || line[0] == '#') { + if (line.empty() || line.at(0) == '#') { continue; } @@ -127,31 +127,31 @@ auto BalloonFormations::parseBalloonLine(const std::string& line, const std::map } try { - int x = evaluateExpression(tokens[0], variables); - int desp = evaluateExpression(tokens[1], variables); - int y = evaluateExpression(tokens[2], variables); - float vel_x = evaluateExpression(tokens[3], variables); + int x = evaluateExpression(tokens.at(0), variables); + int desp = evaluateExpression(tokens.at(1), variables); + int y = evaluateExpression(tokens.at(2), variables); + float vel_x = evaluateExpression(tokens.at(3), variables); - BalloonType type = (tokens[4] == "BALLOON") ? BalloonType::BALLOON : BalloonType::FLOATER; + BalloonType type = (tokens.at(4) == "BALLOON") ? BalloonType::BALLOON : BalloonType::FLOATER; BalloonSize size; - if (tokens[5] == "SIZE1") { + if (tokens.at(5) == "SIZE1") { size = BalloonSize::SIZE1; - desp = desp * (BALLOON_SIZE[0] + 1); - } else if (tokens[5] == "SIZE2") { + desp = desp * (BALLOON_SIZE.at(0) + 1); + } else if (tokens.at(5) == "SIZE2") { size = BalloonSize::SIZE2; - desp = desp * (BALLOON_SIZE[1] + 1); - } else if (tokens[5] == "SIZE3") { + desp = desp * (BALLOON_SIZE.at(1) + 1); + } else if (tokens.at(5) == "SIZE3") { size = BalloonSize::SIZE3; - desp = desp * (BALLOON_SIZE[2] + 1); - } else if (tokens[5] == "SIZE4") { + desp = desp * (BALLOON_SIZE.at(2) + 1); + } else if (tokens.at(5) == "SIZE4") { size = BalloonSize::SIZE4; - desp = desp * (BALLOON_SIZE[3] + 1); + desp = desp * (BALLOON_SIZE.at(3) + 1); } else { return std::nullopt; } - int creation_time = CREATION_TIME + evaluateExpression(tokens[6], variables); + int creation_time = CREATION_TIME + evaluateExpression(tokens.at(6), variables); return BalloonFormationParams(x + desp, y, vel_x, type, size, creation_time); } catch (const std::exception&) { @@ -163,7 +163,7 @@ auto BalloonFormations::evaluateExpression(const std::string& expr, const std::m std::string trimmed_expr = trim(expr); // Si es un número directo - if ((std::isdigit(trimmed_expr[0]) != 0) || (trimmed_expr[0] == '-' && trimmed_expr.length() > 1)) { + if ((std::isdigit(trimmed_expr.at(0)) != 0) || (trimmed_expr.at(0) == '-' && trimmed_expr.length() > 1)) { return std::stoi(trimmed_expr); } @@ -179,7 +179,7 @@ auto BalloonFormations::evaluateExpression(const std::string& expr, const std::m auto BalloonFormations::evaluateSimpleExpression(const std::string& expr, const std::map& variables) -> float { // Buscar operadores (+, -, *, /) for (size_t i = 1; i < expr.length(); ++i) { - char op = expr[i]; + char op = expr.at(i); if (op == '+' || op == '-' || op == '*' || op == '/') { std::string left = trim(expr.substr(0, i)); std::string right = trim(expr.substr(i + 1)); @@ -219,16 +219,16 @@ void BalloonFormations::createFloaterVariants() { // Crear variantes flotantes de las primeras 50 formaciones for (size_t k = 0; k < 50 && k < balloon_formation_.size(); k++) { std::vector floater_params; - floater_params.reserve(balloon_formation_[k].number_of_balloons); + floater_params.reserve(balloon_formation_.at(k).number_of_balloons); - for (int i = 0; i < balloon_formation_[k].number_of_balloons; i++) { - const auto& original = balloon_formation_[k].init[i]; + for (int i = 0; i < balloon_formation_.at(k).number_of_balloons; i++) { + const auto& original = balloon_formation_.at(k).init.at(i); floater_params.emplace_back( original.x, original.y, original.vel_x, BalloonType::FLOATER, original.size, original.creation_counter); } - balloon_formation_[k + 50] = BalloonFormationUnit( - balloon_formation_[k].number_of_balloons, floater_params); + balloon_formation_.at(k + 50) = BalloonFormationUnit( + balloon_formation_.at(k).number_of_balloons, floater_params); } } @@ -239,7 +239,7 @@ void BalloonFormations::addTestFormation() { {90, -BLOCK, 0, BalloonType::FLOATER, BalloonSize::SIZE3, 200}, {140, -BLOCK, 0, BalloonType::FLOATER, BalloonSize::SIZE4, 200}}; - balloon_formation_[99] = BalloonFormationUnit(4, test_params); + balloon_formation_.at(99) = BalloonFormationUnit(4, test_params); } void BalloonFormations::loadDefaultFormations() { @@ -248,7 +248,7 @@ void BalloonFormations::loadDefaultFormations() { const int DEFAULT_POS_Y = param.game.play_area.rect.h - BALLOON_SPAWN_HEIGHT; const int X4_0 = param.game.play_area.rect.x; - const int X4_100 = param.game.play_area.rect.w - BALLOON_SIZE[3]; + const int X4_100 = param.game.play_area.rect.w - BALLOON_SIZE.at(3); // Formación básica #00 std::vector basic_formation = { @@ -258,7 +258,7 @@ void BalloonFormations::loadDefaultFormations() { } // Inicializa los conjuntos de formaciones -void BalloonFormations::initBalloonFormationPools() { +void BalloonFormations::initFormationPools() { // Reserva espacio para cada pool de formaciones balloon_formation_pool_.resize(NUMBER_OF_SETS_PER_POOL); diff --git a/source/balloon_formations.h b/source/balloon_formations.h index 0d12b83..8ccc781 100644 --- a/source/balloon_formations.h +++ b/source/balloon_formations.h @@ -46,8 +46,8 @@ class BalloonFormations { public: // --- Constructor y destructor --- BalloonFormations() { - initBalloonFormations(); - initBalloonFormationPools(); + initFormations(); + initFormationPools(); } ~BalloonFormations() = default; @@ -59,19 +59,18 @@ class BalloonFormations { private: // --- Constantes --- static constexpr int BALLOON_SPAWN_HEIGHT = 208; // Altura desde el suelo en la que aparecen los globos - static constexpr int CREATION_TIME = 300; // Tiempo base de creación de los globos para las formaciones + static constexpr int CREATION_TIME = 200; // Tiempo base de creación de los globos para las formaciones static constexpr int NUMBER_OF_BALLOON_FORMATIONS = 100; static constexpr int MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION = 50; static constexpr int NUMBER_OF_SETS_PER_POOL = 10; - static constexpr int NUMBER_OF_STAGES = 10; // --- Datos --- std::vector balloon_formation_; // Vector con todas las formaciones enemigas std::vector balloon_formation_pool_; // Conjuntos de formaciones enemigas // --- Métodos internos de inicialización --- - void initBalloonFormations(); // Inicializa la lista principal de formaciones de globos disponibles - void initBalloonFormationPools(); // Prepara las estructuras de agrupamiento o reutilización de formaciones (pools) + void initFormations(); // Inicializa la lista principal de formaciones de globos disponibles + void initFormationPools(); // Prepara las estructuras de agrupamiento o reutilización de formaciones (pools) auto loadFormationsFromFile(const std::string& filename, const std::map& variables) -> bool; // Carga las formaciones desde un archivo, evaluando variables dinámicas auto parseBalloonLine(const std::string& line, const std::map& variables) -> std::optional; // Parsea una línea individual del archivo y genera parámetros de formación auto evaluateExpression(const std::string& expr, const std::map& variables) -> float; // Evalúa expresiones matemáticas con variables definidas (complejas)