diff --git a/source/balloon.cpp b/source/balloon.cpp index 6089821..3ff4ac1 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -229,12 +229,6 @@ void Balloon::move() } } -// Deshabilita el globo -void Balloon::disable() { enabled_ = false; } - -// Explosiona el globo -void Balloon::pop() { disable(); } - // Actualiza al globo a su posicion, animación y controla los contadores void Balloon::update() { diff --git a/source/balloon.h b/source/balloon.h index 8f176f2..2f0da0a 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -170,12 +170,6 @@ public: // Actualiza la posición y estados del globo void move(); - // Deshabilita el globo y pone a cero todos los valores - void disable(); - - // Explosiona el globo - void pop(); - // Actualiza al globo a su posicion, animación y controla los contadores void update(); @@ -215,4 +209,5 @@ public: void setSpeed(float speed) { speed_ = speed; } void setInvulnerable(bool value) { invulnerable_ = value; } void setSound(bool value) { sound_enabled_ = value; } + void disable() { enabled_ = false; } }; \ No newline at end of file diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 0efecf2..8b66e53 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -258,7 +258,7 @@ int BalloonManager::popBalloon(std::shared_ptr balloon) // Agrega la explosión y elimina el globo explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast(balloon->getSize())); - balloon->pop(); + balloon->disable(); } return score; @@ -294,7 +294,7 @@ int BalloonManager::destroyBalloon(std::shared_ptr &balloon) // Destruye el globo explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast(balloon->getSize())); - balloon->pop(); + balloon->disable(); return score; } diff --git a/source/game.cpp b/source/game.cpp index 6fe04ed..a116591 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -256,32 +256,29 @@ void Game::renderPlayers() // Comprueba si hay cambio de fase y actualiza las variables void Game::updateStage() { - if (state_ == GameState::PLAYING) + if (Stage::power >= Stage::get(Stage::number).power_to_complete) { - if (Stage::power >= Stage::get(Stage::number).power_to_complete) - { - // Cambio de fase - Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power; - ++Stage::number; - JA_PlaySound(Resource::get()->getSound("stage_change.wav")); - balloon_manager_->resetBalloonSpeed(); - screen_->flash(flash_color, 3); - screen_->shake(); + // Cambio de fase + Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power; + ++Stage::number; + JA_PlaySound(Resource::get()->getSound("stage_change.wav")); + balloon_manager_->resetBalloonSpeed(); + screen_->flash(flash_color, 3); + screen_->shake(); - // Escribe el texto por pantalla - if (Stage::number < 10) + // Escribe el texto por pantalla + if (Stage::number < 10) + { + std::vector paths = {paths_.at(2), paths_.at(3)}; + if (Stage::number == 9) { - std::vector paths = {paths_.at(2), paths_.at(3)}; - if (Stage::number == 9) - { - createMessage(paths, Resource::get()->getTexture("game_text_last_stage")); - } - else - { - auto text = Resource::get()->getText("04b_25_2x"); - const std::string caption = std::to_string(10 - Stage::number) + lang::getText(38); - createMessage(paths, text->writeToTexture(caption, 1, -4)); - } + createMessage(paths, Resource::get()->getTexture("game_text_last_stage")); + } + else + { + auto text = Resource::get()->getText("04b_25_2x"); + const std::string caption = std::to_string(10 - Stage::number) + lang::getText(38); + createMessage(paths, text->writeToTexture(caption, 1, -4)); } } } @@ -858,7 +855,8 @@ void Game::renderPathSprites() void Game::killPlayer(std::shared_ptr &player) { if (!player->isPlaying() || player->isInvulnerable()) - { // Si no está jugando o tiene inmunidad, no hace nada + { + // Si no está jugando o tiene inmunidad, no hace nada return; } @@ -874,12 +872,16 @@ void Game::killPlayer(std::shared_ptr &player) else { // Si no tiene cafes, muere - // pauseMusic(); balloon_manager_->stopAllBalloons(); JA_PlaySound(Resource::get()->getSound("player_collision.wav")); screen_->shake(); JA_PlaySound(Resource::get()->getSound("voice_no.wav")); player->setPlayingState(PlayerState::DYING); + if (allPlayersAreNotPlaying()) + { + // No se puede subir poder de fase si no hay nadie jugando + Stage::power_can_be_added = false; + } } } @@ -919,7 +921,6 @@ void Game::update() counter_++; updateDemo(); - #ifdef RECORDING updateRecording(); #endif diff --git a/source/player.cpp b/source/player.cpp index ab9273a..0810726 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -10,6 +10,7 @@ #include "texture.h" // Para Texture #include "resource.h" #include "jail_audio.h" +#include "stage.h" // Constructor Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector> texture, const std::vector> &animations) @@ -503,6 +504,7 @@ void Player::setPlayingState(PlayerState state) init(); playing_state_ = PlayerState::PLAYING; setScoreboardMode(ScoreboardMode::SCORE); + Stage::power_can_be_added = true; break; } case PlayerState::CONTINUE: diff --git a/source/stage.cpp b/source/stage.cpp index 0a8d3dd..4654e60 100644 --- a/source/stage.cpp +++ b/source/stage.cpp @@ -5,10 +5,11 @@ namespace Stage { - std::vector stages; // Variable con los datos de cada pantalla - int power = 0; // Poder acumulado en la fase - int total_power = 0; // Poder total necesario para completar el juego - int number = 0; // Fase actual + std::vector stages; // Variable con los datos de cada pantalla + int power = 0; // Poder acumulado en la fase + int total_power = 0; // Poder total necesario para completar el juego + int number = 0; // Fase actual + bool power_can_be_added = true; // Habilita la recolecta de poder // Devuelve una fase Stage get(int index) { return stages.at(std::min(9, index)); } @@ -35,7 +36,10 @@ namespace Stage // Añade poder void addPower(int amount) { - power += amount; - total_power += amount; + if (power_can_be_added) + { + power += amount; + total_power += amount; + } } } \ No newline at end of file diff --git a/source/stage.h b/source/stage.h index d9a53a2..17d6e84 100644 --- a/source/stage.h +++ b/source/stage.h @@ -19,6 +19,7 @@ namespace Stage extern int power; // Poder acumulado en la fase extern int total_power; // Poder total necesario para completar el juego extern int number; // Fase actual + extern bool power_can_be_added; // Indica si se puede añadir poder a la fase // Devuelve una fase Stage get(int index);