-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateMenu.cpp
306 lines (275 loc) · 9.32 KB
/
CreateMenu.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#include "GameEngine.hpp"
bool GameEngine::createHomeMenu()
{
std::vector<std::string> _home = createHomeSlide();
AObject *button = new Slide(0, -10, -100, 0, 0, 270, _home, 0);
if ((button->initialize() == false))
return (false);
_objects.push_back(button);
return (true);
}
bool GameEngine::createModeSetting()
{
clearVector();
std::vector<std::string> _mode = createModeSettingSlide();
AObject *mode = new Slide(0, -10, -100, 0, 0, 270, _mode, 0);
if ((mode->initialize() == false))
return (false);
_objects.push_back(mode);
return (true);
}
bool GameEngine::createPlayerSetting()
{
clearVector();
std::vector<std::string> _player = createPlayerSettingSlide();
AObject *player = new Slide(0, -10, -100, 0, 0, 270, _player, 0);
if ((player->initialize() == false))
return (false);
_objects.push_back(player);
return (true);
}
bool GameEngine::createMapModeSetting()
{
clearVector();
std::vector<std::string> _mapMode = createMapSettingSlide();
AObject *mapMode = new Slide(0, -10, -100, 0, 0, 270, _mapMode, 0);
if ((mapMode->initialize() == false))
return (false);
_objects.push_back(mapMode);
return (true);
}
bool GameEngine::createPredefinedSetting()
{
clearVector();
std::vector<std::string> _predefined = createPredefinedSlide();
AObject *predefined = new Slide(0, -10, -100, 0, 0, 270, _predefined, 0);
if ((predefined->initialize() == false))
return (false);
_objects.push_back(predefined);
return (true);
}
bool GameEngine::createCustomSetting()
{
clearVector();
std::vector<std::string> _custom = createCustomSlide();
std::map<int, std::string> _numbers = createNumbersSlide();
AObject *arrow = new Arrow(-8, -6, -70, 0, 0, 270, "./img/arrowUp.tga");
AObject *number1 = new Number(-8, 0, -70, 0, 0, 270, _numbers);
AObject *number2 = new Number(-2, 0, -70, 0, 0, 270, _numbers);
AObject *number3 = new Number(4, 0, -70, 0, 0, 270, _numbers);
AObject *number4 = new Number(10, 0, -70, 0, 0, 270, _numbers);
if ((arrow->initialize() == false) || (number1->initialize() == false)
|| (number2->initialize() == false) || (number3->initialize() == false)
|| (number4->initialize() == false))
return (false);
_objects.push_back(arrow);
_objects.push_back(number1);
_objects.push_back(number2);
_objects.push_back(number3);
_objects.push_back(number4);
return (true);
}
bool GameEngine::createPause()
{
clearVector();
_cam->setPosition(glm::vec3(0, 0, 3));
_cam->setCenter(glm::vec3(0, 0, 0));
_projection = _cam->setPerspective(_winX, _winY);
_transformation = _cam->setLookAt();
// The shader always needs to be bound before setUniform method calls
_shader.bind();
_shader.setUniform("view", _transformation);
_shader.setUniform("projection", _projection);
std::vector<std::string> _pause = createPauseSlide();
AObject *pause = new Slide(0, -10, -100, 0, 0, 270, _pause, 0);
if ((pause->initialize() == false))
return (false);
_objects.push_back(pause);
return (true);
}
void GameEngine::createSound()
{
_sound = new Sound();
_sound->initialise();
_sound->load("./music/08-bgm-08.mp3");
_sound->play();
}
bool GameEngine::startGame()
{
_cam->setPosition(glm::vec3(0, 0, 0));
_cam->setCenter(glm::vec3(0, 10, 10));
_projection = _cam->setPerspective(_winX, _winY);
_transformation = _cam->setLookAt();
// The shader always needs to be bound before setUniform method calls
_shader.bind();
_shader.setUniform("view", _transformation);
_shader.setUniform("projection", _projection);
_height = _total;
_width = _height;
if (_height % 2 == 0)
++_height;
if (_width % 2 == 0)
++_width;
_map = new GameMap(_width, _height, _dynamicObjects);
if (_positionHome.at(2) == 1)
{
_map->createCustomMap();
}
else
{
_height = 23;
_width = 23;
_map->createMap(_positionHome.at(3));
}
int nb_player = _positionHome.at(1) + 2;
for (int i = 0; i < nb_player; ++i)
{
Player *p;
p = new Player(*_map);
_players.push_back(p);
if (_positionHome.at(0) == 0 && i > 0)
{
if (p->initCharacter(_dynamicObjects, i + 2) == false)
throw ErrorException("Error : player load failed in Player.cpp");
}
else
if (p->initCharacter(_dynamicObjects, i + 1) == false)
throw ErrorException("Error : player load failed in Player.cpp");
}
// Will be set by the menu
if (_positionHome.at(0) == 1)
_splitScreen = true;
else
_splitScreen = false;
// initializing objects
int nbBomb = 0;
_wall = new Cube;
_block = new Block;
_ground = new Ground;
_bomb = new Bomb(*_map, nbBomb);
_explosion = new Explosion;
if (_wall->initialize() == false)
throw ErrorException("Error : texture load failed in Cube.hpp");
if (_block->initialize() == false)
throw ErrorException("Error : texture load failed in Block.hpp");
if (_ground->initialize() == false)
throw ErrorException("Error : texture load failed in Ground.hpp");
if (_bomb->initialize() == false)
throw ErrorException("Error : texture load failed in Bomb.cpp");
if (_explosion->initialize() == false)
throw ErrorException("Error : texture load failed in Explosion.cpp");
_wall->setPosZ(1.0f);
_wall->setPosX(1.0f);
_block->setPosZ(1.0f);
_block->setPosX(1.0f);
_ground->setPosZ(1.0f);
_ground->setPosX(1.0f);
// initializing bonuses
Bonus *bonus = new Bonus(AObject::BOMBUP);
if (bonus->initialize() == false)
throw ErrorException("Error : texture load failed in Bonus.cpp");
_bonus.push_back(bonus);
bonus = new Bonus(AObject::POWERUP);
if (bonus->initialize() == false)
throw ErrorException("Error : texture load failed in Bonus.cpp");
_bonus.push_back(bonus);
bonus = new Bonus(AObject::SPEEDUP);
if (bonus->initialize() == false)
throw ErrorException("Error : texture load failed in Bonus.cpp");
_bonus.push_back(bonus);
return (true);
}
void GameEngine::mainMenu()
{
mode = "home";
stat = 0;
clearVector();
_players.clear();
_cam->setPosition(glm::vec3(0, 0, 3));
_cam->setCenter(glm::vec3(0, 0, 0));
_projection = _cam->setPerspective(_winX, _winY);
_transformation = _cam->setLookAt();
// The shader always needs to be bound before setUniform method calls
_shader.bind();
_shader.setUniform("view", _transformation);
_shader.setUniform("projection", _projection);
createHomeMenu();
}
bool GameEngine::saveGame()
{
clearVector();
std::map<int, std::string> _alphabet = createAlphabetSlide();
AObject *arrow = new Arrow(-8, -6, -70, 0, 0, 270, "./img/arrowUp.tga");
AObject *alphabet1 = new SaveInterface(-8, 0, -70, 0, 0, 270, _alphabet);
AObject *alphabet2 = new SaveInterface(-2, 0, -70, 0, 0, 270, _alphabet);
AObject *alphabet3 = new SaveInterface(4, 0, -70, 0, 0, 270, _alphabet);
AObject *alphabet4 = new SaveInterface(10, 0, -70, 0, 0, 270, _alphabet);
if ((arrow->initialize() == false) || (alphabet1->initialize() == false)
|| (alphabet2->initialize() == false)
|| (alphabet3->initialize() == false)
|| (alphabet4->initialize() == false))
return (false);
_objects.push_back(arrow);
_objects.push_back(alphabet1);
_objects.push_back(alphabet2);
_objects.push_back(alphabet3);
_objects.push_back(alphabet4);
return (true);
}
bool GameEngine::createLoad()
{
clearVector();
std::map<int, std::string> _alphabet = createAlphabetSlide();
AObject *arrow = new Arrow(-8, -6, -70, 0, 0, 270, "./img/arrowUp.tga");
AObject *alphabet1 = new SaveInterface(-8, 0, -70, 0, 0, 270, _alphabet);
AObject *alphabet2 = new SaveInterface(-2, 0, -70, 0, 0, 270, _alphabet);
AObject *alphabet3 = new SaveInterface(4, 0, -70, 0, 0, 270, _alphabet);
AObject *alphabet4 = new SaveInterface(10, 0, -70, 0, 0, 270, _alphabet);
if ((arrow->initialize() == false) || (alphabet1->initialize() == false)
|| (alphabet2->initialize() == false)
|| (alphabet3->initialize() == false)
|| (alphabet4->initialize() == false))
return (false);
_objects.push_back(arrow);
_objects.push_back(alphabet1);
_objects.push_back(alphabet2);
_objects.push_back(alphabet3);
_objects.push_back(alphabet4);
return (true);
}
bool GameEngine::loadWinner()
{
clearVector();
_players.clear();
_dynamicObjects.clear();
_cam->setPosition(glm::vec3(0, 0, 3));
_cam->setCenter(glm::vec3(0, 0, 0));
_projection = _cam->setPerspective(_winX, _winY);
_transformation = _cam->setLookAt();
// The shader always needs to be bound before setUniform method calls
_shader.bind();
_shader.setUniform("view", _transformation);
_shader.setUniform("projection", _projection);
std::vector<std::string> _winner = createWinnerSlide();
std::vector<std::string> _score = createScoreSlide();
std::map<int, std::string> _numbers = createNumbersSlide();
AObject *score = new Slide(0, 0, -120, 0, 0, 270, _score, _positionHome.at(1) - 1);
if ((score->initialize() == false))
return (false);
_objects.push_back(score);
return (true);
}
bool GameEngine::loadWinner2()
{
clearVector();
// The shader always needs to be bound before setUniform method calls
_shader.bind();
_shader.setUniform("view", _transformation);
_shader.setUniform("projection", _projection);
std::vector<std::string> _winner = createWinnerSlide();
AObject *winner = new Slide(0, -10, -120, 0, 0, 270, _winner, _id);
if ((winner->initialize() == false))
return (false);
_objects.push_back(winner);
return (true);
}