-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighscore.cpp
More file actions
executable file
·95 lines (67 loc) · 2.04 KB
/
highscore.cpp
File metadata and controls
executable file
·95 lines (67 loc) · 2.04 KB
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
87
88
89
90
91
92
93
94
95
#include "highscore.h"
extern int draw;
static void buttonBackEvent(kiss_button *button, SDL_Event *e, int *draw,
std::function<void()> callback)
{
if (kiss_button_event(button, e, draw)) {
callback();
}
}
bool Highscore::Init(GameEngine* game)
{
buttonBack = {0};
kiss_window* window = (game->GetRend()->GetWindow());
centerW = game->GetRend()->GetWidth()/2;
centerH = game->GetRend()->GetHeight()/2;
screenWidth = game->GetRend()->GetWidth();
screenHeight = game->GetRend()->GetHeight();
kiss_button_new(&buttonBack, window, "Back",
centerW, centerH);
char high[100] = "Highscore ";
Highlevel = game->ReadSave();
HighlevelStr = std::to_string(Highlevel);
char* highscore = strcat(high, HighlevelStr.c_str());
int width = 0;
width = kiss_textwidth(kiss_textfont, highscore, NULL);
kiss_label_new(&HighscoreLabel, window, highscore,
centerW-width/2,
centerH-screenHeight/8);
cupTexture = game->GetRend()->createTexture("data/cup.bmp");
return true;
}
void Highscore::Update(GameEngine* game)
{
}
void Highscore::HandleEvents(GameEngine* game)
{
SDL_PollEvent(&event);
buttonBackEvent(&buttonBack, &event, &draw,
std::bind(&GameEngine::PopState, game));
switch(event.type)
{
case SDL_KEYDOWN:
if( event.key.keysym.sym == SDLK_q){
game->Quit();
}
break;
case SDL_TEXTINPUT:
break;
case SDL_QUIT:
game->Quit();
break;
}
}
void Highscore::DrawLabel(std::shared_ptr<RenderManager>& rend, int x, int y,
int w, int h)
{
rend->DrawTextureReal(cupTexture.get(), x, y, w, h);
}
void Highscore::Draw(std::shared_ptr<RenderManager>& rend)
{
kiss_button_draw(&buttonBack, rend->GetSDLRenderer());
kiss_label_draw(&HighscoreLabel, rend->GetSDLRenderer());
int picWidth = screenWidth/24;
int picHeight = screenHeight/12;
this->DrawLabel(rend, centerW-(screenWidth/6/2)-picWidth,
centerH-picHeight/2-screenHeight/8, picWidth, picHeight);
}