diff options
Diffstat (limited to 'src/character_system.cpp')
-rw-r--r-- | src/character_system.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
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) { | |||
130 | if (pLoc != sprite.loc) { | 130 | if (pLoc != sprite.loc) { |
131 | game_.getSystem<TransformSystem>().moveSprite(spriteId, pLoc); | 131 | game_.getSystem<TransformSystem>().moveSprite(spriteId, pLoc); |
132 | 132 | ||
133 | if (sprite.characterState == CharacterState::Running) { | ||
134 | vec2i newMapTileLoc = pLoc / map.getTileSize(); | ||
135 | StepType newTileStep = map.getStepType(newMapTileLoc.x(), newMapTileLoc.y()); | ||
136 | if (sprite.stepType != newTileStep) { | ||
137 | stopRunningSound(sprite); | ||
138 | |||
139 | sprite.stepType = newTileStep; | ||
140 | |||
141 | if (newTileStep != StepType::none) { | ||
142 | sprite.runningSfxChannel = game_.getMixer().loopSound(runningSfxForStepType(newTileStep)); | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
133 | for (int followerId : sprite.followers) { | 147 | for (int followerId : sprite.followers) { |
134 | Sprite& pNext = game_.getSprite(followerId); | 148 | Sprite& pNext = game_.getSprite(followerId); |
135 | const Movement& posdir = pNext.trail.front(); | 149 | const Movement& posdir = pNext.trail.front(); |
@@ -180,6 +194,7 @@ void CharacterSystem::endCrouch(int spriteId) { | |||
180 | void CharacterSystem::stopRunning(int spriteId) { | 194 | void CharacterSystem::stopRunning(int spriteId) { |
181 | Sprite& sprite = game_.getSprite(spriteId); | 195 | Sprite& sprite = game_.getSprite(spriteId); |
182 | setPartyState(spriteId, CharacterState::Still); | 196 | setPartyState(spriteId, CharacterState::Still); |
197 | stopRunningSound(sprite); | ||
183 | 198 | ||
184 | // Double the movement buffer for the followers. | 199 | // Double the movement buffer for the followers. |
185 | for (int followerId : sprite.followers) { | 200 | for (int followerId : sprite.followers) { |
@@ -232,3 +247,11 @@ void CharacterSystem::setPartyState(int spriteId, CharacterState state) { | |||
232 | game_.getSystem<AnimationSystem>().setSpriteAnimation(followerId, animName); | 247 | game_.getSystem<AnimationSystem>().setSpriteAnimation(followerId, animName); |
233 | } | 248 | } |
234 | } | 249 | } |
250 | |||
251 | void CharacterSystem::stopRunningSound(Sprite& sprite) { | ||
252 | sprite.stepType = StepType::none; | ||
253 | if (sprite.runningSfxChannel != -1) { | ||
254 | game_.getMixer().stopChannel(sprite.runningSfxChannel); | ||
255 | sprite.runningSfxChannel = -1; | ||
256 | } | ||
257 | } | ||