-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmenuSelectGameType.cpp
More file actions
421 lines (356 loc) · 14.2 KB
/
menuSelectGameType.cpp
File metadata and controls
421 lines (356 loc) · 14.2 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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#include "controls.hpp"
#include "game.hpp"
#include "grid.hpp"
#include "menuSelectGameType.hpp"
#include "players.hpp"
#include <SDL3/SDL_opengl.h>
int menuSelectGameType::selection = 0;
static bool debounceStart = false;
static float player1Amount = 0;
static float mpPlayer1Amount = 0;
static float mpPlayer2Amount = 0;
static float mpPlayer3Amount = 0;
static float mpPlayer4Amount = 0;
void menuSelectGameType::init(int player)
{
debounceStart = true;
player1Amount = 0;
mpPlayer1Amount = 0;
mpPlayer2Amount = 0;
mpPlayer3Amount = 0;
mpPlayer4Amount = 0;
theGame->getPlayer1()->mJoined = player == 0 ? true : false;
theGame->getPlayer2()->mJoined = player == 1 ? true : false;
theGame->getPlayer3()->mJoined = player == 2 ? true : false;
theGame->getPlayer4()->mJoined = player == 3 ? true : false;
theGame->mSound->playTrack(SOUNDID_MENU_SELECT);
}
void menuSelectGameType::run()
{
int dir = 0;
if (theGame->mControls->getBackButton(0) || theGame->mControls->getBackButton(1) || theGame->mControls->getBackButton(2) || theGame->mControls->getBackButton(3)) {
// Exit the menu
game::mGameMode = game::GAMEMODE_ATTRACT;
theGame->mSound->playTrack(SOUNDID_MENU_SELECT);
return;
}
if (!debounceStart) {
if (selection == 0) {
if (theGame->mControls->getStartButton(0) || theGame->mControls->getStartButton(1) || theGame->mControls->getStartButton(2) || theGame->mControls->getStartButton(3)) {
theGame->startGame(game::GAMETYPE_SINGLEPLAYER);
theGame->mSound->playTrack(SOUNDID_MENU_SELECT);
}
} else {
if (theGame->mControls->getStartButton(0))
theGame->getPlayer1()->mJoined = true;
if (theGame->mControls->getStartButton(1))
theGame->getPlayer2()->mJoined = true;
if (theGame->mControls->getStartButton(2))
theGame->getPlayer3()->mJoined = true;
if (theGame->mControls->getStartButton(3))
theGame->getPlayer4()->mJoined = true;
if (theGame->mControls->getTriggerButton(0) || theGame->mControls->getTriggerButton(1) || theGame->mControls->getTriggerButton(2) || theGame->mControls->getTriggerButton(3)) {
theGame->startGame(game::GAMETYPE_MULTIPLAYER_COOP);
theGame->mSound->playTrack(SOUNDID_MENU_SELECT);
}
/*
if (theGame->mControls->getStartButton(0)
|| theGame->mControls->getStartButton(1)
|| theGame->mControls->getStartButton(2)
|| theGame->mControls->getStartButton(3))
{
//theGame->startGame(4, game::GAMETYPE_MULTIPLAYER_COOP);
if (theGame->mControls->getStartButton(0))
}
*/
/*
if (theGame->mControls->getStartButton(0))
{
theGame->startGame(1, game::GAMETYPE_SINGLEPLAYER);
}
else if (theGame->mControls->getStartButton(1))
{
theGame->startGame(2, game::GAMETYPE_MULTIPLAYER_COOP);
}
else if (theGame->mControls->getStartButton(2))
{
theGame->startGame(3, game::GAMETYPE_MULTIPLAYER_COOP);
}
else if (theGame->mControls->getStartButton(3))
{
theGame->startGame(4, game::GAMETYPE_MULTIPLAYER_COOP);
}
*/
}
} else {
if (!theGame->mControls->getStartButton(0) && !theGame->mControls->getStartButton(1) && !theGame->mControls->getStartButton(2) && !theGame->mControls->getStartButton(3)) {
debounceStart = false;
}
}
Point3d leftStick = theGame->mControls->getLeftStick(0) + theGame->mControls->getLeftStick(1) + theGame->mControls->getLeftStick(2) + theGame->mControls->getLeftStick(3);
float leftDistance = mathutils::calculate2dDistance(Point3d(0, 0, 0), leftStick);
if (leftDistance > .1) {
if (leftStick.x < -.5) {
dir = 1;
} else if (leftStick.x > .5) {
dir = -1;
}
}
Point3d rightStick = theGame->mControls->getRightStick(0) + theGame->mControls->getRightStick(1) + theGame->mControls->getRightStick(2) + theGame->mControls->getRightStick(3);
float rightDistance = mathutils::calculate2dDistance(Point3d(0, 0, 0), rightStick);
if (rightDistance > .1) {
if (rightStick.x < -.5) {
dir = 1;
} else if (rightStick.x > .5) {
dir = -1;
}
}
if (dir < 0) {
if (selection != 0) {
selection = 0;
theGame->mSound->playTrack(SOUNDID_MENU_SELECT);
}
} else if (dir > 0) {
if (selection != 1) {
selection = 1;
theGame->mSound->playTrack(SOUNDID_MENU_SELECT);
}
}
/*
if (dir > 0)
{
++selection;
if (selection > 1)
{
selection = 1;
}
}
else if (dir < 0)
{
--selection;
if (selection < 0)
{
selection = 0;
}
}
*/
const float amountIncrease = .02;
const float amountDampener = .97;
if (selection == 0) {
if (player1Amount < 1) {
player1Amount += amountIncrease;
} else if (player1Amount > 1) {
player1Amount *= amountDampener;
}
if (mpPlayer1Amount > 0)
mpPlayer1Amount *= amountDampener;
if (mpPlayer2Amount > 0)
mpPlayer2Amount *= amountDampener;
if (mpPlayer3Amount > 0)
mpPlayer3Amount *= amountDampener;
if (mpPlayer4Amount > 0)
mpPlayer4Amount *= amountDampener;
} else if (selection == 1) {
float player1Target = theGame->getPlayer1()->mJoined ? 1 : 0;
float player2Target = theGame->getPlayer2()->mJoined ? 1 : 0;
float player3Target = theGame->getPlayer3()->mJoined ? 1 : 0;
float player4Target = theGame->getPlayer4()->mJoined ? 1 : 0;
if (mpPlayer1Amount < player1Target) {
mpPlayer1Amount += amountIncrease;
} else if (mpPlayer1Amount > player1Target) {
mpPlayer1Amount *= amountDampener;
}
if (mpPlayer2Amount < player2Target) {
mpPlayer2Amount += amountIncrease;
} else if (mpPlayer2Amount > player2Target) {
mpPlayer2Amount *= amountDampener;
}
if (mpPlayer3Amount < player3Target) {
mpPlayer3Amount += amountIncrease;
} else if (mpPlayer3Amount > player3Target) {
mpPlayer3Amount *= amountDampener;
}
if (mpPlayer4Amount < player4Target) {
mpPlayer4Amount += amountIncrease;
} else if (mpPlayer4Amount > player4Target) {
mpPlayer4Amount *= amountDampener;
}
if (player1Amount > 0)
player1Amount *= amountDampener;
}
if (fabs(player1Amount) < amountIncrease)
player1Amount = 0;
if (fabs(mpPlayer1Amount) < amountIncrease)
mpPlayer1Amount = 0;
if (fabs(mpPlayer2Amount) < amountIncrease)
mpPlayer2Amount = 0;
if (fabs(mpPlayer3Amount) < amountIncrease)
mpPlayer3Amount = 0;
if (fabs(mpPlayer4Amount) < amountIncrease)
mpPlayer4Amount = 0;
}
void menuSelectGameType::draw()
{
static float angle0 = 88, angle1 = 123, angle2 = 321, angle3 = 424, angle4 = 242;
angle0 += .052;
angle1 += .051;
angle2 += .049;
angle3 += .05;
angle4 += .052;
glEnable(GL_LINE_SMOOTH);
glEnable(GL_MULTISAMPLE);
Point3d pos;
pos.x = theGame->mGrid->extentX() / 2;
pos.y = theGame->mGrid->extentY() / 2;
pos.z = 0;
glLineWidth(4);
// Single player
pos.x = (theGame->mGrid->extentX() / 2) + 0;
pos.y = (theGame->mGrid->extentY() / 2) + 16;
{
vector::pen pen = theGame->getPlayer1()->getPen();
pen.r = 1;
pen.g = 1;
pen.b = 1;
pen.a = .5;
const auto& model = theGame->getPlayer1()->getModel();
glBegin(GL_LINES);
model->Identity();
model->Scale(4);
model->Rotate((sin(angle0) * .5) * player1Amount);
model->Translate(pos);
model->emit(pen);
glEnd();
}
// Multiplayer
const float player1xPos = (theGame->mGrid->extentX() / 2) - 30;
const float player2xPos = (theGame->mGrid->extentX() / 2) - 10;
const float player3xPos = (theGame->mGrid->extentX() / 2) + 10;
const float player4xPos = (theGame->mGrid->extentX() / 2) + 30;
// PLAYER 1
pos.x = player1xPos;
pos.y = (theGame->mGrid->extentY() / 2) - 16;
{
vector::pen pen = vector::pen(1, .3, .3, 1, 12); // HACK - find a better way to get this color :-(
if (!theGame->getPlayer1()->mJoined)
pen.a *= .25;
const auto& model = theGame->getPlayer1()->getModel();
glBegin(GL_LINES);
model->Identity();
model->Scale(4);
model->Rotate((sin(angle1) * .5) * mpPlayer1Amount);
model->Translate(pos);
model->emit(pen);
glEnd();
}
// PLAYER 2
pos.x = player2xPos;
pos.y = (theGame->mGrid->extentY() / 2) - 16;
{
vector::pen pen = theGame->getPlayer2()->getPen();
if (!theGame->getPlayer2()->mJoined)
pen.a *= .25;
const auto& model = theGame->getPlayer2()->getModel();
glBegin(GL_LINES);
model->Identity();
model->Scale(.25);
model->Rotate((sin(angle2) * .5) * mpPlayer2Amount);
model->Translate(pos);
model->emit(pen);
glEnd();
}
// PLAYER 3
pos.x = player3xPos;
pos.y = (theGame->mGrid->extentY() / 2) - 16;
{
vector::pen pen = theGame->getPlayer3()->getPen();
if (!theGame->getPlayer3()->mJoined)
pen.a *= .25;
const auto& model = theGame->getPlayer3()->getModel();
glBegin(GL_LINES);
model->Identity();
model->Scale(.25);
model->Rotate((sin(angle3) * .5) * mpPlayer3Amount);
model->Translate(pos);
model->emit(pen);
glEnd();
}
// PLAYER 4
pos.x = player4xPos;
pos.y = (theGame->mGrid->extentY() / 2) - 16;
{
vector::pen pen = theGame->getPlayer4()->getPen();
if (!theGame->getPlayer4()->mJoined)
pen.a *= .25;
const auto& model = theGame->getPlayer4()->getModel();
glBegin(GL_LINES);
model->Identity();
model->Scale(.25);
model->Rotate((sin(angle4) * .5) * mpPlayer4Amount);
model->Translate(pos);
model->emit(pen);
glEnd();
}
// Single player selection rectangle
if (selection == 0) {
glColor4f(1, 1, 1, .5);
glLineWidth(4);
glBegin(GL_LINE_LOOP);
Point3d p1((theGame->mGrid->extentX() / 2) - 10, (theGame->mGrid->extentY() / 2) + 25, 0);
Point3d p2((theGame->mGrid->extentX() / 2) + 10, (theGame->mGrid->extentY() / 2) + 25, 0);
Point3d p3((theGame->mGrid->extentX() / 2) + 10, (theGame->mGrid->extentY() / 2) + 7, 0);
Point3d p4((theGame->mGrid->extentX() / 2) - 10, (theGame->mGrid->extentY() / 2) + 7, 0);
glVertex3f(p1.x, p1.y, 0);
glVertex3f(p2.x, p2.y, 0);
glVertex3f(p3.x, p3.y, 0);
glVertex3f(p4.x, p4.y, 0);
glEnd();
}
// Multi player selection rectangle
if (selection == 1) {
glColor4f(1, 1, 1, 1);
glLineWidth(4);
glBegin(GL_LINE_LOOP);
Point3d p1((theGame->mGrid->extentX() / 2) + 40, (theGame->mGrid->extentY() / 2) - 7, 0);
Point3d p2((theGame->mGrid->extentX() / 2) - 40, (theGame->mGrid->extentY() / 2) - 7, 0);
Point3d p3((theGame->mGrid->extentX() / 2) - 40, (theGame->mGrid->extentY() / 2) - 25, 0);
const float indicatorW = 3;
const float indicatorH = 1.5;
// Player 1 indicator
Point3d p4(player1xPos - (indicatorW / 2), ((theGame->mGrid->extentY() / 2) - 25), 0);
Point3d p5(player1xPos, ((theGame->mGrid->extentY() / 2) - 25) + ((theGame->getPlayer1()->mJoined) ? indicatorH : 0), 0);
Point3d p6(player1xPos + (indicatorW / 2), ((theGame->mGrid->extentY() / 2) - 25), 0);
// Player 2 indicator
Point3d p7(player2xPos - (indicatorW / 2), ((theGame->mGrid->extentY() / 2) - 25), 0);
Point3d p8(player2xPos, ((theGame->mGrid->extentY() / 2) - 25) + ((theGame->getPlayer2()->mJoined) ? indicatorH : 0), 0);
Point3d p9(player2xPos + (indicatorW / 2), ((theGame->mGrid->extentY() / 2) - 25), 0);
// Player 3 indicator
Point3d p10(player3xPos - (indicatorW / 2), ((theGame->mGrid->extentY() / 2) - 25), 0);
Point3d p11(player3xPos, ((theGame->mGrid->extentY() / 2) - 25) + ((theGame->getPlayer3()->mJoined) ? indicatorH : 0), 0);
Point3d p12(player3xPos + (indicatorW / 2), ((theGame->mGrid->extentY() / 2) - 25), 0);
// Player 4 indicator
Point3d p13(player4xPos - (indicatorW / 2), ((theGame->mGrid->extentY() / 2) - 25), 0);
Point3d p14(player4xPos, ((theGame->mGrid->extentY() / 2) - 25) + ((theGame->getPlayer4()->mJoined) ? indicatorH : 0), 0);
Point3d p15(player4xPos + (indicatorW / 2), ((theGame->mGrid->extentY() / 2) - 25), 0);
Point3d p16((theGame->mGrid->extentX() / 2) + 40, (theGame->mGrid->extentY() / 2) - 25, 0);
glVertex3f(p1.x, p1.y, 0);
glVertex3f(p2.x, p2.y, 0);
glVertex3f(p3.x, p3.y, 0);
glVertex3f(p4.x, p4.y, 0);
glVertex3f(p5.x, p5.y, 0);
glVertex3f(p6.x, p6.y, 0);
glVertex3f(p7.x, p7.y, 0);
glVertex3f(p8.x, p8.y, 0);
glVertex3f(p9.x, p9.y, 0);
glVertex3f(p10.x, p10.y, 0);
glVertex3f(p11.x, p11.y, 0);
glVertex3f(p12.x, p12.y, 0);
glVertex3f(p13.x, p13.y, 0);
glVertex3f(p14.x, p14.y, 0);
glVertex3f(p15.x, p15.y, 0);
glVertex3f(p16.x, p16.y, 0);
glEnd();
}
glDisable(GL_MULTISAMPLE);
glDisable(GL_LINE_SMOOTH);
}