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