From fd7beee5a16a76892570e15c681f6b4a4766a5a6 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 25 Nov 2024 17:48:25 +0100 Subject: [PATCH] Continuem treballant en els credits --- source/balloon.cpp | 14 +++++++++++++- source/balloon_formations.h | 2 +- source/balloon_manager.cpp | 19 ++++++++++++++++--- source/balloon_manager.h | 7 +++++-- source/credits.cpp | 36 +++++++++++++++++++++++++++++++----- source/credits.h | 3 +++ 6 files changed, 69 insertions(+), 12 deletions(-) diff --git a/source/balloon.cpp b/source/balloon.cpp index dd0b1df..1c70c9c 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -171,7 +171,19 @@ void Balloon::move() y_ += vy_ * speed_; // Colisión en la parte superior de la zona de juego excepto para la PowerBall - if (type_ != BalloonType::POWERBALL) + /*if (type_ != BalloonType::POWERBALL) + { + const int min_y = play_area_.y; + if (y_ < min_y) + { + y_ = min_y; + vy_ = -vy_; + enableBounce(); + } + }*/ + + // Colisión en la parte superior solo si el globo va de subida + if (vy_ < 0) { const int min_y = play_area_.y; if (y_ < min_y) diff --git a/source/balloon_formations.h b/source/balloon_formations.h index 09a7165..7e921b3 100644 --- a/source/balloon_formations.h +++ b/source/balloon_formations.h @@ -38,7 +38,6 @@ struct BalloonFormationUnit BalloonFormationUnit() : number_of_balloons(0), init() {} }; - using BalloonFormationPool = std::vector; class BalloonFormations @@ -67,4 +66,5 @@ public: // Getters const BalloonFormationPool &getPool(int pool) { return balloon_formation_pool_.at(pool); } const BalloonFormationUnit &getSet(int pool, int set) { return *balloon_formation_pool_.at(pool).at(set); } + const BalloonFormationUnit &getSet(int set) const { return balloon_formation_.at(set); } }; diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index a320ace..50feb5b 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -119,9 +119,10 @@ void BalloonManager::deployBalloonFormation(int stage) } } -void BalloonManager::deployBalloonFormation(int pool, int set_number) +// Crea una formación de enemigos específica +void BalloonManager::deploySet(int set_number) { - const auto set = balloon_formations_->getSet(pool, set_number); + const auto set = balloon_formations_->getSet(set_number); const auto numEnemies = set.number_of_balloons; for (int i = 0; i < numEnemies; ++i) { @@ -130,6 +131,18 @@ void BalloonManager::deployBalloonFormation(int pool, int set_number) } } +// Crea una formación de enemigos específica +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) + { + auto p = set.init[i]; + createBalloon(p.x, y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter); + } +} + // Vacia del vector de globos los globos que ya no sirven void BalloonManager::freeBalloons() { @@ -350,7 +363,7 @@ void BalloonManager::reLoad() // Crea dos globos gordos void BalloonManager::createTwoBigBalloons() { - deployBalloonFormation(0, 1); + deploySet(1); } // Obtiene el nivel de ameza actual generado por los globos diff --git a/source/balloon_manager.h b/source/balloon_manager.h index 98ffb2a..87f1f65 100644 --- a/source/balloon_manager.h +++ b/source/balloon_manager.h @@ -53,9 +53,12 @@ public: // Vacia del vector de globos los globos que ya no sirven void freeBalloons(); - // Crea una formación de enemigos + // Crea una formación de enemigos al azar void deployBalloonFormation(int stage); - void deployBalloonFormation(int pool, int set); + + // Crea una formación de enemigos específica + void deploySet(int set); + void deploySet(int set, int y); // Actualiza la variable enemyDeployCounter void updateBalloonDeployCounter(); diff --git a/source/credits.cpp b/source/credits.cpp index efb7b93..1ff02c3 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -28,11 +28,10 @@ Credits::Credits() tiled_bg_(std::make_unique(param.game.game_area.rect, TiledBGMode::DIAGONAL)) { section::name = section::Name::CREDITS; - balloon_manager_->setPlayArea(param.game.game_area.rect); - balloon_manager_->createTwoBigBalloons(); - balloon_manager_->deployBalloonFormation(4,2); - balloon_manager_->deployBalloonFormation(4,5); - balloon_manager_->createPowerBall(); + // balloon_manager_->setPlayArea(param.game.game_area.rect); + const auto r = param.game.game_area.rect; + const int bars = 30; + balloon_manager_->setPlayArea({r.x, r.y + bars, r.w, r.h - bars}); SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND); fillTextTexture(); JA_PlayMusic(Resource::get()->getMusic("credits.ogg")); @@ -67,6 +66,7 @@ void Credits::update() tiled_bg_->update(); balloon_manager_->update(); updateRects(); + throwBalloons(); Screen::get()->update(); ++counter_; } @@ -83,6 +83,11 @@ void Credits::render() tiled_bg_->render(); balloon_manager_->render(); + SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255); + SDL_Rect r1 = {0, 0, 320, 30}; + SDL_Rect r2 = {0, 255 - 30, 320, 30}; + SDL_RenderFillRect(Screen::get()->getRenderer(), &r1); + SDL_RenderFillRect(Screen::get()->getRenderer(), &r2); SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_); SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_); @@ -220,4 +225,25 @@ void Credits::updateRects() --mini_logo_rect_dst_.y; } mini_logo_rect_dst_.y = std::max(mini_logo_rect_dst_.y, mini_logo_final_pos_); +} + +// Tira globos al escenario +void Credits::throwBalloons() +{ + constexpr int speed = 200; + const std::vector sets = {0, 63, 25, 67, 17, 75, 13, 50}; + + if (counter_ > ((sets.size() - 1) * speed) * 3) + return; + + if (counter_ % speed == 0) + { + const int index = (counter_ / speed) % sets.size(); + balloon_manager_->deploySet(sets.at(index), -50); + } + + if (counter_ % (speed * 4) == 0) + { + balloon_manager_->createPowerBall(); + } } \ No newline at end of file diff --git a/source/credits.h b/source/credits.h index b1e0b24..bbeac45 100644 --- a/source/credits.h +++ b/source/credits.h @@ -42,6 +42,9 @@ private: // Actualiza el destino de los rectangulos de las texturas void updateRects(); + // Tira globos al escenario + void throwBalloons(); + public: // Constructor Credits();