From 3996ccb4e2a0d81500d1b1370b2b97256d1ee465 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 12 Mar 2022 09:53:02 -0500 Subject: added transition and the world music --- src/main.cpp | 8 +++++++- src/muxer.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/muxer.h | 12 ++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index cd1a8c2..1805357 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -419,8 +419,12 @@ void setZoom(Game& game, size_t zoom) game.muxer.setMusicLevel(0); } else if (zoomLevel < 3) { game.muxer.setMusicLevel(1); - } else { + } else if (zoomLevel < 5) { game.muxer.setMusicLevel(2); + } else if (zoomLevel < 7) { + game.muxer.setMusicLevel(3); + } else { + game.muxer.setMusicLevel(4); } } @@ -493,6 +497,7 @@ int main(int, char**) quit = true; } else { losing = LoseState::PoppingLamps; + game.muxer.stopMusic(); } } else if (e.type == SDL_KEYDOWN) { @@ -505,6 +510,7 @@ int main(int, char**) quit = true; } else { losing = LoseState::PoppingLamps; + game.muxer.stopMusic(); } break; diff --git a/src/muxer.cpp b/src/muxer.cpp index 5b09ef8..3450187 100644 --- a/src/muxer.cpp +++ b/src/muxer.cpp @@ -62,9 +62,65 @@ void Muxer::playSoundAtPosition(std::string name, float x, float y) { } void Muxer::setMusicLevel(int level) { - ERRCHECK(exploration_event_->setParameterByName("level", level)); + if (transition_state_ == TransitionState::Pre) { + if (level >= 3) { + transition_state_ = TransitionState::Transition; + ERRCHECK(exploration_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT)); + ERRCHECK(exploration_event_->release()); + + FMOD::Studio::EventDescription* eventDescription = nullptr; + ERRCHECK(system_->getEvent("event:/transition", &eventDescription)); + ERRCHECK(eventDescription->createInstance(&transition_event_)); + ERRCHECK(transition_event_->start()); + } else { + ERRCHECK(exploration_event_->setParameterByName("level", level)); + } + } else if (transition_state_ == TransitionState::Post) { + if (level <= 3) { + ERRCHECK(the_world_event_->setParameterByName("level_full", 0)); + } else { + ERRCHECK(the_world_event_->setParameterByName("level_full", level - 3)); + } + } +} + +void Muxer::stopMusic() { + switch (transition_state_) { + case TransitionState::Pre: { + ERRCHECK(exploration_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT)); + break; + } + case TransitionState::Transition: { + ERRCHECK(transition_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT)); + break; + } + case TransitionState::Post: { + ERRCHECK(the_world_event_->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT)); + break; + } + case TransitionState::Stopped: { + // Do nothing. + break; + } + } + + transition_state_ = TransitionState::Stopped; } void Muxer::update() { + if (transition_state_ == TransitionState::Transition) { + FMOD_STUDIO_PLAYBACK_STATE playbackState; + ERRCHECK(transition_event_->getPlaybackState(&playbackState)); + if (playbackState == FMOD_STUDIO_PLAYBACK_STOPPED) { + transition_state_ = TransitionState::Post; + transition_event_->release(); + + FMOD::Studio::EventDescription* eventDescription = nullptr; + ERRCHECK(system_->getEvent("event:/the_world", &eventDescription)); + ERRCHECK(eventDescription->createInstance(&the_world_event_)); + ERRCHECK(the_world_event_->start()); + } + } + ERRCHECK(system_->update()); } diff --git a/src/muxer.h b/src/muxer.h index f99cce4..b1a5b26 100644 --- a/src/muxer.h +++ b/src/muxer.h @@ -15,6 +15,13 @@ public: using fmod_system_ptr = std::unique_ptr; +enum class TransitionState { + Pre, + Transition, + Post, + Stopped +}; + class Muxer { public: Muxer(); @@ -25,11 +32,16 @@ public: void setMusicLevel(int level); + void stopMusic(); + void update(); private: fmod_system_ptr system_; FMOD::Studio::EventInstance* exploration_event_; + FMOD::Studio::EventInstance* transition_event_; + FMOD::Studio::EventInstance* the_world_event_; + TransitionState transition_state_ = TransitionState::Pre; }; #endif /* end of include guard: MUXER_H_3146C802 */ -- cgit 1.4.1