diff --git a/src/states/EndingState.cpp b/src/states/EndingState.cpp index addf934..1429a8d 100644 --- a/src/states/EndingState.cpp +++ b/src/states/EndingState.cpp @@ -3,9 +3,12 @@ #include #include +int score = 0; + void EndingState::init() { SDL_ShowCursor(SDL_ENABLE); std::cout << "Ending state initialized\n"; + score = SDL_GetTicks() / 100; } void EndingState::handleEvents(SDL_Event& event) { @@ -33,5 +36,8 @@ void EndingState::render(SDL_Renderer* renderer, double deltaTime) { drawText(renderer, font, "GAME OVER", WINDOW_WIDTH / 2 - 100, WINDOW_HEIGHT / 2 - 50, {255, 0, 0, SDL_ALPHA_OPAQUE}); + drawText(renderer, font, "Score: " + std::to_string(score), + WINDOW_WIDTH / 2 - 120, WINDOW_HEIGHT / 2, {255, 255, 255, SDL_ALPHA_OPAQUE}); + SDL_RenderPresent(renderer); } diff --git a/src/states/InGameState.cpp b/src/states/InGameState.cpp index afbc281..3d98124 100644 --- a/src/states/InGameState.cpp +++ b/src/states/InGameState.cpp @@ -138,6 +138,23 @@ void InGameState::renderHUD(SDL_Renderer* renderer, SDL_Texture* heart) const { for (int i = 0; i < this->player.health; i++) { drawTexture(renderer, heart, 10 + i * 30, 10, 24, 24); } + + TTF_Font *font = TTF_OpenFont("./res/font.ttf", 24); + int score = SDL_GetTicks() / 100; + + int marginL = 90; + if (score > 9) marginL = 70; + if (score > 99) marginL = 50; + if (score > 999) marginL = 20; + if (score > 9999) marginL = 0; + + SDL_Rect highRect = {WINDOW_WIDTH - 120 + marginL - 10, 0, 120, 40}; + SDL_RenderFillRect(renderer, &highRect); + + + drawText(renderer, font, std::to_string(score),WINDOW_WIDTH - 120 + marginL, 10, + {255, 255, 255, SDL_ALPHA_OPAQUE}); + TTF_CloseFont(font); } void InGameState::init() {