From 2c75d95ddf849996bfc18267a9eecb4d0f4e1916 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 16 Mar 2022 15:30:37 -0400 Subject: signs can be read now! --- src/game.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 301447f..5838528 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -7,9 +7,10 @@ #include "renderer.h" #include "consts.h" -Game::Game(std::mt19937& rng, Muxer& muxer) : +Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : rng(rng), - muxer(muxer) + muxer(muxer), + sign(renderer.getFont()) { losePopLampTimer.accumulate(losePopLampTimer.getDt()); @@ -631,7 +632,7 @@ void Game::performDash() { } } -void Game::update(size_t frameTime) { +void Game::updatePlaying(size_t frameTime) { SDL_Event e; while (SDL_PollEvent(&e)) @@ -666,8 +667,22 @@ void Game::update(size_t frameTime) { { if (losing == LoseState::None) { + auto [lookX, lookY] = coordInDirection(player_x, player_y, playerAnim.getDirection()); + MapData& lookTile = map.at(lookX, lookY); if (moving) { - queueDash = true; + if (!lookTile.sign) { + queueDash = true; + } + } else if (lookTile.sign) { + if (lookTile.text.empty()) { + int lineToRead = nextSignIndex++; + if (nextSignIndex >= signTexts.size()) { + nextSignIndex = 0; + } + lookTile.text = signTexts[lineToRead]; + } + + sign.displayMessage(lookTile.text); } else { performDash(); } @@ -815,7 +830,7 @@ void Game::update(size_t frameTime) { switch (signInstructionState) { case SignInstructionState::Hidden: { auto [lookX, lookY] = coordInDirection(player_x, player_y, playerAnim.getDirection()); - if (map.at(lookX, lookY).sign) { + if (losing == LoseState::None && map.at(lookX, lookY).sign) { signInstructionState = SignInstructionState::FadingIn; signFade.start(1000); } @@ -913,3 +928,11 @@ void Game::update(size_t frameTime) { playerAnim.update(frameTime); } + +void Game::update(size_t frameTime) { + if (sign.signDisplayState != SignInstructionState::Hidden) { + sign.update(frameTime, *this); + } else { + updatePlaying(frameTime); + } +} -- cgit 1.4.1