From dab96b810691c26e29fef92d88c828a311be3e9d Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 3 Feb 2021 17:11:46 -0500 Subject: Added running sounds --- src/character_system.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/character_system.cpp') diff --git a/src/character_system.cpp b/src/character_system.cpp index ac0f01a..2f26aee 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp @@ -130,6 +130,20 @@ void CharacterSystem::tick(double dt) { if (pLoc != sprite.loc) { game_.getSystem().moveSprite(spriteId, pLoc); + if (sprite.characterState == CharacterState::Running) { + vec2i newMapTileLoc = pLoc / map.getTileSize(); + StepType newTileStep = map.getStepType(newMapTileLoc.x(), newMapTileLoc.y()); + if (sprite.stepType != newTileStep) { + stopRunningSound(sprite); + + sprite.stepType = newTileStep; + + if (newTileStep != StepType::none) { + sprite.runningSfxChannel = game_.getMixer().loopSound(runningSfxForStepType(newTileStep)); + } + } + } + for (int followerId : sprite.followers) { Sprite& pNext = game_.getSprite(followerId); const Movement& posdir = pNext.trail.front(); @@ -180,6 +194,7 @@ void CharacterSystem::endCrouch(int spriteId) { void CharacterSystem::stopRunning(int spriteId) { Sprite& sprite = game_.getSprite(spriteId); setPartyState(spriteId, CharacterState::Still); + stopRunningSound(sprite); // Double the movement buffer for the followers. for (int followerId : sprite.followers) { @@ -232,3 +247,11 @@ void CharacterSystem::setPartyState(int spriteId, CharacterState state) { game_.getSystem().setSpriteAnimation(followerId, animName); } } + +void CharacterSystem::stopRunningSound(Sprite& sprite) { + sprite.stepType = StepType::none; + if (sprite.runningSfxChannel != -1) { + game_.getMixer().stopChannel(sprite.runningSfxChannel); + sprite.runningSfxChannel = -1; + } +} -- cgit 1.4.1