From 1811ec874d235d44a143c39307ac984b87fe3a8a Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 26 Apr 2022 11:37:44 +0200 Subject: Implemented simple scoring system --- OverScreen.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'OverScreen.cpp') diff --git a/OverScreen.cpp b/OverScreen.cpp index dcf5866..a465464 100644 --- a/OverScreen.cpp +++ b/OverScreen.cpp @@ -9,7 +9,11 @@ #include "TitleScreen.h" -static constexpr const char* DIED {"The Bone is Gone"}; +static constexpr const char* DIED {"Game Over"}; +static constexpr const char* LABEL {"Your Score: "}; + + +static const char* points_text(std::shared_ptr stats); OverScreen::OverScreen(std::shared_ptr stats) : @@ -17,7 +21,12 @@ OverScreen::OverScreen(std::shared_ptr stats) : { const int screen_width = GetScreenWidth(); const int died_width = MeasureText(DIED, 20); + const int label_width = MeasureText(LABEL, 20); + const int score_width = MeasureText(points_text(m_stats), 20); + const int label_and_score = label_width + score_width; m_died_x = (screen_width - died_width) / 2; + m_label_x = (screen_width - label_and_score) / 2; + m_score_x = m_label_x + label_width; m_flash.start(); } @@ -36,5 +45,16 @@ OverScreen::draw() { ClearBackground(BLACK); DrawText(DIED, m_died_x, 160, 20, RED); + DrawText(LABEL, m_label_x, 180, 20, GRAY); + DrawText(points_text(m_stats), m_score_x, 180, 20, GOLD); m_flash.draw(); } + + +const char* +points_text(std::shared_ptr stats) +{ + if (stats->lifes > 0) + return TextFormat("%d + %d", stats->points, 1000 * stats->lifes); + return TextFormat("%d", stats->points); +} -- cgit v1.1