diff --git a/include/SoundManager.h b/include/SoundManager.h index acd42e5..34e20db 100644 --- a/include/SoundManager.h +++ b/include/SoundManager.h @@ -48,17 +48,18 @@ class SoundManager //! \returns a pointer to Mix_Chunk, which is added to a map in the AssetManager //! \sa AssetManager::AddSound(std::string id, const char* path) - static void playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume); //!< Plays sound effects + static void playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume, int channel); //!< Plays sound effects //! handles if sounds can overlap, how often they can loop, as well as the volume at which the specified sound effect should play static void playMusic(Game* game, std::string sound, int loops, int volume, int ms); //up]) { transform->direction.y = -1; sprite->playAnimation(WALK); - SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME); + SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1); } if (keystates[this->left]) { transform->direction.x = -1; sprite->playAnimation(WALK); sprite->setDirection(Direction::LEFT); - SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME); + SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1); } if (keystates[this->down]) { transform->direction.y = 1; sprite->playAnimation(WALK); - SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME); + SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1); } if (keystates[this->right]) { transform->direction.x = 1; sprite->playAnimation(WALK); sprite->setDirection(Direction::RIGHT); - SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME); + SoundManager::playSound(this->entity->getManager().getGame(), "steps", false, PLAY_ONCE, MAX_VOLUME, -1); } if (keystates[this->fire]) { diff --git a/src/ProjectileComponent.cpp b/src/ProjectileComponent.cpp index af0eb13..9c0087a 100644 --- a/src/ProjectileComponent.cpp +++ b/src/ProjectileComponent.cpp @@ -13,7 +13,7 @@ void ProjectileComponent::init() { transformComponent = &entity->getComponent(); transformComponent->direction = direction; - SoundManager::playSound(this->entity->getManager().getGame(), "throw_egg", true, PLAY_ONCE, MAX_VOLUME); + SoundManager::playSound(this->entity->getManager().getGame(), "throw_egg", true, PLAY_ONCE, MAX_VOLUME, -1); } void ProjectileComponent::update() diff --git a/src/SoundManager.cpp b/src/SoundManager.cpp index 2daa198..bc93785 100644 --- a/src/SoundManager.cpp +++ b/src/SoundManager.cpp @@ -48,11 +48,11 @@ Mix_Chunk* SoundManager::loadSound(const char* fileName) } // TODO: using a string here is probably... a less than stellar method, figure out how to change this -void SoundManager::playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume) +void SoundManager::playSound(Game* game, std::string sound, bool canOverlap, int loops, int volume, int channel) { if(!canOverlap) { - if (Mix_Playing(-1) != 0) + if (Mix_Playing(channel) != 0) return; } @@ -61,7 +61,7 @@ void SoundManager::playSound(Game* game, std::string sound, bool canOverlap, int std::cerr << "Error adjusting volume: " << Mix_GetError() << std::endl; } - if (Mix_PlayChannel(-1, game->assets->getSound(sound), loops) == -1) + if (Mix_PlayChannel(channel, game->assets->getSound(sound), loops) == -1) { std::cerr << "Error playing sound '" << sound << "': " << Mix_GetError() << std::endl; } @@ -89,14 +89,19 @@ void SoundManager::playMusic(Game* game, std::string music, int loops, int volum } } -void SoundManager::setVolume(int volume) +void SoundManager::setSoundVolume(int volume, int channel) { - Mix_Volume(-1, volume); + Mix_Volume(channel, volume); } -void SoundManager::pauseSound() +void SoundManager::setMusicVolume(int volume) { - Mix_Pause(-1); + Mix_VolumeMusic(volume); +} + +void SoundManager::pauseSound(int channel) +{ + Mix_Pause(channel); } void SoundManager::pauseMusic() @@ -104,9 +109,9 @@ void SoundManager::pauseMusic() Mix_PauseMusic(); } -void SoundManager::restartSound() +void SoundManager::restartSound(int channel) { - Mix_Resume(-1); + Mix_Resume(channel); } void SoundManager::restartMusic()