This repository has been archived by the owner on Apr 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenu.cpp
177 lines (146 loc) · 4.09 KB
/
MainMenu.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "MainMenu.h"
MainMenu::MainMenu(std::string Nickname) : HardcoreMode(false), MenuMovementY(310), CurrentNickname(Nickname)
{
DisplaySurface = init("SUPER", 800, 600, 32);
EnterNickname = true;
Running = true;
}
MainMenu::~MainMenu()
{ }
SDL_Surface* MainMenu::init(const std::string Title, int Width, int Height, int Bpp)
{
TTF_Init();
SDL_Init(SDL_INIT_EVERYTHING);
SDL_WM_SetCaption(Title.c_str(), NULL);
DisplaySurface = SDL_SetVideoMode(Width, Height, Bpp, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_FillRect(DisplaySurface, NULL, 0x000000);
return DisplaySurface;
}
void MainMenu::set_menu_movement_y(const int Value)
{
MenuMovementY = Value;
}
int MainMenu::get_menu_movement_y()
{
return MenuMovementY;
}
void MainMenu::set_hardcore(bool Hardcore)
{
HardcoreMode = Hardcore;
}
bool MainMenu::get_hardcore()
{
return HardcoreMode;
}
void MainMenu::handle_events(SDL_Event &Event)
{
while (SDL_PollEvent(&Event))
{
switch (Event.type)
{
case SDL_KEYDOWN:
switch (Event.key.keysym.sym)
{
case SDLK_w:
case SDLK_UP:
if (get_menu_movement_y() <= 310)
set_menu_movement_y(430);
set_menu_movement_y(get_menu_movement_y() - 30);
break;
case SDLK_s:
case SDLK_DOWN:
if (get_menu_movement_y() >= 400)
set_menu_movement_y(280);
set_menu_movement_y(get_menu_movement_y() + 30);
break;
case SDLK_u:
if (get_hardcore())
{
set_hardcore(false);
}
else
{
set_hardcore(true);
}
break;
case SDLK_SPACE:
case SDLK_RETURN:
// If you wanna start the game
if (get_menu_movement_y() == 310)
{
GameWindow *r = new GameWindow(CurrentNickname);
r->run_game(get_hardcore());
delete r;
r = 0;
}
// If you wanna check the highscore
else if (get_menu_movement_y() == 340)
{
Highscore *s = new Highscore();
s->run_highscore();
delete s;
s = 0;
}
// If you wanna quit
else if (get_menu_movement_y() == 370)
{
Running = false;
}
// If you wanna change your initiales
else if (get_menu_movement_y() == 400)
{
EnterNickname = true;
}
break;
case SDLK_ESCAPE:
Running = false;
break;
}
}
}
}
void MainMenu::run_menu()
{
Draw *d = new Draw();
while(Running)
{
if (EnterNickname) {
Nickname *n = new Nickname(CurrentNickname);
n->run_nickname();
CurrentNickname = n->get_nickname();
delete n;
n = 0;
EnterNickname = false;
// If the user hits ESCAPE before entering 3 characters it will end this loop
if (CurrentNickname.size() < 3)
Running = false;
}
// Set the background to black
SDL_FillRect(DisplaySurface, NULL, 0x000000);
// The title and subtitle
d->draw_text(DisplaySurface, "SUPER", 137, 120, -1, 51, 108, 184);
d->draw_text(DisplaySurface, "Super Unique Death Efficient Rally", 25, 260, -1, 176, 54, 56);
// The menu entries
if (get_menu_movement_y() == 310)
d->draw_text(DisplaySurface, "new game", 18, 300, -1, 255, 0, 0);
else
d->draw_text(DisplaySurface, "new game", 18, 300, -1, 255, 255, 255);
if (get_menu_movement_y() == 340)
d->draw_text(DisplaySurface, "highscore", 18, 330, -1, 255, 255, 0);
else
d->draw_text(DisplaySurface, "highscore", 18, 330, -1, 255, 255, 255);
if (get_menu_movement_y() == 370)
d->draw_text(DisplaySurface, "quit", 18, 360, -1, 0, 255, 0);
else
d->draw_text(DisplaySurface, "quit", 18, 360, -1, 255, 255, 255);
if (get_menu_movement_y() == 400)
d->draw_text(DisplaySurface, "change initials", 18, 390, -1, 255, 0, 255);
else
d->draw_text(DisplaySurface, "change initials", 18, 390, -1, 255, 255, 255);
// Draw the "choose arrow" in the menu
d->draw_menu_arrow(DisplaySurface, get_menu_movement_y(), 250);
SDL_Delay(10);
SDL_Flip(DisplaySurface);
handle_events(Events);
}
}