-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoreBoard.cpp
59 lines (52 loc) · 1.05 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
58
59
#include "ScoreBoard.h"
ScoreBoard::ScoreBoard()
: ScoreBoard({ 230, 230, 230 })
{
}
ScoreBoard::ScoreBoard(SDL_Color color)
{
mColor = color;
Score(0);
}
ScoreBoard::~ScoreBoard()
{
ClearScoreBoard();
}
void ScoreBoard::ClearScoreBoard()
{
for (int i = 0; i < mScore.size(); ++i)
{
delete mScore[i];
mScore[i] = NULL;
}
mScore.clear();
}
void ScoreBoard::Score(int score)
{
ClearScoreBoard();
if (score == 0)
{
for (int i = 0; i < 2; ++i)
{
mScore.push_back(new Texture("0", "emulogic.ttf", 32, mColor));
mScore[i]->Parent(this);
mScore[i]->Pos(Vector2(-32.0f*i, 0.0f));
}
} else {
std::string str = std::to_string(score);
int lastIndex = str.length() - 1;
for (int i = 0; i <= lastIndex; ++i)
{
mScore.push_back(new Texture(str.substr(i, 1), "emulogic.ttf", 32, mColor));
mScore[i]->Parent(this);
mScore[i]->Pos(Vector2(-32.0f*(lastIndex - i), 0.0f));
}
}
}
void ScoreBoard::Render()
{
for (int i = 0; i < mScore.size(); ++i)
{
mScore[i]->Render();
}
}