-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreBoard.cpp
57 lines (47 loc) · 1.37 KB
/
ScoreBoard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "ScoreBoard.h"
ScoreBoard::ScoreBoard()
{
}
ScoreBoard::~ScoreBoard()
{
}
void ScoreBoard::render(SDL_Renderer* renderer, TTF_Font* font, std::set<std::pair<std::string, size_t>, classcomp>& scores) const
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
SDL_RenderClear(renderer);
constexpr SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
std::string msg = "High Scores";
auto text = TTF_RenderUTF8_Solid(font, msg.c_str(), white);
SDL_Rect msgRect{};
msgRect.x = WINDOW_WIDTH / 2 - text->w / 2;
msgRect.y = WINDOW_HEIGHT / 10;
msgRect.w = text->w;
msgRect.h = text->h;
auto texture = SDL_CreateTextureFromSurface(renderer, text);
SDL_RenderCopy(renderer, texture, nullptr, &msgRect);
SDL_FreeSurface(text);
SDL_DestroyTexture(texture);
auto it = scores.begin();
for (Uint8 i = 0; i < 5; i++)
{
std::string msg = std::to_string(i + 1) + ". ";
if (it != scores.end())
{
msg += it->first;
msg += " ";
msg += std::to_string(it->second);
it++;
}
text = TTF_RenderUTF8_Solid(font, msg.c_str(), white);
SDL_Rect msgRect{};
msgRect.x = WINDOW_WIDTH / 10;
msgRect.y = WINDOW_HEIGHT / 10 * (i + 2);
msgRect.w = text->w;
msgRect.h = text->h;
texture = SDL_CreateTextureFromSurface(renderer, text);
SDL_RenderCopy(renderer, texture, nullptr, &msgRect);
SDL_FreeSurface(text);
SDL_DestroyTexture(texture);
}
SDL_RenderPresent(renderer);
}