#include "OverScreen.h" #include #include #include "Globals.h" #include "Stats.h" #include "TitleScreen.h" 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) : m_stats {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(); } void OverScreen::update(const float dt) { m_flash.update(dt); if (IsKeyPressed(KEY_SPACE)) g_game.set(std::make_unique()); } void 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); }