From ea78916cc43fe67690f2f92d88ac4a8b0e9857d8 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 5 Feb 2021 17:38:30 -0500 Subject: Added little bobbing "next message" arrow --- src/input_system.cpp | 5 +++-- src/message_system.cpp | 24 +++++++++++++++++++++++- src/message_system.h | 10 +++++++++- src/renderer.cpp | 15 +++++++++++++++ src/renderer.h | 1 + 5 files changed, 51 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/input_system.cpp b/src/input_system.cpp index e8b2bb9..b70b377 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp @@ -32,8 +32,9 @@ void InputSystem::tick(double dt) { } else { game_.getSystem().displayCutsceneBars(); }*/ - //game_.getSystem().displayMessage("Some people always try to avoid fighting when there are enemies around. You know the type, right? They use the dash ability to zoom right by. I guess you could say they're followers of \"peace at any price\".", SpeakerType::Woman); - game_.getSystem().displayMessage("Lucas. You're awful at hide-and-seek, you know that? Try harder.", "Kumatora", SpeakerType::Woman); + game_.getSystem().displayMessage("Some people always try to avoid fighting when there are enemies around. You know the type, right? They use the dash ability to zoom right by. I guess you could say they're followers of \"peace at any price\".", "Sparrow", SpeakerType::Woman); + //game_.getSystem().displayMessage("Lucas. You're awful at hide-and-seek, you know that? Try harder.", "Kumatora", SpeakerType::Woman); + //game_.getSystem().displayMessage("Hi Tooth! I hope you're having a good day.", "Lucas", SpeakerType::Boy); } else if (e.key.keysym.sym == SDLK_b) { // TODO: Remove this, it's just for testing. game_.getSystem().advanceText(); diff --git a/src/message_system.cpp b/src/message_system.cpp index 08ef799..0b0d53e 100644 --- a/src/message_system.cpp +++ b/src/message_system.cpp @@ -3,7 +3,7 @@ #include "util.h" const int CHARS_TO_REVEAL = 1; -const int CHARS_PER_BEEP = 10; +const int CHARS_PER_BEEP = 8; void MessageSystem::tick(double dt) { if (barsState_ == BarsState::Opening || barsState_ == BarsState::Closing) { @@ -59,6 +59,27 @@ void MessageSystem::tick(double dt) { linesToShow_.push_back(MessageLine { .text = lines_.front() }); lines_.pop_front(); + } else { + showNextArrow_ = true; + } + } + } + + if (showNextArrow_) { + nextArrowBobTimer_.accumulate(dt); + while (nextArrowBobTimer_.step()) { + if (nextArrowBobDown_) { + nextArrowBobPos_++; + + if (nextArrowBobPos_ >= 4) { + nextArrowBobDown_ = false; + } + } else { + nextArrowBobPos_--; + + if (nextArrowBobPos_ <= 0) { + nextArrowBobDown_ = true; + } } } } @@ -172,6 +193,7 @@ void MessageSystem::advanceText() { } lines_.pop_front(); + showNextArrow_ = false; if (lines_.empty()) { linesToShow_.clear(); diff --git a/src/message_system.h b/src/message_system.h index 18dd299..93ca087 100644 --- a/src/message_system.h +++ b/src/message_system.h @@ -53,6 +53,10 @@ public: const std::string& getSpeaker() const { return speakerName_; } + bool isNextArrowShowing() const { return showNextArrow_; } + + int getNextArrowBob() const { return nextArrowBobPos_; } + private: enum class BarsState { @@ -70,7 +74,11 @@ private: std::string speakerName_; std::list lines_; std::list linesToShow_; - Timer textAdvTimer_ { 10 }; + Timer textAdvTimer_ { 15 }; + bool showNextArrow_ = false; + int nextArrowBobPos_ = 0; + bool nextArrowBobDown_ = true; + Timer nextArrowBobTimer_ { 125 }; }; #endif /* end of include guard: MESSAGE_SYSTEM_H_DE10D011 */ diff --git a/src/renderer.cpp b/src/renderer.cpp index ae18851..4f5b4ff 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -205,6 +205,21 @@ void Renderer::render(Game& game) { lineIndex++; } + + // 216, 138, 142 + if (game.getSystem().isNextArrowShowing()) { + if (advMsgArrowTex_ == -1) { + advMsgArrowTex_ = loadImageFromFile("../res/advance_text_arrow.png"); + } + + SDL_Rect destRect { + 216, + 138 + game.getSystem().getNextArrowBob(), + 16, + 16 }; + + SDL_RenderCopy(ren_.get(), textures_.at(advMsgArrowTex_).get(), nullptr, &destRect); + } } } diff --git a/src/renderer.h b/src/renderer.h index 4195d11..b812429 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -150,6 +150,7 @@ private: MessageCache messageLines_[2]; int speakerHeaderTex_ = -1; MessageCache speakerHeaderLine_; + int advMsgArrowTex_ = -1; }; #endif /* end of include guard: RENDERER_H_6A58EC30 */ -- cgit 1.4.1