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/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 { diff --git a/engine/src/hikari/client/game/GamePlayState.cpp b/engine/src/hikari/client/game/GamePlayState.cpp index 3c83cca4..b6f15cc0 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() << ")"; } @@ -1879,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 eaffd364..74a81fbb 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" @@ -40,6 +39,7 @@ namespace hikari { , isInvincible(false) , isUnderWater(false) , wasUnderWaterLastFrame(false) + , hasAvailableWeaponEnergy(true) , climbableRegion(0, 0, 0, 0) , actionController(nullptr) , mobilityState(nullptr) @@ -242,6 +242,10 @@ namespace hikari { return body.isOnGround(); } + void Hero::setHasAvailableWeaponEnergy(bool hasEnergy) { + hasAvailableWeaponEnergy = hasEnergy; + } + void Hero::playAnimation(float dt) { const auto & animSprite = getAnimatedSprite(); @@ -528,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(); } @@ -566,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; }