diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 8abf9eb..0efecf2 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -107,11 +107,18 @@ void BalloonManager::deployBalloonFormation(int stage) last_balloon_deploy_ = formation; const auto set = balloon_formations_->getSet(stage, formation); - const auto numEnemies = set.number_of_balloons; - for (int i = 0; i < numEnemies; ++i) + const auto num_enemies = set.number_of_balloons; + for (int i = 0; i < num_enemies; ++i) { auto p = set.init[i]; - createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter); + createBalloon( + p.x, + p.y, + p.type, + p.size, + p.vel_x, + balloon_speed_, + (creation_time_enabled_) ? p.creation_counter : 0); } balloon_deploy_counter_ = 300; @@ -123,8 +130,8 @@ void BalloonManager::deployBalloonFormation(int stage) void BalloonManager::deploySet(int set_number) { const auto set = balloon_formations_->getSet(set_number); - const auto numEnemies = set.number_of_balloons; - for (int i = 0; i < numEnemies; ++i) + const auto num_enemies = set.number_of_balloons; + for (int i = 0; i < num_enemies; ++i) { auto p = set.init[i]; createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter); @@ -135,8 +142,8 @@ void BalloonManager::deploySet(int set_number) void BalloonManager::deploySet(int set_number, int y) { const auto set = balloon_formations_->getSet(set_number); - const auto numEnemies = set.number_of_balloons; - for (int i = 0; i < numEnemies; ++i) + const auto num_enemies = set.number_of_balloons; + for (int i = 0; i < num_enemies; ++i) { auto p = set.init[i]; createBalloon(p.x, y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter); @@ -366,6 +373,21 @@ void BalloonManager::createTwoBigBalloons() deploySet(1); } +// Crea una disposición de globos aleatoria +void BalloonManager::createRandomBalloons() +{ + const int num_balloons = 2 + rand() % 4; + for (int i = 0; i < num_balloons; ++i) + { + const float x = param.game.game_area.rect.x + (rand() % param.game.game_area.rect.w) - BALLOON_SIZE[3]; + const int y = param.game.game_area.rect.y + (rand() % 50); + const BalloonSize size = static_cast(rand() % 4); + const float vel_x = (rand() % 2 == 0) ? BALLOON_VELX_POSITIVE : BALLOON_VELX_NEGATIVE; + const int creation_counter = 0; + createBalloon(x, y, BalloonType::BALLOON, size, vel_x, balloon_speed_, creation_counter); + } +} + // Obtiene el nivel de ameza actual generado por los globos int BalloonManager::getMenace() { diff --git a/source/balloon_manager.h b/source/balloon_manager.h index 1554824..b3db7b4 100644 --- a/source/balloon_manager.h +++ b/source/balloon_manager.h @@ -33,6 +33,7 @@ private: int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir; SDL_Rect play_area_ = param.game.play_area.rect; // Zona por donde se moveran los globos + bool creation_time_enabled_ = true; // Indica si los globos se crean con tiempo // Inicializa void init(); @@ -108,6 +109,9 @@ public: // Crea dos globos gordos void createTwoBigBalloons(); + // Crea una disposición de globos aleatoria + void createRandomBalloons(); + // Obtiene el nivel de ameza actual generado por los globos int getMenace(); @@ -117,9 +121,11 @@ public: // Getters float getBalloonSpeed() const { return balloon_speed_; } Balloons &getBalloons() { return balloons_; } + int getNumBalloons() const { return balloons_.size(); } // Setters void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; } void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); } void setPlayArea(SDL_Rect play_area) { play_area_ = play_area; } + void setCreationTimeEnabled(bool value) { creation_time_enabled_ = value; } }; \ No newline at end of file diff --git a/source/game.cpp b/source/game.cpp index 84b7e2b..b1dafbc 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1652,11 +1652,6 @@ void Game::initDemo(int player_id) Stage::total_power += Stage::get(i).power_to_complete; } - // Pone al jugador en estado jugar - { - getPlayer(player_id)->setPlayingState(PlayerState::PLAYING); - } - // Activa o no al otro jugador if (rand() % 3 != 0) { @@ -1680,6 +1675,9 @@ void Game::initDemo(int player_id) // Configura los marcadores scoreboard_->setMode(SCOREBOARD_LEFT_PANEL, ScoreboardMode::DEMO); scoreboard_->setMode(SCOREBOARD_RIGHT_PANEL, ScoreboardMode::DEMO); + + // Añade unos cuantos globos + // balloon_manager_->createRandomBalloons(); } // Modo grabar demo @@ -1770,7 +1768,7 @@ void Game::initPlayers(int player_id) // Activa el jugador que coincide con el "player_id" auto player = getPlayer(player_id); - player->setPlayingState(PlayerState::ENTERING_SCREEN); + player->setPlayingState((demo_.enabled) ? PlayerState::PLAYING : PlayerState::ENTERING_SCREEN); player->setInvulnerable(false); } @@ -1816,6 +1814,8 @@ void Game::updateDemo() { if (demo_.enabled) { + balloon_manager_->setCreationTimeEnabled((balloon_manager_->getNumBalloons() == 0) ? false : true); + // Actualiza ambos fades fade_in_->update(); fade_out_->update();