From a0705fcd7b51401b45ff9960a81c08520f142230 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 17 Apr 2022 11:04:00 +0200 Subject: Added some details to title screen --- Screen.h | 1 + TitleScreen.cpp | 21 ++++++++++++++++++++- TitleScreen.h | 10 +++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Screen.h b/Screen.h index d875165..6700acc 100644 --- a/Screen.h +++ b/Screen.h @@ -3,6 +3,7 @@ struct Screen { + virtual ~Screen() = default; virtual void update(float dt) = 0; virtual void draw() = 0; }; diff --git a/TitleScreen.cpp b/TitleScreen.cpp index d109003..9bdd47c 100644 --- a/TitleScreen.cpp +++ b/TitleScreen.cpp @@ -10,10 +10,27 @@ extern Game g_game; +static constexpr const char* TITLE {"Generic Bullet HELL"}; +static constexpr const char* PRESS {"Press SPACE to start"}; + + +TitleScreen::TitleScreen() : + m_blink {0} +{ + const int screen_width = GetScreenWidth(); + const int title_width = MeasureText(TITLE, FONT_SIZE); + const int press_width = MeasureText(PRESS, FONT_SIZE); + m_title_x = (screen_width - title_width) / 2; + m_press_x = (screen_width - press_width) / 2; +} + void TitleScreen::update(const float dt) { + m_blink += dt; + if (m_blink > 2 * INTERVAL) + m_blink -= 2 * INTERVAL; if (IsKeyPressed(KEY_SPACE)) g_game.set(std::make_unique()); } @@ -22,5 +39,7 @@ TitleScreen::update(const float dt) void TitleScreen::draw() { - DrawText("Bullet HELL 2022", 190, 200, 20, LIGHTGRAY); + DrawText(TITLE, m_title_x, 160, FONT_SIZE, LIGHTGRAY); + if (m_blink < INTERVAL) + DrawText(PRESS, m_press_x, 180, FONT_SIZE, GRAY); } diff --git a/TitleScreen.h b/TitleScreen.h index a0ec64f..2839a9e 100644 --- a/TitleScreen.h +++ b/TitleScreen.h @@ -3,8 +3,16 @@ #include "Screen.h" -struct TitleScreen : public Screen +class TitleScreen : public Screen { +public: + TitleScreen(); void update(float dt) override; void draw() override; +private: + static constexpr int FONT_SIZE {20}; + static constexpr float INTERVAL {0.7f}; + int m_title_x; + int m_press_x; + float m_blink; }; -- cgit v1.1