Skip to content

Commit

Permalink
Fixed bug when shooting weapon and run out of energy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zackthehuman committed Apr 14, 2014
1 parent 57c5fb9 commit 8b1b4fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 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
7 changes: 6 additions & 1 deletion engine/src/hikari/client/game/GamePlayState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ namespace hikari {
if(auto sound = audioService.lock()) {
sound->playSample(weapon->getUsageSound());
}

HIKARI_LOG(debug4) << "Hero's shot count: " << hero->getActiveShotCount();
}
}
Expand Down Expand Up @@ -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);

//
Expand Down
9 changes: 7 additions & 2 deletions engine/src/hikari/client/game/objects/Hero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,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 @@ -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();

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

0 comments on commit 8b1b4fd

Please sign in to comment.