From 514b240348a7c401fa6725ae74540d5f3ee29cfb Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 19 Mar 2022 21:07:50 -0400 Subject: added fade in to new game and fixed music on new game --- src/game.cpp | 14 ++++++++++++++ src/game.h | 6 +++++- src/muxer.cpp | 14 +++++++++----- src/muxer.h | 2 ++ src/renderer.cpp | 6 ++++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 72bcbfa..caa465c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -16,6 +16,7 @@ Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : sign(renderer.getFont()) { losePopLampTimer.accumulate(losePopLampTimer.getDt()); + initialFade.start(1000); do { loadMap(); @@ -846,6 +847,19 @@ void Game::updatePlaying(size_t frameTime) { switch (losing) { + case LoseState::NewGame: + { + if (!startedMusic) { + startedMusic = true; + muxer.startMusic(); + } + initialFade.tick(frameTime); + if (initialFade.isComplete()) { + losing = LoseState::None; + } + break; + } + case LoseState::None: { if (moving) { diff --git a/src/game.h b/src/game.h index 839be67..3b092dd 100644 --- a/src/game.h +++ b/src/game.h @@ -21,6 +21,7 @@ constexpr int TilesetIndex(int x, int y) { } enum class LoseState { + NewGame, None, PoppingLamps, PoppingPlayer, @@ -66,7 +67,10 @@ public: bool quit = false; bool quitting = false; // <- whether we will quit after losing, vs starting a new game - LoseState losing = LoseState::None; + LoseState losing = LoseState::NewGame; + + Interpolation initialFade; + bool startedMusic = false; Map map; std::list kickups; diff --git a/src/muxer.cpp b/src/muxer.cpp index c93c45a..6ae6936 100644 --- a/src/muxer.cpp +++ b/src/muxer.cpp @@ -26,11 +26,6 @@ Muxer::Muxer() { FMOD::Studio::Bank* stringsBank = nullptr; ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.strings.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank)); - - FMOD::Studio::EventDescription* exploration_desc = nullptr; - ERRCHECK(system_->getEvent("event:/exploration", &exploration_desc)); - ERRCHECK(exploration_desc->createInstance(&exploration_event_)); - ERRCHECK(exploration_event_->start()); } void Muxer::setPlayerLoc(int x, int y) { @@ -96,6 +91,15 @@ void Muxer::setMusicLevel(int level) { } } +void Muxer::startMusic() { + FMOD::Studio::EventDescription* exploration_desc = nullptr; + ERRCHECK(system_->getEvent("event:/exploration", &exploration_desc)); + ERRCHECK(exploration_desc->createInstance(&exploration_event_)); + ERRCHECK(exploration_event_->start()); + + transition_state_ = TransitionState::Pre; +} + void Muxer::stopMusic() { switch (transition_state_) { case TransitionState::Pre: { diff --git a/src/muxer.h b/src/muxer.h index 9750808..acceca8 100644 --- a/src/muxer.h +++ b/src/muxer.h @@ -34,6 +34,8 @@ public: void setMusicLevel(int level); + void startMusic(); + void stopMusic(); void update(); diff --git a/src/renderer.cpp b/src/renderer.cpp index b24ddbf..b6a9b4a 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -396,6 +396,12 @@ void Renderer::renderGame( SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); + if (game.losing == LoseState::NewGame) { + SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_BLEND); + SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, game.initialFade.getProgress(255, 0)); + SDL_RenderFillRect(ren_.get(), nullptr); + } + texture_ptr overlays( SDL_CreateTexture( ren_.get(), -- cgit 1.4.1