treballant en el format del fitxer balloons_formations.txt

This commit is contained in:
2025-07-21 00:30:19 +02:00
parent 9550e5e0b1
commit 2e606bf160
3 changed files with 228 additions and 223 deletions

View File

@@ -11,7 +11,7 @@
void BalloonFormations::initBalloonFormations() {
// Calcular posiciones base
const int Y_BASE = 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_100 = param.game.play_area.rect.w - BALLOON_SIZE[3];
@@ -40,13 +40,13 @@ void BalloonFormations::initBalloonFormations() {
{"X4_100", X4_100},
{"QUARTER1_X4", QUARTER1_X4},
{"QUARTER3_X4", QUARTER3_X4},
{"Y_BASE", Y_BASE},
{"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]},
{"VEL_POSITIVE", BALLOON_VELX_POSITIVE},
{"VEL_NEGATIVE", BALLOON_VELX_NEGATIVE}};
{"RIGHT", BALLOON_VELX_POSITIVE},
{"LEFT", BALLOON_VELX_NEGATIVE}};
balloon_formation_.reserve(NUMBER_OF_BALLOON_FORMATIONS);
@@ -122,33 +122,38 @@ auto BalloonFormations::parseBalloonLine(const std::string& line, const std::map
tokens.push_back(trim(token));
}
if (tokens.size() != 6) {
if (tokens.size() != 7) {
return std::nullopt;
}
try {
float x = evaluateExpression(tokens[0], variables);
float y = evaluateExpression(tokens[1], variables);
float vel_x = evaluateExpression(tokens[2], variables);
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);
BalloonType type = (tokens[3] == "BALLOON") ? BalloonType::BALLOON : BalloonType::FLOATER;
BalloonType type = (tokens[4] == "BALLOON") ? BalloonType::BALLOON : BalloonType::FLOATER;
BalloonSize size;
if (tokens[4] == "SIZE1") {
if (tokens[5] == "SIZE1") {
size = BalloonSize::SIZE1;
} else if (tokens[4] == "SIZE2") {
desp = desp * (BALLOON_SIZE[0] + 1);
} else if (tokens[5] == "SIZE2") {
size = BalloonSize::SIZE2;
} else if (tokens[4] == "SIZE3") {
desp = desp * (BALLOON_SIZE[1] + 1);
} else if (tokens[5] == "SIZE3") {
size = BalloonSize::SIZE3;
} else if (tokens[4] == "SIZE4") {
desp = desp * (BALLOON_SIZE[2] + 1);
} else if (tokens[5] == "SIZE4") {
size = BalloonSize::SIZE4;
desp = desp * (BALLOON_SIZE[3] + 1);
} else {
return std::nullopt;
}
int creation_time = evaluateExpression(tokens[5], variables);
int creation_time = evaluateExpression(tokens[6], variables);
return BalloonFormationParams(x, y, vel_x, type, size, creation_time);
return BalloonFormationParams(x + desp, y, vel_x, type, size, creation_time);
} catch (const std::exception&) {
return std::nullopt;
}
@@ -241,15 +246,15 @@ void BalloonFormations::loadDefaultFormations() {
// Código de fallback con algunas formaciones básicas hardcodeadas
// para que el juego funcione aunque falle la carga del archivo
const int Y_BASE = 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_100 = param.game.play_area.rect.w - BALLOON_SIZE[3];
constexpr int CREATION_TIME = 300;
// Formación básica #00
std::vector<BalloonFormationParams> basic_formation = {
BalloonFormationParams(X4_0, Y_BASE, BALLOON_VELX_POSITIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME),
BalloonFormationParams(X4_100, Y_BASE, BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME)};
BalloonFormationParams(X4_0, DEFAULT_POS_Y, BALLOON_VELX_POSITIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME),
BalloonFormationParams(X4_100, DEFAULT_POS_Y, BALLOON_VELX_NEGATIVE, BalloonType::BALLOON, BalloonSize::SIZE4, CREATION_TIME)};
balloon_formation_.emplace_back(2, basic_formation);
}
@@ -260,16 +265,16 @@ void BalloonFormations::initBalloonFormationPools() {
// Set #0
balloon_formation_pool_.at(0) = {
&balloon_formation_.at(0),
&balloon_formation_.at(1),
&balloon_formation_.at(2),
&balloon_formation_.at(2),
&balloon_formation_.at(2),
&balloon_formation_.at(2),
&balloon_formation_.at(2),
&balloon_formation_.at(2),
&balloon_formation_.at(2),
&balloon_formation_.at(2),
&balloon_formation_.at(2),
&balloon_formation_.at(2)};
&balloon_formation_.at(3),
&balloon_formation_.at(4),
&balloon_formation_.at(5),
&balloon_formation_.at(6),
&balloon_formation_.at(7),
&balloon_formation_.at(8),
&balloon_formation_.at(9)};
// Set #1
balloon_formation_pool_.at(1) = {