From e5fc5bccff29bce3de09209707cf8dbe14a80b35 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 20 Mar 2022 20:14:46 -0400 Subject: control instructions --- res/help.png | Bin 0 -> 4828 bytes res/help.psd | Bin 0 -> 124984 bytes src/game.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/game.h | 10 ++++++++++ src/renderer.cpp | 13 ++++++++++++- src/renderer.h | 1 + 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 res/help.png create mode 100644 res/help.psd diff --git a/res/help.png b/res/help.png new file mode 100644 index 0000000..4b6ac6e Binary files /dev/null and b/res/help.png differ diff --git a/res/help.psd b/res/help.psd new file mode 100644 index 0000000..a3d034b Binary files /dev/null and b/res/help.psd differ diff --git a/src/game.cpp b/src/game.cpp index 39828f4..98745f4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -18,6 +18,7 @@ Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : { losePopLampTimer.accumulate(losePopLampTimer.getDt()); initialFade.start(1000); + helpProgress.start(1500); do { loadMap(); @@ -954,6 +955,44 @@ void Game::updatePlaying(size_t frameTime) { } } + switch (helpState) { + case HelpState::PreWait: { + helpProgress.tick(frameTime); + if (helpProgress.isComplete()) { + helpState = HelpState::FadeIn; + helpProgress.start(1000); + } + break; + } + case HelpState::FadeIn: { + helpProgress.tick(frameTime); + if (helpProgress.isComplete()) { + helpState = HelpState::Hold; + helpProgress.start(3000); + } + break; + } + case HelpState::Hold: { + helpProgress.tick(frameTime); + if (helpProgress.isComplete()) { + helpState = HelpState::FadeOut; + helpProgress.start(1000); + } + break; + } + case HelpState::FadeOut: { + helpProgress.tick(frameTime); + if (helpProgress.isComplete()) { + helpState = HelpState::Done; + } + break; + } + case HelpState::Done: { + // Do nothing. + break; + } + } + switch (signInstructionState) { case SignInstructionState::Hidden: { auto [lookX, lookY] = coordInDirection(player_x, player_y, playerAnim.getDirection()); diff --git a/src/game.h b/src/game.h index 914df53..5bdc245 100644 --- a/src/game.h +++ b/src/game.h @@ -30,6 +30,14 @@ enum class LoseState { Done }; +enum class HelpState { + PreWait, + FadeIn, + Hold, + FadeOut, + Done +}; + struct Input { bool left = false; bool right = false; @@ -72,6 +80,8 @@ public: Interpolation initialFade; bool startedMusic = false; + HelpState helpState = HelpState::PreWait; + Interpolation helpProgress; Map map; std::list kickups; diff --git a/src/renderer.cpp b/src/renderer.cpp index 5d6ac08..2fc6023 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -120,6 +120,7 @@ void Renderer::loadAllTextures() { loadTextureFromFile("lamp.png", lamp_); loadTextureFromFile("read_instruction.png", readInstruction_); loadTextureFromFile("menu.png", menuBg_); + loadTextureFromFile("help.png", help_); loadTextureFromFile("title0.png", titles_[0]); SDL_QueryTexture(titles_[0].get(), nullptr, nullptr, &titleWidths_[0], &titleHeights_[0]); @@ -424,7 +425,17 @@ void Renderer::renderGame( SDL_SetRenderDrawColor(ren_.get(), 0, 0, 0, 0); SDL_RenderClear(ren_.get()); - if (game.signInstructionState != SignInstructionState::Hidden) { + if (game.helpState == HelpState::FadeIn || game.helpState == HelpState::Hold || game.helpState == HelpState::FadeOut) { + int instOpacity = 255; + if (game.helpState == HelpState::FadeIn) { + instOpacity = game.helpProgress.getProgress(0, 255); + } else if (game.helpState == HelpState::FadeOut) { + instOpacity = game.helpProgress.getProgress(255, 0); + } + + SDL_SetTextureAlphaMod(help_.get(), instOpacity); + SDL_RenderCopy(ren_.get(), help_.get(), nullptr, nullptr); + } else if (game.signInstructionState != SignInstructionState::Hidden) { int instOpacity = 255; if (game.signInstructionState == SignInstructionState::FadingIn) { instOpacity = game.signFade.getProgress(0, 255); diff --git a/src/renderer.h b/src/renderer.h index f650736..549f64a 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -187,6 +187,7 @@ private: texture_ptr lamp_; texture_ptr readInstruction_; texture_ptr menuBg_; + texture_ptr help_; std::array titles_; std::array titleWidths_; -- cgit 1.4.1