-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScore.cpp
86 lines (62 loc) · 1.18 KB
/
Score.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#include "Score.h"
Score::Score()
{
initialize();
}
void Score::initialize()
{
score = 0;
num_die = 0;
score_loop = 0;
}
Score::~Score()
{
score_displayed.free();
}
void Score::SetFont()
{
score_displayed.SetFont(gFont_40);
num_die_displayed.SetFont(gFont_38);
}
string Score::Convert(int a)
{
string ans;
if (a == 0) ans = "0";
while(a > 0)
ans = char(a%10 + 48) + ans,
a/= 10;
return ans;
}
void Score::Update_ScoreLoop(int a)
{
if (a > 0)
num_die++;
score_loop += a;
}
void Score::Update_Score()
{
score += score_loop * num_die;
if (num_die != 0)
num_die_displayed.loadFromRenderedText("x " + Convert(num_die), {255, 246, 3}),
frame = 0;
score_loop = 0;
num_die = 0;
}
int Score::get_die()
{
return num_die;
}
void Score::render()
{
Update_Score();
if (frame < 8)
num_die_displayed.render(SCREEN_WIDTH/2 - 10, SCREEN_HEIGHT - 75);
frame++;
score_displayed.loadFromRenderedText(Convert(score), {216, 168, 30});
score_displayed.render(SCREEN_WIDTH - 10 - score_displayed.getWidth(), 0);
}
int Score::get_score()
{
return score;
}