From 1796cb2f42e06d238a6e4fa762c86a0b431ccb65 Mon Sep 17 00:00:00 2001 From: zackhehuman Date: Mon, 14 Apr 2014 08:50:57 -0700 Subject: [PATCH 1/3] Implemented mute/unmute in AudioService --- engine/src/hikari/client/audio/AudioService.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/engine/src/hikari/client/audio/AudioService.cpp b/engine/src/hikari/client/audio/AudioService.cpp index 30508d2f..ebf41cbc 100644 --- a/engine/src/hikari/client/audio/AudioService.cpp +++ b/engine/src/hikari/client/audio/AudioService.cpp @@ -114,14 +114,21 @@ namespace hikari { } void AudioService::mute() { - mutedFlag = false; + mutedFlag = true; - // stopAllSamples(); - // stopMusic(); + if(library->isEnabled()) { + library->setMusicVolume(getMusicVolume()); + library->setSampleVolume(getSampleVolume()); + } } void AudioService::unmute() { - mutedFlag = true; + mutedFlag = false; + + if(library->isEnabled()) { + library->setMusicVolume(getMusicVolume()); + library->setSampleVolume(getSampleVolume()); + } } bool AudioService::isMuted() const { From 57c5fb9ce499025da8eb83b243e3f6f2361bd13c Mon Sep 17 00:00:00 2001 From: zackhehuman Date: Mon, 14 Apr 2014 09:00:19 -0700 Subject: [PATCH 2/3] Fixed weapon sound bug There was a bug that even if you didn't have enough energy to fire a weapon it would still play the sound. --- engine/src/hikari/client/game/GamePlayState.cpp | 13 ++++++++----- engine/src/hikari/client/game/objects/Hero.cpp | 1 - 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/engine/src/hikari/client/game/GamePlayState.cpp b/engine/src/hikari/client/game/GamePlayState.cpp index 3c83cca4..1dffa7ba 100644 --- a/engine/src/hikari/client/game/GamePlayState.cpp +++ b/engine/src/hikari/client/game/GamePlayState.cpp @@ -1242,6 +1242,10 @@ namespace hikari { // Use up the weapon energy gp->setWeaponEnergy(currentWeapon, weaponEnergy - weapon->getUsageCost()); + if(auto sound = audioService.lock()) { + sound->playSample(weapon->getUsageSound()); + } + HIKARI_LOG(debug4) << "Hero's shot count: " << hero->getActiveShotCount(); } } @@ -1257,14 +1261,13 @@ namespace hikari { if(auto enemyGoPtr = possibleEnemyPtr.lock()) { if(std::shared_ptr enemy = std::static_pointer_cast(enemyGoPtr)) { enemy->observeShot(shot); + + if(auto sound = audioService.lock()) { + sound->playSample(weapon->getUsageSound()); + } } } } - - if(auto sound = audioService.lock()) { - sound->playSample(weapon->getUsageSound()); - } - } else { HIKARI_LOG(debug4) << "Tried to fire weapon with bad ID (" << eventData->getWeaponId() << ")"; } diff --git a/engine/src/hikari/client/game/objects/Hero.cpp b/engine/src/hikari/client/game/objects/Hero.cpp index eaffd364..22bd9944 100644 --- a/engine/src/hikari/client/game/objects/Hero.cpp +++ b/engine/src/hikari/client/game/objects/Hero.cpp @@ -8,7 +8,6 @@ #include "hikari/client/game/events/EventData.hpp" #include "hikari/client/game/events/EntityDeathEventData.hpp" #include "hikari/client/game/events/EntityStateChangeEventData.hpp" -#include "hikari/client/game/events/WeaponFireEventData.hpp" #include "hikari/core/game/Animation.hpp" #include "hikari/core/game/map/Room.hpp" #include "hikari/core/math/NESNumber.hpp" From 8b1b4fd298edde95b3a354fe823edc0de8425888 Mon Sep 17 00:00:00 2001 From: zackhehuman Date: Mon, 14 Apr 2014 15:32:24 -0700 Subject: [PATCH 3/3] Fixed bug when shooting weapon and run out of energy If when you run out of energy you can no longer fire a weapon. There was a bug that caused the weapon sound to still play even though no projectile was created. This is fixed now. --- engine/include/hikari/client/game/objects/Hero.hpp | 2 ++ engine/src/hikari/client/game/GamePlayState.cpp | 7 ++++++- engine/src/hikari/client/game/objects/Hero.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/engine/include/hikari/client/game/objects/Hero.hpp b/engine/include/hikari/client/game/objects/Hero.hpp index 9633fc5f..3bec41af 100644 --- a/engine/include/hikari/client/game/objects/Hero.hpp +++ b/engine/include/hikari/client/game/objects/Hero.hpp @@ -45,6 +45,7 @@ namespace hikari { bool isUnderWater; bool wasUnderWaterLastFrame; + bool hasAvailableWeaponEnergy; #ifdef HIKARI_DEBUG_HERO_PHYSICS int countAscendingFrames; @@ -219,6 +220,7 @@ namespace hikari { bool isVulnerable(); bool isNowShooting(); bool isOnGround(); + void setHasAvailableWeaponEnergy(bool hasEnergy); virtual void update(float dt); virtual void render(sf::RenderTarget &target); diff --git a/engine/src/hikari/client/game/GamePlayState.cpp b/engine/src/hikari/client/game/GamePlayState.cpp index 1dffa7ba..b6f15cc0 100644 --- a/engine/src/hikari/client/game/GamePlayState.cpp +++ b/engine/src/hikari/client/game/GamePlayState.cpp @@ -1245,7 +1245,7 @@ namespace hikari { if(auto sound = audioService.lock()) { sound->playSample(weapon->getUsageSound()); } - + HIKARI_LOG(debug4) << "Hero's shot count: " << hero->getActiveShotCount(); } } @@ -1882,6 +1882,11 @@ namespace hikari { index++; } + if(auto gp = gamePlayState.gameProgress.lock()) { + int currentWeaponEnergy = gp->getWeaponEnergy(gp->getCurrentWeapon()); + gamePlayState.hero->setHasAvailableWeaponEnergy(currentWeaponEnergy); + } + gamePlayState.hero->update(dt); // diff --git a/engine/src/hikari/client/game/objects/Hero.cpp b/engine/src/hikari/client/game/objects/Hero.cpp index 22bd9944..74a81fbb 100644 --- a/engine/src/hikari/client/game/objects/Hero.cpp +++ b/engine/src/hikari/client/game/objects/Hero.cpp @@ -39,6 +39,7 @@ namespace hikari { , isInvincible(false) , isUnderWater(false) , wasUnderWaterLastFrame(false) + , hasAvailableWeaponEnergy(true) , climbableRegion(0, 0, 0, 0) , actionController(nullptr) , mobilityState(nullptr) @@ -241,6 +242,10 @@ namespace hikari { return body.isOnGround(); } + void Hero::setHasAvailableWeaponEnergy(bool hasEnergy) { + hasAvailableWeaponEnergy = hasEnergy; + } + void Hero::playAnimation(float dt) { const auto & animSprite = getAnimatedSprite(); @@ -527,7 +532,7 @@ namespace hikari { auto const * controller = hero.actionController.get(); // TODO: Actually fix this to use a real cooldown - if(controller->shouldShootWeapon()) { + if(controller->shouldShootWeapon() && hero.hasAvailableWeaponEnergy) { cooldownTimer = cooldown; hero.fireWeapon(); } @@ -565,7 +570,7 @@ namespace hikari { if(hero.actionController) { auto const * controller = hero.actionController.get(); - if(controller->shouldShootWeapon() && hero.canFireWeapon() && !hero.isSliding) { + if(controller->shouldShootWeapon() && hero.canFireWeapon() && !hero.isSliding && hero.hasAvailableWeaponEnergy) { hero.requestShootingStateChange(std::unique_ptr(new IsShootingState(hero))); return ShootingState::NEXT; }