diff --git a/source/balloon.cpp b/source/balloon.cpp index 887ff84..6089821 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -5,6 +5,8 @@ #include "param.h" // Para Param, param, ParamBalloon, ParamGame #include "sprite.h" // Para Sprite #include "texture.h" // Para Texture +#include "resource.h" +#include "jail_audio.h" // Constructor Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, SDL_Rect play_area, std::shared_ptr texture, const std::vector &animation) @@ -36,6 +38,7 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel power_ = BALLOON_POWER[index]; menace_ = BALLOON_MENACE[index]; score_ = BALLOON_SCORE[index]; + sound_ = BALLOON_SOUND[index]; break; } @@ -50,14 +53,16 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel power_ = BALLOON_POWER[index]; menace_ = BALLOON_MENACE[index]; score_ = BALLOON_SCORE[index]; + sound_ = BALLOON_SOUND[index]; break; } case BalloonType::POWERBALL: { - const int index = 3; + constexpr int index = 3; h_ = w_ = BALLOON_SIZE[4]; + sound_ = BALLOON_SOUND[3]; power_ = score_ = menace_ = 0; vy_ = 0; @@ -145,6 +150,7 @@ void Balloon::move() const float max_x = play_area_.x + play_area_.w - w_ + clip; if (x_ < min_x || x_ > max_x) { + playSound(); x_ = std::clamp(x_, min_x, max_x); vx_ = -vx_; // Activa el efecto de rebote o invierte la rotación @@ -179,6 +185,7 @@ void Balloon::move() const int min_y = play_area_.y; if (y_ < min_y) { + playSound(); y_ = min_y; vy_ = -vy_; enableBounce(); @@ -189,6 +196,7 @@ void Balloon::move() const int max_y = play_area_.y + play_area_.h - h_; if (y_ > max_y) { + playSound(); y_ = max_y; vy_ = -default_vy_; if (type_ != BalloonType::POWERBALL) @@ -401,4 +409,13 @@ void Balloon::useNormalColor() { use_reversed_colors_ = false; setAnimation(); +} + +// Reproduce el sonido al rebotar +void Balloon::playSound() +{ + if (sound_enabled_) + { + JA_PlaySound(Resource::get()->getSound(sound_)); + } } \ No newline at end of file diff --git a/source/balloon.h b/source/balloon.h index 6a4d730..8f176f2 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -17,6 +17,7 @@ constexpr int BALLOON_SCORE[] = {50, 100, 200, 400}; constexpr int BALLOON_POWER[] = {1, 3, 7, 15}; constexpr int BALLOON_MENACE[] = {1, 2, 4, 8}; constexpr int BALLOON_SIZE[] = {10, 16, 26, 48, 49}; +const std::string BALLOON_SOUND[] = {"bubble1.wav", "bubble2.wav", "bubble3.wav", "bubble4.wav"}; // Tamaños de globo enum class BalloonSize : Uint8 @@ -113,6 +114,8 @@ private: float speed_; // Velocidad a la que se mueven los globos Uint8 power_; // Cantidad de poder que alberga el globo SDL_Rect play_area_; // Zona por donde se puede mover el globo + std::string sound_; // Archivo de sonido que hace el globo al rebotar + bool sound_enabled_ = false; // Indica si ha de sonar el sonido del globo al rebotar // Alinea el circulo de colisión con la posición del objeto globo void shiftColliders(); @@ -138,6 +141,9 @@ private: // Establece la animación correspondiente void setAnimation(); + // Reproduce el sonido al rebotar + void playSound(); + public: // Constructor Balloon( @@ -208,4 +214,5 @@ public: void setVelY(float vel_y) { vy_ = vel_y; } void setSpeed(float speed) { speed_ = speed; } void setInvulnerable(bool value) { invulnerable_ = value; } + void setSound(bool value) { sound_enabled_ = value; } }; \ No newline at end of file diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 9f48fb7..8abf9eb 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -371,4 +371,13 @@ int BalloonManager::getMenace() { return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) { return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); }); +} + +// Establece el sonido de los globos +void BalloonManager::setSounds(bool value) +{ + for (auto &balloon : balloons_) + { + balloon->setSound(value); + } } \ No newline at end of file diff --git a/source/balloon_manager.h b/source/balloon_manager.h index 87f1f65..1554824 100644 --- a/source/balloon_manager.h +++ b/source/balloon_manager.h @@ -111,6 +111,9 @@ public: // Obtiene el nivel de ameza actual generado por los globos int getMenace(); + // Establece el sonido de los globos + void setSounds(bool value); + // Getters float getBalloonSpeed() const { return balloon_speed_; } Balloons &getBalloons() { return balloons_; } diff --git a/source/director.cpp b/source/director.cpp index ff848db..7dc5550 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -54,7 +54,7 @@ Director::Director(int argc, const char *argv[]) section::name = section::Name::GAME; section::options = section::Options::GAME_PLAY_1P; #elif DEBUG - section::name = section::Name::LOGO; + section::name = section::Name::GAME; #else // NORMAL GAME section::name = section::Name::LOGO; section::attract_mode = section::AttractMode::TITLE_TO_DEMO; diff --git a/source/game.cpp b/source/game.cpp index 4034712..c62d80f 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -283,10 +283,15 @@ void Game::updateGameOverState() if (game_over_counter_ > 0) { if (game_over_counter_ == GAME_OVER_COUNTER_) + { createMessage({paths_.at(2), paths_.at(3)}, Resource::get()->getTexture("game_over")); + stopMusic(); + balloon_manager_->setSounds(true); + } game_over_counter_--; + /* if ((game_over_counter_ == 250) || (game_over_counter_ == 200) || (game_over_counter_ == 180) || (game_over_counter_ == 120) || (game_over_counter_ == 60)) { // Hace sonar aleatoriamente uno de los 4 sonidos de burbujas @@ -294,6 +299,7 @@ void Game::updateGameOverState() JA_Sound_t *sound[4] = {Resource::get()->getSound("bubble1.wav"), Resource::get()->getSound("bubble2.wav"), Resource::get()->getSound("bubble3.wav"), Resource::get()->getSound("bubble4.wav")}; JA_PlaySound(sound[index], 0); } + */ if (game_over_counter_ == 150) { @@ -724,7 +730,9 @@ void Game::createMessage(const std::vector &paths, std::shared_ptraddPath(path, true); + } path_sprites_.back()->enable(); } @@ -817,13 +825,13 @@ void Game::killPlayer(std::shared_ptr &player) else { // Si no tiene cafes, muere - pauseMusic(); + // 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); - allPlayersAreNotPlaying() ? stopMusic() : resumeMusic(); + // allPlayersAreNotPlaying() ? stopMusic() : resumeMusic(); } } @@ -871,7 +879,7 @@ void Game::update() checkMusicStatus(); screen_->update(); - globalInputs::update(); + globalInputs::update(); fillCanvas(); } } @@ -962,10 +970,8 @@ void Game::disableTimeStopItem() // Comprueba si la música ha de estar sonando void Game::checkMusicStatus() { - // Si la música no está sonando - if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED) - // Si se ha completado el juego o los jugadores han terminado, detiene la música - state_ == GameState::COMPLETED || allPlayersAreGameOver() ? JA_StopMusic() : JA_PlayMusic(Resource::get()->getMusic("playing.ogg")); + // Si se ha completado el juego o los jugadores han terminado, detiene la música + state_ == GameState::COMPLETED || allPlayersAreGameOver() ? stopMusic() : playMusic(); } // Bucle para el juego @@ -1000,8 +1006,7 @@ void Game::initPaths() paths_.emplace_back(Path(createPath(x1, x2, PathType::HORIZONTAL, y, 80, easeInQuint), 0)); } - // Recorrido para el texto de "Last Stage!" o de "X stages left" o "Game Over" - // (2,3) + // Recorrido para el texto de "Last Stage!" o de "X stages left" o "Game Over" (2,3) { const auto &texture = Resource::get()->getTexture("last_stage"); const auto h = texture->getHeight(); @@ -1693,6 +1698,16 @@ void Game::resumeMusic() } } +// Hace sonar la música +void Game::playMusic() +{ + // Si la música no está sonando + if (JA_GetMusicState() == JA_MUSIC_INVALID || JA_GetMusicState() == JA_MUSIC_STOPPED) + { + JA_PlayMusic(Resource::get()->getMusic("playing.ogg")); + } +} + // Detiene la música void Game::stopMusic() { diff --git a/source/game.h b/source/game.h index f52e205..dcea838 100644 --- a/source/game.h +++ b/source/game.h @@ -373,6 +373,9 @@ private: // Reanuda la música void resumeMusic(); + // Hace sonar la música + void playMusic(); + // Detiene la música void stopMusic();