diff --git a/PlayerController.cpp b/PlayerController.cpp index a441a7c..c86943d 100644 --- a/PlayerController.cpp +++ b/PlayerController.cpp @@ -174,8 +174,14 @@ void PlayerController::update() { _player->reload(); } - if ((_inRunning || _player->velocity().sqrAbs() > 3) && _player->inCollision() && SoundController::getStatus(SoundTag("walk")) != sf::Sound::Status::Playing) { - int soundNum = (int)((double) rand() / RAND_MAX * 5) + 1; - SoundController::playSound(SoundTag("walk"), "sound/stonestep" + std::to_string(soundNum) + ".ogg"); + bool walkSoundPlayed = false; + for(int k = 1; k < 7; k++) { + if(SoundController::getStatus(SoundTag("walkSound_" + std::to_string(k))) == sf::Sound::Status::Playing) { + walkSoundPlayed = true; + } + } + if ((_inRunning || _player->velocity().sqrAbs() > 3) && _player->inCollision() && !walkSoundPlayed) { + int soundNum = (int)((double) rand() / RAND_MAX * 6) + 1; + SoundController::playSound(SoundTag("walkSound_" + std::to_string(soundNum)), "sound/stonestep" + std::to_string(soundNum) + ".ogg"); } } diff --git a/engine/SoundController.cpp b/engine/SoundController.cpp index e01ffe2..a0e58fb 100644 --- a/engine/SoundController.cpp +++ b/engine/SoundController.cpp @@ -22,8 +22,9 @@ void SoundController::playSound(const SoundTag& soundTag, const std::string& fil return; } - stopSound(soundTag); - _instance->_sounds.emplace(soundTag, sf::Sound(*ResourceManager::loadSoundBuffer(filename))); + if(_instance->_sounds.count(soundTag) == 0) { + _instance->_sounds.emplace(soundTag, sf::Sound(*ResourceManager::loadSoundBuffer(filename))); + } _instance->_sounds[soundTag].play(); Log::log("SoundController::playSound(): play sound '" + soundTag.str() + "'"); @@ -49,7 +50,6 @@ void SoundController::stopSound(const SoundTag& soundTag) { if(_instance->_sounds.count(soundTag) > 0) { _instance->_sounds[soundTag].stop(); } - _instance->_sounds.erase(soundTag); Log::log("SoundController::stopSound(): sound '" + soundTag.str() + "' was stopped"); } @@ -62,7 +62,6 @@ sf::Sound::Status SoundController::getStatus(const SoundTag& soundTag) { if(_instance->_sounds.count(soundTag) > 0) { return _instance->_sounds[soundTag].getStatus(); } else { - _instance->_sounds.erase(soundTag); return sf::Sound::Status::Stopped; } } @@ -70,8 +69,7 @@ sf::Sound::Status SoundController::getStatus(const SoundTag& soundTag) { void SoundController::free() { if(_validInstance) { for(auto& [soundTag, sound] : _instance->_sounds) { - _instance->_sounds[soundTag].stop(); - Log::log("SoundController::stopSound(): sound '" + soundTag.str() + "' was stopped"); + stopSound(soundTag); } _instance->_sounds.clear(); } diff --git a/weapon/Weapon.cpp b/weapon/Weapon.cpp index 567e530..4d4d3e4 100644 --- a/weapon/Weapon.cpp +++ b/weapon/Weapon.cpp @@ -40,7 +40,7 @@ FireInformation Weapon::fire(std::function