-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.h
49 lines (43 loc) · 993 Bytes
/
score.h
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
#ifndef SCORE_H
#define SCORE_H
#include <string>
#include "include/sdlxx.h"
using namespace sdlxx;
class Score {
public:
Score() = default;
~Score() {}
static Score& sharedInstance() {
static Score instance;
return instance;
}
void increment() {
++score;
}
void set(int newScore) {
score = newScore;
}
int get() {
return score;
}
void draw(Sdl_renderer& renderer) {
// Draw the score
auto texture = Sdl_texture{ "resources/numbers.bmp", renderer };
std::string scoreStr = std::to_string(Score::sharedInstance().get());
int x = 50;
int y = 50;
for (char& c : scoreStr) {
int i = c - '0';
SDL_Rect clip;
clip.x = 63 * i;
clip.y = 0;
clip.w = 63;
clip.h = 64;
renderer.copy(texture, x, y, &clip);
x += 63;
}
}
private:
int score{ 0 };
};
#endif