Skip to content

Commit

Permalink
Merge pull request #172 from zackthehuman/master
Browse files Browse the repository at this point in the history
Audio/volume and shooting sound bug. Closes #172 and progress on #156.
  • Loading branch information
zackthehuman committed Apr 15, 2014
2 parents 62db2e6 + 8b1b4fd commit 6444eda
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions engine/include/hikari/client/game/objects/Hero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace hikari {

bool isUnderWater;
bool wasUnderWaterLastFrame;
bool hasAvailableWeaponEnergy;

#ifdef HIKARI_DEBUG_HERO_PHYSICS
int countAscendingFrames;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions engine/src/hikari/client/audio/AudioService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 13 additions & 5 deletions engine/src/hikari/client/game/GamePlayState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -1257,14 +1261,13 @@ namespace hikari {
if(auto enemyGoPtr = possibleEnemyPtr.lock()) {
if(std::shared_ptr<Enemy> enemy = std::static_pointer_cast<Enemy>(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() << ")";
}
Expand Down Expand Up @@ -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);

//
Expand Down
10 changes: 7 additions & 3 deletions engine/src/hikari/client/game/objects/Hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -40,6 +39,7 @@ namespace hikari {
, isInvincible(false)
, isUnderWater(false)
, wasUnderWaterLastFrame(false)
, hasAvailableWeaponEnergy(true)
, climbableRegion(0, 0, 0, 0)
, actionController(nullptr)
, mobilityState(nullptr)
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<ShootingState>(new IsShootingState(hero)));
return ShootingState::NEXT;
}
Expand Down

0 comments on commit 6444eda

Please sign in to comment.