summary refs log tree commit diff stats
path: root/src/character_system.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-03 17:11:46 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-03 17:11:46 -0500
commitdab96b810691c26e29fef92d88c828a311be3e9d (patch)
treee906b10f8dbca817e2b65bd14469226c2717a05a /src/character_system.cpp
parentc54dd4fd583f1d00d424590a9f192b2a35ede26b (diff)
downloadtanetane-dab96b810691c26e29fef92d88c828a311be3e9d.tar.gz
tanetane-dab96b810691c26e29fef92d88c828a311be3e9d.tar.bz2
tanetane-dab96b810691c26e29fef92d88c828a311be3e9d.zip
Added running sounds
Diffstat (limited to 'src/character_system.cpp')
-rw-r--r--src/character_system.cpp23
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) {
180void CharacterSystem::stopRunning(int spriteId) { 194void 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
251void 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}