arreglant balloon.cpp per a deltaTime pur
This commit is contained in:
@@ -82,11 +82,11 @@ void BalloonManager::render() {
|
||||
// Crea una formación de globos
|
||||
void BalloonManager::deployRandomFormation(int stage) {
|
||||
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
|
||||
if (balloon_deploy_counter_ == 0) {
|
||||
if (balloon_deploy_counter_ >= DEFAULT_BALLOON_DEPLOY_COUNTER) {
|
||||
// En este punto se decide entre crear una powerball o una formación enemiga
|
||||
if ((rand() % 100 < 15) && (canPowerBallBeCreated())) {
|
||||
createPowerBall(); // Crea una powerball
|
||||
balloon_deploy_counter_ = 10; // Da un poco de margen para que se creen mas globos
|
||||
balloon_deploy_counter_ = -167; // Resetea con pequeño retraso (10 frames = 167ms negativos)
|
||||
} else {
|
||||
// Decrementa el contador de despliegues de globos necesarios para la siguiente PowerBall
|
||||
if (power_ball_counter_ > 0) {
|
||||
@@ -113,13 +113,13 @@ void BalloonManager::deployRandomFormation(int stage) {
|
||||
.type = balloon.type,
|
||||
.size = balloon.size,
|
||||
.vel_x = balloon.vel_x,
|
||||
.speed = balloon_speed_,
|
||||
.game_tempo = balloon_speed_,
|
||||
.creation_counter = static_cast<Uint16>(creation_time_enabled_ ? balloon.creation_counter : 0)};
|
||||
createBalloon(config);
|
||||
}
|
||||
|
||||
// Reinicia el contador para el próximo despliegue
|
||||
balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_COUNTER;
|
||||
balloon_deploy_counter_ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ void BalloonManager::deployFormation(int formation_id) {
|
||||
.type = balloon.type,
|
||||
.size = balloon.size,
|
||||
.vel_x = balloon.vel_x,
|
||||
.speed = balloon_speed_,
|
||||
.game_tempo = balloon_speed_,
|
||||
.creation_counter = balloon.creation_counter};
|
||||
createBalloon(config);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ void BalloonManager::deployFormation(int formation_id, float y) {
|
||||
.type = balloon.type,
|
||||
.size = balloon.size,
|
||||
.vel_x = balloon.vel_x,
|
||||
.speed = balloon_speed_,
|
||||
.game_tempo = balloon_speed_,
|
||||
.creation_counter = balloon.creation_counter};
|
||||
createBalloon(config);
|
||||
}
|
||||
@@ -164,12 +164,8 @@ void BalloonManager::freeBalloons() {
|
||||
|
||||
// Actualiza la variable enemyDeployCounter (time-based)
|
||||
void BalloonManager::updateBalloonDeployCounter(float deltaTime) {
|
||||
if (balloon_deploy_counter_ > 0) {
|
||||
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
|
||||
float frameFactor = deltaTime / (1000.0f / 60.0f);
|
||||
balloon_deploy_counter_ -= frameFactor;
|
||||
if (balloon_deploy_counter_ < 0) balloon_deploy_counter_ = 0;
|
||||
}
|
||||
// DeltaTime puro - contador incrementa hasta llegar al umbral
|
||||
balloon_deploy_counter_ += deltaTime;
|
||||
}
|
||||
|
||||
// Indica si se puede crear una powerball
|
||||
@@ -214,14 +210,15 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
|
||||
.y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
|
||||
.size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1),
|
||||
.vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE,
|
||||
.speed = balloon_speed_,
|
||||
.game_tempo = balloon_speed_,
|
||||
.creation_counter = 0};
|
||||
|
||||
// Crea el globo
|
||||
auto b = createBalloon(config);
|
||||
|
||||
// Establece parametros
|
||||
b->setVelY(b->getType() == Balloon::Type::BALLOON ? -2.50F : Balloon::VELX_NEGATIVE * 2.0F);
|
||||
// Establece parametros (deltaTime puro - valores ya en pixels/ms)
|
||||
constexpr float VEL_Y_BALLOON_PER_MS = -0.15F; // -2.50F convertido a pixels/ms
|
||||
b->setVelY(b->getType() == Balloon::Type::BALLOON ? VEL_Y_BALLOON_PER_MS : Balloon::VELX_NEGATIVE * 2.0F);
|
||||
|
||||
// Herencia de estados
|
||||
if (balloon->isStopped()) { b->stop(); }
|
||||
@@ -248,7 +245,7 @@ void BalloonManager::createPowerBall() {
|
||||
.type = Balloon::Type::POWERBALL,
|
||||
.size = Balloon::Size::EXTRALARGE,
|
||||
.vel_x = VEL_X.at(LUCK),
|
||||
.speed = balloon_speed_,
|
||||
.game_tempo = balloon_speed_,
|
||||
.creation_counter = 0,
|
||||
.play_area = play_area_,
|
||||
.texture = balloon_textures_.at(4),
|
||||
@@ -270,7 +267,7 @@ void BalloonManager::createPowerBall() {
|
||||
void BalloonManager::setBalloonSpeed(float speed) {
|
||||
balloon_speed_ = speed;
|
||||
for (auto &balloon : balloons_) {
|
||||
balloon->setSpeed(speed);
|
||||
balloon->setGameTempo(speed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +280,7 @@ auto BalloonManager::popBalloon(const std::shared_ptr<Balloon> &balloon) -> int
|
||||
balloon->pop(true);
|
||||
score = destroyAllBalloons();
|
||||
power_ball_enabled_ = false;
|
||||
balloon_deploy_counter_ = 20;
|
||||
balloon_deploy_counter_ = -334; // Resetea con retraso (20 frames = 334ms negativos)
|
||||
} else {
|
||||
score = balloon->getScore();
|
||||
if (balloon->getSize() != Balloon::Size::SMALL) {
|
||||
@@ -339,7 +336,7 @@ auto BalloonManager::destroyAllBalloons() -> int {
|
||||
score += destroyBalloon(balloon);
|
||||
}
|
||||
|
||||
balloon_deploy_counter_ = 300;
|
||||
balloon_deploy_counter_ = -5000; // Resetea con retraso grande (300 frames = 5000ms negativos)
|
||||
Screen::get()->flash(Colors::FLASH, 3);
|
||||
Screen::get()->shake();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user