-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.cpp
More file actions
executable file
·108 lines (77 loc) · 2.41 KB
/
menu.cpp
File metadata and controls
executable file
·108 lines (77 loc) · 2.41 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
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "menu.h"
extern int draw;
static void buttonStartEvent(kiss_button *button, SDL_Event *e, int *draw,
std::function<void()> callback)
{
if (kiss_button_event(button, e, draw)) {
callback();
}
}
static void buttonHighscoreEvent(kiss_button *button, SDL_Event *e, int *draw,
std::function<void()> callback)
{
if (kiss_button_event(button, e, draw)) {
callback();
}
}
static void buttonExitEvent(kiss_button *button, SDL_Event *e, int *draw,
std::function<void()> callback)
{
if (kiss_button_event(button, e, draw)) {
callback();
}
}
bool Menu::Init(GameEngine* game)
{
buttonStart = {0};
buttonHighscore = {0};
buttonExit = {0};
text_rect = { 0, 0, 200, 20 };
SDL_Color color = { 255, 255, 255 };
kiss_window* window = (game->GetRend()->GetWindow());
int screenWidth = game->GetRend()->GetWidth();
int screenHeight = game->GetRend()->GetHeight();
int centerW = game->GetRend()->GetWidth()/2;
int centerH = game->GetRend()->GetHeight()/2;
kiss_button_new(&buttonStart, window, "Start Game",
centerW, centerH-screenHeight/8);
kiss_button_new(&buttonHighscore, window, "Highscore",
centerW, centerH);
kiss_button_new(&buttonExit, window, "Exit",
centerW, centerH+screenHeight/8);
return true;
}
void Menu::Update(GameEngine* game)
{
}
void Menu::HandleEvents(GameEngine* game)
{
SDL_PollEvent(&event);
kiss_window_event(game->rend->GetWindow(), &event, &draw);
buttonStartEvent(&buttonStart, &event, &draw,
std::bind(&GameEngine::ToSinglePlayer, game));
buttonHighscoreEvent(&buttonHighscore, &event, &draw,
std::bind(&GameEngine::ToHighscore, game));
buttonExitEvent(&buttonExit, &event, &draw,
std::bind(&GameEngine::Quit, 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 Menu::Draw(std::shared_ptr<RenderManager>& rend)
{
//kiss_window_draw(&(rend->GetWindow()), rend->GetSDLRenderer());
kiss_button_draw(&buttonStart, rend->GetSDLRenderer());
kiss_button_draw(&buttonHighscore, rend->GetSDLRenderer());
kiss_button_draw(&buttonExit, rend->GetSDLRenderer());
}