diff --git a/src/main.cpp b/src/main.cpp index b9144b7..6e626a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "utils.hpp" // Color and formatting macros for terminal output @@ -114,7 +115,8 @@ int main() { std::this_thread::sleep_for(std::chrono::milliseconds(200)); tcflush(STDIN_FILENO, TCIFLUSH); - auto last_tick = std::chrono::steady_clock::now(); + auto game_start = std::chrono::steady_clock::now(); + auto last_tick = game_start; bool updateUI = true; struct pollfd fds[1] = {{STDIN_FILENO, POLLIN, 0}}; while (true) { @@ -143,7 +145,13 @@ int main() { } if (updateUI) { - std::cout << "\r" ERASE_LINE << CLR_SCORE << "Score: " << formatWithCommas(score) << CLR_RESET << " | High: " << formatWithCommas(highscore) << " " + auto current_now = std::chrono::steady_clock::now(); + double duration_sec = std::chrono::duration(current_now - game_start).count(); + double cps = (duration_sec > 0.0) ? (score / duration_sec) : 0.0; + + std::cout << "\r" ERASE_LINE << CLR_SCORE << "Score: " << formatWithCommas(score) << CLR_RESET + << " | High: " << formatWithCommas(highscore) + << " | CPS: " << std::fixed << std::setprecision(1) << cps << " " << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") << (score > initialHighscore ? " NEW BEST! 🥳 (was " + formatWithCommas(initialHighscore) + ")" : "") << std::flush;