revisat balloon_formationc.cpp i credits.cpp

This commit is contained in:
2025-09-23 14:03:07 +02:00
parent 159528adc9
commit 3fafff026b
6 changed files with 200 additions and 200 deletions

View File

@@ -70,7 +70,7 @@ Balloon::Balloon(const Config& config)
default_vy_ = param.balloon.settings.at(INDEX).vel;
sprite_->setRotate(config.creation_counter <= 0);
sprite_->setRotateAmount(vx_ > 0.0F ? 2.0 : -2.0);
sprite_->setRotateAmount(vx_ > 0.0F ? 120.0 : -120.0); // Convert from 2 degrees/frame to 120 degrees/second
break;
}

View File

@@ -77,7 +77,7 @@ class Balloon {
Size size = Size::EXTRALARGE;
float vel_x = VELX_POSITIVE;
float game_tempo = GAME_TEMPO.at(0);
Uint16 creation_counter = 0;
float creation_counter = 0.0f;
SDL_FRect play_area = {.x = 0.0F, .y = 0.0F, .w = 0.0F, .h = 0.0F};
std::shared_ptr<Texture> texture = nullptr;
std::vector<std::string> animation;

View File

@@ -155,7 +155,7 @@ auto BalloonFormations::parseBalloonLine(const std::string& line, const std::map
return std::nullopt;
}
int creation_time = DEFAULT_CREATION_TIME + evaluateExpression(tokens.at(6), variables);
float creation_time = evaluateExpression(tokens.at(6), variables); // Values in formations.txt are already in seconds
return SpawnParams(x + offset, y, vel_x, type, size, creation_time);
} catch (const std::exception&) {
@@ -168,7 +168,7 @@ auto BalloonFormations::evaluateExpression(const std::string& expr, const std::m
// Si es un número directo
if ((std::isdigit(trimmed_expr.at(0)) != 0) || (trimmed_expr.at(0) == '-' && trimmed_expr.length() > 1)) {
return std::stoi(trimmed_expr);
return std::stof(trimmed_expr);
}
// Si es una variable simple
@@ -205,7 +205,7 @@ auto BalloonFormations::evaluateSimpleExpression(const std::string& expr, const
}
// Si no se encuentra operador, intentar como variable o número
return variables.find(expr) != variables.end() ? variables.at(expr) : std::stoi(expr);
return variables.find(expr) != variables.end() ? variables.at(expr) : std::stof(expr);
}
auto BalloonFormations::trim(const std::string& str) -> std::string {

View File

@@ -20,13 +20,13 @@ class BalloonFormations {
float vel_x = 0.0F; // Velocidad inicial en el eje X
Balloon::Type type = Balloon::Type::BALLOON; // Tipo de globo
Balloon::Size size = Balloon::Size::SMALL; // Tamaño de globo
Uint16 creation_counter = 0; // Temporizador para la creación del globo
float creation_counter = 0.0f; // Temporizador para la creación del globo
// Constructor por defecto
SpawnParams() = default;
// Constructor con parámetros
SpawnParams(float x, float y, float vel_x, Balloon::Type type, Balloon::Size size, Uint16 creation_counter)
SpawnParams(float x, float y, float vel_x, Balloon::Type type, Balloon::Size size, float creation_counter)
: x(x),
y(y),
vel_x(vel_x),

View File

@@ -114,7 +114,7 @@ void BalloonManager::deployRandomFormation(int stage) {
.size = balloon.size,
.vel_x = balloon.vel_x,
.game_tempo = balloon_speed_,
.creation_counter = static_cast<Uint16>(creation_time_enabled_ ? balloon.creation_counter : 0)};
.creation_counter = creation_time_enabled_ ? balloon.creation_counter : 0.0f};
createBalloon(config);
}