Add high score
This commit is contained in:
parent
86feca9943
commit
e5dc74257e
@ -3,9 +3,12 @@
|
||||
#include <iostream>
|
||||
#include <SDL_image.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user