diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 889d306..848d750 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -5,7 +5,6 @@ #include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VELX... #include "balloon_formations.h" // Para BalloonFormationParams, BalloonForma... #include "explosions.h" // Para Explosions -#include "audio.h" // Para JA_PlaySound #include "param.h" // Para Param, ParamGame, param #include "resource.h" // Para Resource #include "screen.h" // Para Screen @@ -320,7 +319,6 @@ int BalloonManager::destroyAllBalloons() } balloon_deploy_counter_ = 300; - Audio::get()->playSound("power_ball_explosion.wav"); Screen::get()->flash(FLASH_COLOR, 3); Screen::get()->shake(); diff --git a/source/director.cpp b/source/director.cpp index 6bf2df6..6b64580 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -296,15 +296,22 @@ void Director::setFileList() Asset::get()->add(prefix + "/data/sound/clock.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/coffee_out.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/continue_clock.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/debian_drop.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/debian_pickup.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/game_start.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/hi_score_achieved.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/item_drop.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/item_pickup.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/jump.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/logo.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/notify.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/player_collision.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/power_ball_explosion.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/service_menu_adjust.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/service_menu_move.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/service_menu_select.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/stage_change.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/tabe_hit.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/tabe.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/title.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/voice_aw_aw_aw.wav", AssetType::SOUND); @@ -314,13 +321,6 @@ void Director::setFileList() Asset::get()->add(prefix + "/data/sound/voice_power_up.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/voice_thankyou.wav", AssetType::SOUND); Asset::get()->add(prefix + "/data/sound/walk.wav", AssetType::SOUND); - Asset::get()->add(prefix + "/data/sound/debian_drop.wav", AssetType::SOUND); - Asset::get()->add(prefix + "/data/sound/debian_pickup.wav", AssetType::SOUND); - Asset::get()->add(prefix + "/data/sound/tabe_hit.wav", AssetType::SOUND); - Asset::get()->add(prefix + "/data/sound/jump.wav", AssetType::SOUND); - Asset::get()->add(prefix + "/data/sound/service_menu_move.wav", AssetType::SOUND); - Asset::get()->add(prefix + "/data/sound/service_menu_adjust.wav", AssetType::SOUND); - Asset::get()->add(prefix + "/data/sound/service_menu_select.wav", AssetType::SOUND); // Shaders Asset::get()->add(prefix + "/data/shaders/crtpi_256.glsl", AssetType::DATA); diff --git a/source/player.cpp b/source/player.cpp index c65f8f3..46811ef 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -186,7 +186,7 @@ void Player::move() { player_sprite_->setPosX(std::clamp(X, MIN_X, MAX_X)); player_sprite_->setVelX(-player_sprite_->getVelX()); - playJumpingSound(); + playSound("jump.wav"); } // Si el cadaver toca el suelo rebota y si tiene poca velocidad, se detiene y cambia de estado @@ -201,7 +201,7 @@ void Player::move() pos_y_ = default_pos_y_; player_sprite_->clear(); shiftSprite(); - playJumpingSound(); + playSound("jump.wav"); } else { @@ -209,7 +209,7 @@ void Player::move() player_sprite_->setPosY(play_area_.h - HEIGHT_); player_sprite_->setVelY(player_sprite_->getVelY() * -0.5f); player_sprite_->setVelX(player_sprite_->getVelX() * 0.75f); - playJumpingSound(); + playSound("jump.wav"); } } break; @@ -228,7 +228,7 @@ void Player::move() ++step_counter_; if (step_counter_ % 10 == 0) { - Audio::get()->playSound("walk.wav"); + playSound("walk.wav"); } switch (id_) @@ -259,7 +259,7 @@ void Player::move() ++step_counter_; if (step_counter_ % 10 == 0) { - Audio::get()->playSound("walk.wav"); + playSound("walk.wav"); } switch (id_) @@ -530,7 +530,7 @@ void Player::setPlayingState(PlayerState state) continue_ticks_ = SDL_GetTicks(); continue_counter_ = 9; setScoreboardMode(ScoreboardMode::CONTINUE); - Audio::get()->playSound("continue_clock.wav"); + playSound("continue_clock.wav"); break; } case PlayerState::WAITING: @@ -568,8 +568,8 @@ void Player::setPlayingState(PlayerState state) player_sprite_->setCurrentAnimation("dying"); player_sprite_->setAnimationSpeed(5); setScoreboardMode(ScoreboardMode::GAME_OVER); - Audio::get()->playSound("voice_aw_aw_aw.wav"); - Audio::get()->playSound("jump.wav"); + playSound("voice_aw_aw_aw.wav"); + playSound("jump.wav"); break; } case PlayerState::GAME_OVER: @@ -769,7 +769,7 @@ void Player::decContinueCounter() } else { - Audio::get()->playSound("continue_clock.wav"); + playSound("continue_clock.wav"); } } @@ -812,10 +812,13 @@ void Player::shiftSprite() power_sprite_->setPosX(getPosX() - power_up_desp_x_); } -// Hace sonar un ruido al azar -void Player::playJumpingSound() +void Player::playSound(const std::string &name) { - Audio::get()->playSound("jump.wav"); + if (demo_) + return; + + static auto audio = Audio::get(); + audio->playSound(name); } // Añade una puntuación a la tabla de records diff --git a/source/player.h b/source/player.h index 4bf9522..7cfc035 100644 --- a/source/player.h +++ b/source/player.h @@ -210,7 +210,7 @@ private: void decEnterNameCounter(); // Decrementa el contador de entrar nombre void updateScoreboard(); // Actualiza el panel del marcador void setScoreboardMode(ScoreboardMode mode); // Cambia el modo del marcador - void playJumpingSound(); // Hace sonar un sonido aleatorio + void playSound(const std::string &name); // Hace sonar un sonido bool isRenderable() const { return !isWaiting() && !isGameOver(); } void addScoreToScoreBoard(); // Añade una puntuación a la tabla de records }; \ No newline at end of file diff --git a/source/sections/game.cpp b/source/sections/game.cpp index aed3103..952b660 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -199,7 +199,7 @@ void Game::updateHiScore() if (hi_score_achieved_ == false) { hi_score_achieved_ = true; - Audio::get()->playSound("hi_score_achieved.wav"); + playSound("hi_score_achieved.wav"); } } } @@ -257,7 +257,7 @@ void Game::updateStage() // Cambio de fase Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power; ++Stage::number; - Audio::get()->playSound("stage_change.wav"); + playSound("stage_change.wav"); balloon_manager_->resetBalloonSpeed(); screen_->flash(FLASH_COLOR, 3); screen_->shake(); @@ -374,6 +374,7 @@ void Game::updateGameStateCompleted() stopMusic(); Stage::number = 9; // Deja el valor dentro de los limites balloon_manager_->destroyAllBalloons(); // Destruye a todos los globos + playSound("power_ball_explosion.wav"); destroyAllItems(); // Destruye todos los items Stage::power = 0; // Vuelve a dejar el poder a cero, por lo que hubiera podido subir al destruir todos los globos background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas @@ -479,7 +480,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr &player) player->addScore(1000); const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(0)->getWidth()) / 2; createItemText(x, game_text_textures_.at(0)); - Audio::get()->playSound("item_pickup.wav"); + playSound("item_pickup.wav"); break; } case ItemType::GAVINA: @@ -487,7 +488,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr &player) player->addScore(2500); const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(1)->getWidth()) / 2; createItemText(x, game_text_textures_.at(1)); - Audio::get()->playSound("item_pickup.wav"); + playSound("item_pickup.wav"); break; } case ItemType::PACMAR: @@ -495,7 +496,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr &player) player->addScore(5000); const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(2)->getWidth()) / 2; createItemText(x, game_text_textures_.at(2)); - Audio::get()->playSound("item_pickup.wav"); + playSound("item_pickup.wav"); break; } case ItemType::DEBIAN: @@ -503,7 +504,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr &player) player->addScore(100000); const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(6)->getWidth()) / 2; createItemText(x, game_text_textures_.at(6)); - Audio::get()->playSound("debian_pickup.wav"); + playSound("debian_pickup.wav"); break; } case ItemType::CLOCK: @@ -511,7 +512,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr &player) enableTimeStopItem(); const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(5)->getWidth()) / 2; createItemText(x, game_text_textures_.at(5)); - Audio::get()->playSound("item_pickup.wav"); + playSound("item_pickup.wav"); break; } case ItemType::COFFEE: @@ -528,7 +529,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr &player) const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(4)->getWidth()) / 2; createItemText(x, game_text_textures_.at(4)); } - Audio::get()->playSound("voice_coffee.wav"); + playSound("voice_coffee.wav"); break; } case ItemType::COFFEE_MACHINE: @@ -537,7 +538,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr &player) coffee_machine_enabled_ = false; const auto x = item->getPosX() + (item->getWidth() - game_text_textures_.at(3)->getWidth()) / 2; createItemText(x, game_text_textures_.at(3)); - Audio::get()->playSound("voice_power_up.wav"); + playSound("voice_power_up.wav"); break; } default: @@ -566,7 +567,7 @@ void Game::checkBulletCollision() if (tabe_->tryToGetBonus()) { createItem(ItemType::DEBIAN, pos.x, pos.y); - Audio::get()->playSound("debian_drop.wav"); + playSound("debian_drop.wav"); } else { @@ -574,7 +575,7 @@ void Game::checkBulletCollision() { createItem(ItemType::COFFEE, pos.x, pos.y); } - Audio::get()->playSound("tabe_hit.wav"); + playSound("tabe_hit.wav"); } break; } @@ -596,7 +597,7 @@ void Game::checkBulletCollision() if (dropped_item != ItemType::COFFEE_MACHINE) { createItem(dropped_item, balloon->getPosX(), balloon->getPosY()); - Audio::get()->playSound("item_drop.wav"); + playSound("item_drop.wav"); } else { @@ -618,7 +619,7 @@ void Game::checkBulletCollision() updateHiScore(); // Sonido de explosión - Audio::get()->playSound("balloon.wav"); + playSound("balloon.wav"); // Deshabilita la bala bullet->disable(); @@ -674,7 +675,7 @@ void Game::updateItems() item->update(); if (item->isOnFloor()) { - Audio::get()->playSound("title.wav"); + playSound("title.wav"); screen_->shake(1, 2, 4); } } @@ -901,16 +902,16 @@ void Game::killPlayer(std::shared_ptr &player) // Lo pierde player->removeExtraHit(); throwCoffee(player->getPosX() + (player->getWidth() / 2), player->getPosY() + (player->getHeight() / 2)); - Audio::get()->playSound("coffee_out.wav"); + playSound("coffee_out.wav"); screen_->shake(); } else { // Si no tiene cafes, muere balloon_manager_->stopAllBalloons(); - Audio::get()->playSound("player_collision.wav"); + playSound("player_collision.wav"); screen_->shake(); - Audio::get()->playSound("voice_no.wav"); + playSound("voice_no.wav"); player->setPlayingState(PlayerState::DYING); if (allPlayersAreNotPlaying()) { @@ -930,7 +931,7 @@ void Game::updateTimeStopped() { if (time_stopped_counter_ % 30 == 0) { - Audio::get()->playSound("clock.wav"); + playSound("clock.wav"); } } else @@ -938,12 +939,12 @@ void Game::updateTimeStopped() if (time_stopped_counter_ % 30 == 0) { balloon_manager_->normalColorsToAllBalloons(); - Audio::get()->playSound("clock.wav"); + playSound("clock.wav"); } else if (time_stopped_counter_ % 30 == 15) { balloon_manager_->reverseColorsToAllBalloons(); - Audio::get()->playSound("clock.wav"); + playSound("clock.wav"); } } } @@ -1438,7 +1439,7 @@ void Game::handleFireInput(const std::shared_ptr &player, BulletType bul player->setInput(bulletType == BulletType::UP ? InputAction::FIRE_CENTER : bulletType == BulletType::LEFT ? InputAction::FIRE_LEFT : InputAction::FIRE_RIGHT); createBullet(player->getPosX() + (player->getWidth() / 2) - 6, player->getPosY() + (player->getHeight() / 2), bulletType, player->isPowerUp(), player->getId()); - Audio::get()->playSound("bullet.wav"); + playSound("bullet.wav"); // Establece un tiempo de espera para el próximo disparo. const int cooldown = player->isPowerUp() ? 5 : Options::settings.autofire ? 10 @@ -1535,7 +1536,7 @@ void Game::handlePlayerContinue(const std::shared_ptr &player) { player->setPlayingState(PlayerState::PLAYING); player->addCredit(); - Audio::get()->playSound("voice_thankyou.wav"); + playSound("voice_thankyou.wav"); } // Disminuye el contador de continuación si se presiona cualquier botón de disparo. @@ -1850,7 +1851,7 @@ void Game::updateGameStateEnteringPlayer() { setState(GameState::SHOWING_GET_READY_MESSAGE); createMessage({paths_.at(0), paths_.at(1)}, Resource::get()->getTexture("game_text_get_ready")); - Audio::get()->playSound("voice_get_ready.wav"); + playSound("voice_get_ready.wav"); } } } @@ -1972,6 +1973,15 @@ void Game::setState(GameState state) counter_ = 0; } +void Game::playSound(const std::string &name) +{ + if (demo_.enabled) + return; + + static auto audio = Audio::get(); + audio->playSound(name); +} + #ifdef DEBUG // Comprueba los eventos en el modo DEBUG void Game::checkDebugEvents(const SDL_Event &event) @@ -1997,6 +2007,7 @@ void Game::checkDebugEvents(const SDL_Event &event) if (auto_pop_balloons_) { balloon_manager_->destroyAllBalloons(); + playSound("power_ball_explosion.wav"); } balloon_manager_->setDeployBalloons(!auto_pop_balloons_); break; diff --git a/source/sections/game.h b/source/sections/game.h index eec3bee..cf2fb46 100644 --- a/source/sections/game.h +++ b/source/sections/game.h @@ -137,22 +137,22 @@ private: Options::settings.hi_score_table[0].name, Options::settings.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta - Demo demo_; // Variable con todas las variables relacionadas con el modo demo + Demo demo_; // Variable con todas las variables relacionadas con el modo demo Options::DifficultyCode difficulty_ = Options::settings.difficulty; // Dificultad del juego - Helper helper_; // Variable para gestionar las ayudas - Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa - bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego - bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima - bool paused_ = false; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade) - float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad - int counter_ = 0; // Contador para el juego - int game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos - int game_over_counter_ = GAME_OVER_COUNTER_; // Contador para el estado de fin de partida - int time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido - int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases - int menace_current_ = 0; // Nivel de amenaza actual - int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos - GameState state_ = GameState::FADE_IN; // Estado + Helper helper_; // Variable para gestionar las ayudas + Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa + bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego + bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima + bool paused_ = false; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade) + float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad + int counter_ = 0; // Contador para el juego + int game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos + int game_over_counter_ = GAME_OVER_COUNTER_; // Contador para el estado de fin de partida + int time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido + int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases + int menace_current_ = 0; // Nivel de amenaza actual + int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos + GameState state_ = GameState::FADE_IN; // Estado #ifdef DEBUG bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados @@ -230,19 +230,20 @@ private: void initPlayers(int player_id); // Inicializa los jugadores void playMusic(); // Hace sonar la música void stopMusic(); // Detiene la música + void playSound(const std::string &name); // Hace sonar un sonido void updateDemo(); // Actualiza las variables durante el modo demo + void updateGameStateFadeIn(); // Actualiza las variables durante dicho estado + void updateGameStateEnteringPlayer(); // Actualiza las variables durante dicho estado + void updateGameStateShowingGetReadyMessage(); // Actualiza las variables durante dicho estado + void updateGameStatePlaying(); // Actualiza las variables durante el transcurso normal del juego + void updateGameStateCompleted(); // Gestiona eventos para el estado del final del juego + void checkState(); // Comprueba el estado del juego + void cleanVectors(); // Vacía los vectores de elementos deshabilitados + void updateMenace(); // Gestiona el nivel de amenaza + void evaluateAndSetMenace(); // Calcula y establece el valor de amenaza en funcion de los globos activos + void checkAndUpdateBalloonSpeed(); // Actualiza la velocidad de los globos en funcion del poder acumulado de la fase + void setState(GameState state); // Cambia el estado del juego #ifdef RECORDING void updateRecording(); // Actualiza las variables durante el modo de grabación #endif - void updateGameStateFadeIn(); // Actualiza las variables durante dicho estado - void updateGameStateEnteringPlayer(); // Actualiza las variables durante dicho estado - void updateGameStateShowingGetReadyMessage(); // Actualiza las variables durante dicho estado - void updateGameStatePlaying(); // Actualiza las variables durante el transcurso normal del juego - void updateGameStateCompleted(); // Gestiona eventos para el estado del final del juego - void checkState(); // Comprueba el estado del juego - void cleanVectors(); // Vacía los vectores de elementos deshabilitados - void updateMenace(); // Gestiona el nivel de amenaza - void evaluateAndSetMenace(); // Calcula y establece el valor de amenaza en funcion de los globos activos - void checkAndUpdateBalloonSpeed(); // Actualiza la velocidad de los globos en funcion del poder acumulado de la fase - void setState(GameState state); // Cambia el estado del juego }; \ No newline at end of file