From 042da1570181dc80ee76860582f6a3c97641c14a Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 14 Mar 2022 08:32:39 -0400 Subject: fmod splash screen --- src/main.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index ec253ee..4ae11d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,12 @@ #include "game.h" #include "renderer.h" +enum class TitleState { + FadeIn, + Sustain, + FadeOut +}; + int main(int, char**) { std::random_device randomEngine; @@ -17,6 +23,14 @@ int main(int, char**) Game game(rng, muxer); + constexpr int titleFadeLen = 3000; + bool doneTitles = false; + int titleNum = 0; + TitleState titleState = TitleState::FadeIn; + Interpolation titleFade; + Timer titleSustain(3000); + titleFade.start(titleFadeLen); + size_t lastTime = SDL_GetTicks(); while (!game.quit) { @@ -24,9 +38,58 @@ int main(int, char**) size_t frameTime = currentTime - lastTime; lastTime = currentTime; - game.update(frameTime); - renderer.renderGame(game, true); - muxer.update(); + if (doneTitles) { + game.update(frameTime); + renderer.renderGame(game, true); + muxer.update(); + } else { + SDL_Event e; + + while (SDL_PollEvent(&e)); + + switch (titleState) { + case TitleState::FadeIn: { + titleFade.tick(frameTime); + if (titleFade.isComplete()) { + titleState = TitleState::Sustain; + titleSustain.reset(); + } + + renderer.renderTitle(titleNum, titleFade.getProgress(0, 1)); + + break; + } + case TitleState::Sustain: { + titleSustain.accumulate(frameTime); + const Uint8* state = SDL_GetKeyboardState(NULL); + if (state[SDL_SCANCODE_SPACE] || titleSustain.step()) { + titleState = TitleState::FadeOut; + titleFade.start(titleFadeLen); + } + + renderer.renderTitle(titleNum, 1); + + break; + } + case TitleState::FadeOut: { + titleFade.tick(frameTime); + renderer.renderTitle(titleNum, titleFade.getProgress(1, 0)); + + if (titleFade.isComplete()) { + titleNum++; + + if (titleNum < NUM_TITLES) { + titleState = TitleState::FadeIn; + titleFade.start(titleFadeLen); + } else { + doneTitles = true; + } + } + + break; + } + } + } } } catch (const sdl_error& ex) { -- cgit 1.4.1