-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMenu.cpp
2101 lines (1805 loc) · 92.8 KB
/
Menu.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
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
* @file Menu.cpp
* @author Andrés Gavín Murillo, 716358
* @author Rubén Rodríguez Esteban, 737215
* @date Mayo 2020
* @coms Videojuegos - OutRun
******************************************************************************/
#include "Menu.hpp"
#include <memory>
#define FPS 60
// Screen
#define SCREEN_DEFAULT make_pair(SCREEN_DEFAULT_X, SCREEN_DEFAULT_Y)
// HD
#define SCREEN_1 make_pair(SCREEN_HD_X, SCREEN_HD_Y)
// HD+
#define SCREEN_2 make_pair(1366, 768)
// FULL HD
#define SCREEN_3 make_pair(1920, 1080)
// QHD
#define SCREEN_4 make_pair(2560, 1440)
// UHD
#define SCREEN_5 make_pair(3840, 2160)
using namespace std;
using namespace sf;
Config::Config() : resolutions({SCREEN_DEFAULT, SCREEN_1, SCREEN_2, SCREEN_3, SCREEN_4, SCREEN_5}), resIndex(0),
isDefaultScreen(true), camD(0.87), renderLen(300) {
window.create(VideoMode(static_cast<unsigned int>(resolutions[resIndex].first),
static_cast<unsigned int>(resolutions[resIndex].second)), "Out Run",
Style::Titlebar | Style::Close);
window.setFramerateLimit(FPS);
window.setKeyRepeatEnabled(false);
if (isDefaultScreen)
window.setView(View(Vector2f(SCREEN_DEFAULT_X / 4.0f, SCREEN_DEFAULT_Y / 4.0f),
Vector2f(SCREEN_DEFAULT_X / 2.0f, SCREEN_DEFAULT_Y / 2.0f)));
else
window.setView(View(Vector2f(SCREEN_HD_X / 4.0f, SCREEN_HD_Y / 4.0f),
Vector2f(SCREEN_HD_X / 2.0f, SCREEN_HD_Y / 2.0f)));
w.create(static_cast<unsigned int>(window.getView().getSize().x),
static_cast<unsigned int>(window.getView().getSize().y));
Image i;
i.loadFromFile("resources/Icon/OutRun.png");
window.setIcon(i.getSize().x, i.getSize().y, i.getPixelsPtr());
screenScale = float(w.getSize().x) / float(SCREEN_DEFAULT_X);
menuKey = Keyboard::Escape;
menuUpKey = Keyboard::Up;
menuDownKey = Keyboard::Down;
menuEnterKey = Keyboard::Enter;
accelerateKey = Keyboard::LControl;
brakeKey = Keyboard::LAlt;
leftKey = Keyboard::Left;
rightKey = Keyboard::Right;
timeToPlay = initializeFontTimePlay();
speedVehicle = initializeFontSpeed();
options = initializeFontOptions();
volumeEffects = 100;
volumeMusic = 80;
level = NORMAL;
modifiedConfig = false;
currentSoundtrack = 0;
maxAggressiveness = 0.0f;
enableAI = false;
enablePixelArt = true;
}
State introAnimation(Config &c) {
// Load the game effects
for (int i = 1; i <= 30; i++) {
// Detect the possible events
Event e{};
while (c.window.pollEvent(e)) {
if (e.type == Event::Closed) {
return EXIT;
}
}
unique_ptr<Music> effect = make_unique<Music>();
effect->openFromFile("resources/SoundEffects/" + to_string(i) + ".ogg");
effect->setVolume(100);
c.effects.push_back(move(effect));
}
c.effects[29]->setLoop(true);
// Vector of images with the logo of Sega
Texture t;
vector<Texture> segaIcons;
Sprite segaIcon;
// Iterate throughout all the icons of sega
for (int i = 1; i < NUM_SEGA_ICONS; i++) {
// Detect the possible events
Event e{};
while (c.window.pollEvent(e)) {
if (e.type == Event::Closed) {
return EXIT;
}
}
// Loading the icon texture
t.loadFromFile("resources/SegaAnimation/segaLogo" + to_string(i) + ".png");
segaIcons.push_back(t);
// Load the texture in the sprite reseting the last texture
segaIcon.setTexture(segaIcons.at(static_cast<unsigned long>(i - 1)), true);
segaIcon.setScale(c.screenScale, c.screenScale);
if (i == 1) {
segaIcon.setPosition((c.w.getSize().x - segaIcon.getGlobalBounds().width) / 2.0f,
(c.w.getSize().y - segaIcon.getGlobalBounds().height) / 2.0f);
}
c.w.draw(segaIcon);
// Show the logos in the console
Sprite bufferSprite(c.w.getTexture());
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
// Sleep the process to see the menu icons correctly
sleep(milliseconds(40));
}
c.effects[26]->play();
// Load the music soundtracks of the game
for (int i = 0; i <= 5; i++) {
unique_ptr<Music> music = make_unique<Music>();
music->openFromFile("resources/Soundtrack/" + to_string(i) + ".ogg");
music->setVolume(90);
music->setLoop(true);
c.themes.push_back(move(music));
}
return START;
}
State startMenu(Config &c, bool startPressed) {
c.window.setView(View(Vector2f(c.window.getSize().x / 2.0f, c.window.getSize().y / 2.0f),
Vector2f(c.window.getSize().x, c.window.getSize().y)));
c.w.create(static_cast<unsigned int>(c.window.getView().getSize().x),
static_cast<unsigned int>(c.window.getView().getSize().y));
c.screenScale = float(c.w.getSize().x) / float(SCREEN_DEFAULT_X);
const int ELEMENTS = 8;
// Clean the console window
c.w.clear();
Sprite bufferSprite(c.w.getTexture());
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
Texture backgroundMenu, gameIcon, rowSelector;
Sprite mainMenu, nameGame, row;
vector<Texture> gameIcons;
vector<Sprite> nameGames;
// Loading the background texture
backgroundMenu.loadFromFile("resources/MainMenu/LogoMain1.png");
mainMenu.setTexture(backgroundMenu);
mainMenu.setPosition(0, 0);
mainMenu.setScale((float) c.w.getSize().x / backgroundMenu.getSize().x,
(float) c.w.getSize().y / backgroundMenu.getSize().y);
for (int i = 2; i <= 7; i++) {
// Loading the texture of the game's name
gameIcon.loadFromFile("resources/MainMenu/LogoMain" + to_string(i) + ".png");
gameIcons.push_back(gameIcon);
}
for (int i = 0; i < 6; i++) {
// Loading the texture of the game's name
nameGame.setTexture(gameIcons[i], true);
nameGame.setPosition((c.w.getSize().x / 2.f) - 180.0f * c.screenScale,
c.w.getSize().y / 2.f - 200.0f * c.screenScale);
nameGame.setScale(2.0f * c.screenScale, 2.0f * c.screenScale);
nameGames.push_back(nameGame);
}
// Loading the texture of the game's name
rowSelector.loadFromFile("resources/MainMenu/row.png");
row.setTexture(rowSelector);
row.setScale(0.06f * c.screenScale, 0.06f * c.screenScale);
row.setPosition((c.w.getSize().x / 2.f) - 100.0f * c.screenScale, c.w.getSize().y / 2.f + 75.0f * c.screenScale);
// Options of the main menu
Text textElements[ELEMENTS];
textElements[0].setString("PRESS ENTER KEY");
textElements[0].setCharacterSize(static_cast<unsigned int>(int(40.0f * c.screenScale)));
textElements[0].setFont(c.timeToPlay);
textElements[0].setFillColor(Color::Green);
textElements[0].setOutlineColor(Color::Black);
textElements[0].setOutlineThickness(3.0f * c.screenScale);
textElements[0].setPosition((c.w.getSize().x - textElements[0].getGlobalBounds().width) / 2.f,
c.w.getSize().y / 2.f + 100.0f * c.screenScale);
textElements[1].setString("START");
textElements[1].setPosition((c.w.getSize().x / 2.f) - 50.0f * c.screenScale,
c.w.getSize().y / 2.f + 70.0f * c.screenScale);
textElements[1].setCharacterSize(static_cast<unsigned int>(int(30.0f * c.screenScale)));
textElements[1].setFont(c.timeToPlay);
textElements[1].setFillColor(Color::Green);
textElements[1].setOutlineColor(Color::Black);
textElements[1].setOutlineThickness(3.0f * c.screenScale);
textElements[2].setString("OPTIONS");
textElements[2].setPosition(c.w.getSize().x / 2.f - 50.0f * c.screenScale,
c.w.getSize().y / 2.f + 120.0f * c.screenScale);
textElements[2].setCharacterSize(static_cast<unsigned int>(int(30.0f * c.screenScale)));
textElements[2].setFont(c.timeToPlay);
textElements[2].setFillColor(Color::Green);
textElements[2].setOutlineColor(Color::Black);
textElements[2].setOutlineThickness(3.0f * c.screenScale);
textElements[4].setString("©SEGA");
textElements[4].setCharacterSize(static_cast<unsigned int>(int(30.0f * c.screenScale)));
textElements[4].setFont(c.timeToPlay);
textElements[4].setFillColor(Color::Green);
textElements[4].setOutlineColor(Color::Black);
textElements[4].setOutlineThickness(3.0f * c.screenScale);
float initialX = c.w.getSize().x - 2.0f * textElements[4].getGlobalBounds().width, initialY =
c.w.getSize().y - 2.0f * float(textElements[4].getCharacterSize());
textElements[4].setPosition(initialX, initialY);
textElements[3].setString("1986");
textElements[3].setCharacterSize(static_cast<unsigned int>(int(30.0f * c.screenScale)));
textElements[3].setFont(c.timeToPlay);
textElements[3].setFillColor(Color::Green);
textElements[3].setOutlineColor(Color::Black);
textElements[3].setOutlineThickness(3.0f * c.screenScale);
textElements[3].setPosition(initialX - 1.5f * textElements[3].getGlobalBounds().width, initialY);
initialX = textElements[4].getGlobalBounds().width;
textElements[5].setString("EXIT / PAUSE: ESC KEY");
textElements[5].setCharacterSize(static_cast<unsigned int>(int(30.0f * c.screenScale)));
textElements[5].setFont(c.timeToPlay);
textElements[5].setFillColor(Color::Green);
textElements[5].setOutlineColor(Color::Black);
textElements[5].setOutlineThickness(3.0f * c.screenScale);
textElements[5].setPosition(initialX, initialY);
initialY -= 2.0f * textElements[5].getGlobalBounds().height;
textElements[6].setString("MOVE: ARROW KEYS");
textElements[6].setCharacterSize(static_cast<unsigned int>(int(30.0f * c.screenScale)));
textElements[6].setFont(c.timeToPlay);
textElements[6].setFillColor(Color::Green);
textElements[6].setOutlineColor(Color::Black);
textElements[6].setOutlineThickness(3.0f * c.screenScale);
textElements[6].setPosition(initialX, initialY);
initialY -= 2.0f * textElements[6].getGlobalBounds().height;
textElements[7].setString("SELECT: ENTER KEY");
textElements[7].setCharacterSize(static_cast<unsigned int>(int(30.0f * c.screenScale)));
textElements[7].setFont(c.timeToPlay);
textElements[7].setFillColor(Color::Green);
textElements[7].setOutlineColor(Color::Black);
textElements[7].setOutlineThickness(3.0f * c.screenScale);
textElements[7].setPosition(initialX, initialY);
// Partial state of the game
State state = START;
// Change the background texture
c.w.draw(mainMenu);
// Code of sprite to display
int j = 0;
float elapsed1, elapsed2;
Clock blinkClcok;
Time blink_delay = seconds(1.0);
blinkClcok.restart().asSeconds();
elapsed1 = blinkClcok.restart().asSeconds();
bool blink = true;
// While the console window is opened
while (c.window.isOpen()) {
// While the ENTER keyword is not pressed
while (!startPressed) {
// Detect the possible events
Event e{};
while (c.window.pollEvent(e)) {
if (e.type == Event::Closed) {
return EXIT;
}
}
elapsed2 = blinkClcok.getElapsedTime().asSeconds();
// Change the color of the main text
if (elapsed2 - elapsed1 >= blink_delay.asSeconds()) {
blink = !blink;
blinkClcok.restart();
}
if (blink) {
textElements[0].setFillColor(Color::Green);
textElements[0].setOutlineColor(Color::Black);
} else {
textElements[0].setFillColor(Color::Transparent);
textElements[0].setOutlineColor(Color::Transparent);
}
// Show the press start title in the menu
c.w.draw(mainMenu);
c.w.draw(nameGames[j]);
c.w.draw(textElements[0]);
c.w.draw(textElements[3]);
c.w.draw(textElements[4]);
c.w.draw(textElements[5]);
c.w.draw(textElements[6]);
c.w.draw(textElements[7]);
bufferSprite.setTexture(c.w.getTexture(), true);
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
// sleep(milliseconds(180));
// Check if the start keyword has been pressed
if (Keyboard::isKeyPressed(c.menuEnterKey)) {
// Pass to the second menu
startPressed = true;
c.effects[1]->stop();
c.effects[1]->play();
// sleep(milliseconds(50));
} else if (Keyboard::isKeyPressed(Keyboard::Escape))
return EXIT;
j = (j < (int) nameGames.size() - 1) ? j + 1 : 0;
}
// Control the second menu
startPressed = false;
state = MUSIC;
sleep(milliseconds(200));
// While the ENTER keyword is not pressed
while (!startPressed) {
// Detect the possible events
Event e{};
while (c.window.pollEvent(e))
if (e.type == Event::Closed)
return EXIT;
// Control if the up or down cursor keys are pressed or not
if (Keyboard::isKeyPressed(c.menuUpKey)) {
// Up cursor pressed
if (state != MUSIC) {
c.effects[0]->stop();
c.effects[0]->play();
row.setPosition((c.w.getSize().x / 2.f) - 100.0f * c.screenScale,
c.w.getSize().y / 2.f + 75.0f * c.screenScale);
state = MUSIC;
}
} else if (Keyboard::isKeyPressed(c.menuDownKey)) {
// Down cursor pressed
if (state != OPTIONS) {
c.effects[0]->stop();
c.effects[0]->play();
row.setPosition((c.w.getSize().x / 2.f) - 100.0f * c.screenScale,
c.w.getSize().y / 2.f + 125.0f * c.screenScale);
state = OPTIONS;
}
} else if (Keyboard::isKeyPressed(Keyboard::Escape))
return EXIT;
// Show the menu with the starting and options indicators
c.w.draw(mainMenu);
c.w.draw(nameGames[j]);
c.w.draw(textElements[1]);
c.w.draw(textElements[2]);
c.w.draw(textElements[3]);
c.w.draw(textElements[4]);
c.w.draw(textElements[5]);
c.w.draw(textElements[6]);
c.w.draw(textElements[7]);
c.w.draw(row);
bufferSprite.setTexture(c.w.getTexture(), true);
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
// Check if the start keyword has been pressed
if (Keyboard::isKeyPressed(c.menuEnterKey)) {
// Pass to the second menu
startPressed = true;
c.effects[1]->stop();
c.effects[1]->play();
}
j = (j < (int) nameGames.size() - 1) ? j + 1 : 0;
}
// Return the state of the game
c.effects[0]->stop();
if (c.enablePixelArt) {
if (c.isDefaultScreen)
c.window.setView(View(Vector2f(SCREEN_DEFAULT_X / 4.0f, SCREEN_DEFAULT_Y / 4.0f),
Vector2f(SCREEN_DEFAULT_X / 2.0f, SCREEN_DEFAULT_Y / 2.0f)));
else
c.window.setView(View(Vector2f(SCREEN_HD_X / 4.0f, SCREEN_HD_Y / 4.0f),
Vector2f(SCREEN_HD_X / 2.0f, SCREEN_HD_Y / 2.0f)));
c.w.create(static_cast<unsigned int>(c.window.getView().getSize().x),
static_cast<unsigned int>(c.window.getView().getSize().y));
c.screenScale = float(c.w.getSize().x) / float(SCREEN_DEFAULT_X);
}
return state;
}
return EXIT;
}
State changeCarControllers(Config &c) {
// Clean the console window
c.w.clear(Color(0, 0, 0));
Sprite bufferSprite(c.w.getTexture());
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
KeywordMapper kM = KeywordMapper();
// Clean the console window
c.w.clear(Color(0, 0, 0));
bufferSprite.setTexture(c.w.getTexture(), true);
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
// Loading the background texture
Texture segaBackground, textureShape;
segaBackground.loadFromFile("resources/MenuOptions/segaIcon.png");
segaBackground.setRepeated(true);
textureShape.loadFromFile("resources/MenuOptions/outrun.png");
textureShape.setRepeated(true);
IntRect background(0, 0, c.w.getSize().x, c.w.getSize().y);
Sprite sprite(segaBackground, background);
RectangleShape shape;
shape.setPosition((c.w.getSize().x / 2.f) - 300.0f * c.screenScale, c.w.getSize().y / 2.f - 250.0f * c.screenScale);
shape.setSize(sf::Vector2f(610.0f * c.screenScale, 500.0f * c.screenScale));
shape.setOutlineColor(Color(19, 186, 251));
shape.setOutlineThickness(5.0f * c.screenScale);
shape.setTexture(&textureShape, true);
vector<Button> menuButtons;
// Main Text of the menu
Text optionsText;
optionsText.setString("CONTROLLERS");
optionsText.setPosition(c.w.getSize().x / 2.f - 160.0f * c.screenScale,
c.w.getSize().y / 2.f - 220.0f * c.screenScale);
optionsText.setCharacterSize(static_cast<unsigned int>(int(35.0f * c.screenScale)));
optionsText.setFont(c.options);
optionsText.setStyle(Text::Bold | Text::Underlined);
optionsText.setFillColor(Color::Red);
Text info1;
info1.setString("Hold down Space to select a controller");
info1.setFillColor(Color(10, 201, 235));
info1.setOutlineColor(Color(3, 39, 8));
info1.setOutlineThickness(3.0f * c.screenScale);
info1.setCharacterSize(static_cast<unsigned int>(int(15.0f * c.screenScale)));
info1.setStyle(Text::Bold);
info1.setPosition(c.w.getSize().x / 2.f - 235.0f * c.screenScale, c.w.getSize().y / 2.f - 160.0f * c.screenScale);
info1.setFont(c.options);
c.w.draw(info1);
Text info2;
info2.setString("Then press a key to change its configuration");
info2.setFillColor(Color(10, 201, 235));
info2.setOutlineColor(Color(3, 39, 8));
info2.setCharacterSize(static_cast<unsigned int>(int(15.0f * c.screenScale)));
info2.setOutlineThickness(3.0f * c.screenScale);
info2.setStyle(Text::Bold);
info2.setPosition(c.w.getSize().x / 2.f - 265.0f * c.screenScale, c.w.getSize().y / 2.f - 120.0f * c.screenScale);
info2.setFont(c.options);
c.w.draw(info2);
// Option indicators
menuButtons.emplace_back(c.w.getSize().x / 2.f - 270.0f * c.screenScale,
c.w.getSize().y / 2.f - 70.0f * c.screenScale, 200.0f * c.screenScale,
30.0f * c.screenScale, c.options,
"Turning left", Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 1, c.screenScale);
menuButtons.emplace_back(c.w.getSize().x / 2.f - 270.0f * c.screenScale, c.w.getSize().y / 2.f,
200.0f * c.screenScale, 30.0f * c.screenScale, c.options,
"Turning right", Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0, c.screenScale);
menuButtons.emplace_back(c.w.getSize().x / 2.f - 270.0f * c.screenScale,
c.w.getSize().y / 2.f + 70.0f * c.screenScale, 200.0f * c.screenScale,
30.0f * c.screenScale, c.options,
"Acceleration", Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0, c.screenScale);
menuButtons.emplace_back(c.w.getSize().x / 2.f - 270.0f * c.screenScale,
c.w.getSize().y / 2.f + 140.0f * c.screenScale, 200.0f * c.screenScale,
30.0f * c.screenScale, c.options,
"Brake", Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0, c.screenScale);
// Option configurations
int code;
code = kM.mapperCodeKeyWord[c.leftKey];
menuButtons.emplace_back(c.w.getSize().x / 2.f + 80.0f * c.screenScale,
c.w.getSize().y / 2.f - 70.0f * c.screenScale, 200.0f * c.screenScale,
30.0f * c.screenScale, c.options,
kM.mapperIdKeyWord[code], Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 1,
c.screenScale);
code = kM.mapperCodeKeyWord[c.rightKey];
menuButtons.emplace_back(c.w.getSize().x / 2.f + 80.0f * c.screenScale, c.w.getSize().y / 2.f,
200.0f * c.screenScale, 30.0f * c.screenScale, c.options,
kM.mapperIdKeyWord[code], Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0,
c.screenScale);
code = kM.mapperCodeKeyWord[c.accelerateKey];
menuButtons.emplace_back(c.w.getSize().x / 2.f + 80.0f * c.screenScale,
c.w.getSize().y / 2.f + 70.0f * c.screenScale, 200.0f * c.screenScale,
30.0f * c.screenScale, c.options,
kM.mapperIdKeyWord[code], Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0,
c.screenScale);
code = kM.mapperCodeKeyWord[c.brakeKey];
menuButtons.emplace_back(c.w.getSize().x / 2.f + 80.0f * c.screenScale,
c.w.getSize().y / 2.f + 140.0f * c.screenScale, 200.0f * c.screenScale,
30.0f * c.screenScale, c.options,
kM.mapperIdKeyWord[code], Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0,
c.screenScale);
// Control if the start key is pressed or not
bool startPressed = false;
// Control the option selected by the user
int optionSelected = 0;
// Until the start keyword is not pressed
while (!startPressed) {
c.w.draw(sprite);
c.w.draw(shape);
c.w.draw(optionsText);
c.w.draw(info1);
c.w.draw(info2);
// Show the buttons of the menu
for (auto &menuButton : menuButtons) {
menuButton.render(&c.w);
}
bufferSprite.setTexture(c.w.getTexture(), true);
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
sleep(milliseconds(120));
c.effects[0]->stop();
// Detect the possible events
Event e{};
while (c.window.pollEvent(e)) {
if (e.type == Event::Closed) {
return EXIT;
}
}
if (Keyboard::isKeyPressed(c.menuDownKey)) {
// Up cursor pressed and change the soundtrack selected in the list
if (optionSelected != int(menuButtons.size() - 1) / 2) {
// Change the color appearance of both buttons
c.effects[0]->play();
optionSelected++;
menuButtons[optionSelected].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected - 1].setButtonState(BUTTON_IDLE);
menuButtons[optionSelected + 4].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 3].setButtonState(BUTTON_IDLE);
}
} else if (Keyboard::isKeyPressed(c.menuUpKey)) {
// Down cursor pressed and change the soundtrack selected in the list
if (optionSelected != 0) {
// Change the color appearance of both buttons
c.effects[0]->play();
optionSelected--;
menuButtons[optionSelected].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 1].setButtonState(BUTTON_IDLE);
menuButtons[optionSelected + 4].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 5].setButtonState(BUTTON_IDLE);
}
}
while (Keyboard::isKeyPressed(Keyboard::Space) && !Keyboard::isKeyPressed(Keyboard::Enter)) {
// Check if any keyword has been pressed or not
c.window.waitEvent(e);
if (e.type == Event::KeyPressed && e.key.code != -1 && e.key.code != Keyboard::Enter &&
e.key.code != Keyboard::Space) {
// Modify the option parameter if it's necessary
switch (optionSelected) {
case 0:
if (kM.mapperCodeKeyWord[e.key.code] == c.rightKey ||
kM.mapperCodeKeyWord[e.key.code] == c.accelerateKey ||
kM.mapperCodeKeyWord[e.key.code] == c.brakeKey) {
c.effects[3]->stop();
c.effects[3]->play();
} else {
menuButtons[optionSelected + 4].setTextButton(kM.mapperIdKeyWord[e.key.code]);
c.leftKey = kM.mapperCodeKeyWord[e.key.code];
c.effects[1]->stop();
c.effects[1]->play();
}
break;
case 1:
// Get the code of the keyword if it's not the up pr down cursor keys
if (kM.mapperCodeKeyWord[e.key.code] == c.leftKey ||
kM.mapperCodeKeyWord[e.key.code] == c.accelerateKey ||
kM.mapperCodeKeyWord[e.key.code] == c.brakeKey) {
c.effects[3]->stop();
c.effects[3]->play();
} else {
menuButtons[optionSelected + 4].setTextButton(kM.mapperIdKeyWord[e.key.code]);
c.rightKey = kM.mapperCodeKeyWord[e.key.code];
c.effects[1]->stop();
c.effects[1]->play();
}
break;
case 2:
// Get the code of the keyword if it's not the up pr down cursor keys
if (kM.mapperCodeKeyWord[e.key.code] == c.leftKey ||
kM.mapperCodeKeyWord[e.key.code] == c.rightKey ||
kM.mapperCodeKeyWord[e.key.code] == c.brakeKey) {
c.effects[3]->stop();
c.effects[3]->play();
} else {
menuButtons[optionSelected + 4].setTextButton(kM.mapperIdKeyWord[e.key.code]);
c.accelerateKey = kM.mapperCodeKeyWord[e.key.code];
c.effects[1]->stop();
c.effects[1]->play();
}
break;
case 3:
// Get the code of the keyword if it's not the up pr down cursor keys
if (kM.mapperCodeKeyWord[e.key.code] == c.leftKey ||
kM.mapperCodeKeyWord[e.key.code] == c.rightKey ||
kM.mapperCodeKeyWord[e.key.code] == c.accelerateKey) {
c.effects[3]->stop();
c.effects[3]->play();
} else {
menuButtons[optionSelected + 4].setTextButton(kM.mapperIdKeyWord[e.key.code]);
c.brakeKey = kM.mapperCodeKeyWord[e.key.code];
c.effects[1]->stop();
c.effects[1]->play();
}
break;
default:
break;
}
}
}
// Check if left or right cursor keys have been pressed or not
if (Keyboard::isKeyPressed(c.menuEnterKey)) {
// Change the controllers of the car
startPressed = true;
c.modifiedConfig = true;
c.effects[2]->stop();
c.effects[2]->play();
}
}
return OPTIONS;
}
State soundMenu(Config &c, const bool &inGame) {
// Clean the console window
c.w.clear(Color(0, 0, 0));
Sprite bufferSprite(c.w.getTexture());
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
// Clean the console window
c.w.clear(Color(0, 0, 0));
bufferSprite.setTexture(c.w.getTexture(), true);
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
// Loading the background texture
Texture segaBackground, textureShape;
segaBackground.loadFromFile("resources/MenuOptions/segaIcon.png");
segaBackground.setRepeated(true);
textureShape.loadFromFile("resources/MenuOptions/outrun.png");
textureShape.setRepeated(true);
IntRect background(0, 0, c.w.getSize().x, c.w.getSize().y);
Sprite sprite(segaBackground, background);
RectangleShape shape;
shape.setPosition((c.w.getSize().x / 2.f) - 300.0f * c.screenScale, c.w.getSize().y / 2.f - 250.0f * c.screenScale);
shape.setSize(sf::Vector2f(610.0f * c.screenScale, 500.0f * c.screenScale));
shape.setOutlineColor(Color(19, 186, 251));
shape.setOutlineThickness(5.0f * c.screenScale);
shape.setTexture(&textureShape, true);
vector<Button> menuButtons;
// Main Text of the menu
Text optionsText;
optionsText.setString("SOUND MENU");
optionsText.setPosition(c.w.getSize().x / 2.f - 160.0f * c.screenScale,
c.w.getSize().y / 2.f - 220.0f * c.screenScale);
optionsText.setCharacterSize(static_cast<unsigned int>(int(35.0f * c.screenScale)));
optionsText.setFont(c.options);
optionsText.setStyle(Text::Bold | Text::Underlined);
optionsText.setFillColor(Color::Red);
// Option indicators
menuButtons.emplace_back(c.w.getSize().x / 2.f - 270.0f * c.screenScale,
c.w.getSize().y / 2.f - 70.0f * c.screenScale, 200.0f * c.screenScale,
30.0f * c.screenScale, c.options,
"Music volume", Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 1, c.screenScale);
menuButtons.emplace_back(c.w.getSize().x / 2.f - 270.0f * c.screenScale, c.w.getSize().y / 2.f,
200.0f * c.screenScale, 30.0f * c.screenScale, c.options,
"Effects volume", Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0,
c.screenScale);
// Option configurations
menuButtons.emplace_back(c.w.getSize().x / 2.f + 80.0f * c.screenScale,
c.w.getSize().y / 2.f - 70.0f * c.screenScale, 200.0f * c.screenScale,
30.0f * c.screenScale, c.options,
to_string(c.volumeMusic), Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 1,
c.screenScale);
menuButtons.emplace_back(c.w.getSize().x / 2.f + 80.0f * c.screenScale, c.w.getSize().y / 2.f,
200.0f * c.screenScale, 30.0f * c.screenScale, c.options,
to_string(c.volumeEffects), Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0,
c.screenScale);
// Control if the start key is pressed or not
bool startPressed = false;
// Control the option selected by the user
int optionSelected = 0;
// Until the start keyword is not pressed
while (!startPressed) {
// Detect the possible events
Event e{};
while (c.window.pollEvent(e)) {
if (e.type == Event::Closed) {
return EXIT;
}
}
if (Keyboard::isKeyPressed(c.menuDownKey)) {
// Up cursor pressed and change the soundtrack selected in the list
if (optionSelected != int(menuButtons.size() - 1) / 2) {
// Change the color appearance of both buttons
c.effects[0]->play();
optionSelected++;
menuButtons[optionSelected].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected - 1].setButtonState(BUTTON_IDLE);
menuButtons[optionSelected + 2].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 1].setButtonState(BUTTON_IDLE);
}
} else if (Keyboard::isKeyPressed(c.menuUpKey)) {
// Down cursor pressed and change the soundtrack selected in the list
if (optionSelected != 0) {
// Change the color appearance of both buttons
c.effects[0]->play();
optionSelected--;
menuButtons[optionSelected].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 1].setButtonState(BUTTON_IDLE);
menuButtons[optionSelected + 2].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 3].setButtonState(BUTTON_IDLE);
}
}
if (optionSelected == 0) {
// Volume music
// Check if left or right cursor keys have been pressed or not
if (Keyboard::isKeyPressed(c.leftKey)) {
if (c.volumeMusic != 0) {
c.volumeMusic--;
for (int i = 0; i <= 5; i++) {
c.themes[i]->setVolume(float(c.volumeMusic));
if (i == 0) {
c.themes[i]->pause();
c.themes[i]->play();
}
}
menuButtons[optionSelected + 2].setTextButton((to_string(c.volumeMusic)));
}
} else if (Keyboard::isKeyPressed(c.rightKey)) {
if (c.volumeMusic != 100) {
c.volumeMusic++;
for (int i = 0; i <= 5; i++) {
c.themes[i]->setVolume(float(c.volumeMusic));
if (i == 0) {
c.themes[i]->pause();
c.themes[i]->play();
}
}
menuButtons[optionSelected + 2].setTextButton((to_string(c.volumeMusic)));
}
}
} else {
// Volume effects
// Check if left or right cursor keys have been pressed or not
if (Keyboard::isKeyPressed(c.leftKey)) {
if (c.volumeEffects != 0) {
c.volumeEffects--;
for (int i = 0; i <= 29; i++) {
c.effects[i]->setVolume(float(c.volumeEffects));
}
c.effects[0]->stop();
c.effects[0]->play();
menuButtons[optionSelected + 2].setTextButton((to_string(c.volumeEffects)));
}
} else if (Keyboard::isKeyPressed(c.rightKey)) {
if (c.volumeEffects != 100) {
c.volumeEffects++;
for (int i = 0; i <= 29; i++) {
c.effects[i]->setVolume(float(c.volumeEffects));
}
c.effects[0]->stop();
c.effects[0]->play();
menuButtons[optionSelected + 2].setTextButton((to_string(c.volumeEffects)));
}
}
}
c.w.draw(sprite);
c.w.draw(shape);
c.w.draw(optionsText);
// Show the buttons of the menu
for (auto &menuButton : menuButtons) {
menuButton.render(&c.w);
}
bufferSprite.setTexture(c.w.getTexture(), true);
c.w.display();
c.window.draw(bufferSprite);
c.window.display();
sleep(milliseconds(120));
c.effects[0]->stop();
// Check if left or right cursor keys have been pressed or not
if (Keyboard::isKeyPressed(c.menuEnterKey)) {
// Change the controllers of the car
startPressed = true;
c.modifiedConfig = true;
c.effects[2]->stop();
c.effects[2]->play();
}
}
return OPTIONS;
}
State Config::graphicsMenu() {
// Control if the start key is pressed or not
bool startPressed = false;
bool resized = false;
while (!startPressed) {
bool currentResized = false;
// Clean the console window
w.clear(Color(0, 0, 0));
Sprite bufferSprite(w.getTexture());
w.display();
window.draw(bufferSprite);
window.display();
// Clean the console window
w.clear(Color(0, 0, 0));
bufferSprite.setTexture(w.getTexture(), true);
w.display();
window.draw(bufferSprite);
window.display();
// Loading the background texture
Texture segaBackground, textureShape;
segaBackground.loadFromFile("resources/MenuOptions/segaIcon.png");
segaBackground.setRepeated(true);
textureShape.loadFromFile("resources/MenuOptions/outrun.png");
textureShape.setRepeated(true);
IntRect background(0, 0, w.getSize().x, w.getSize().y);
Sprite sprite(segaBackground, background);
RectangleShape shape;
shape.setPosition((w.getSize().x / 2.f) - 300.0f * screenScale, w.getSize().y / 2.f - 250.0f * screenScale);
shape.setSize(sf::Vector2f(610.0f * screenScale, 500.0f * screenScale));
shape.setOutlineColor(Color(19, 186, 251));
shape.setOutlineThickness(5.0f * screenScale);
shape.setTexture(&textureShape, true);
vector<Button> menuButtons;
// Main Text of the menu
Text optionsText;
optionsText.setString("GRAPHICS MENU");
optionsText.setPosition(w.getSize().x / 2.f - 160.0f * screenScale, w.getSize().y / 2.f - 220.0f * screenScale);
optionsText.setCharacterSize(static_cast<unsigned int>(int(35.0f * screenScale)));
optionsText.setFont(options);
optionsText.setStyle(Text::Bold | Text::Underlined);
optionsText.setFillColor(Color::Red);
// Option indicators
menuButtons.emplace_back(w.getSize().x / 2.f - 270.0f * screenScale, w.getSize().y / 2.f - 70.0f * screenScale,
200.0f * screenScale, 30.0f * screenScale, options,
"Resolution", Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 1, screenScale);
menuButtons.emplace_back(w.getSize().x / 2.f - 270.0f * screenScale, w.getSize().y / 2.f, 200.0f * screenScale,
30.0f * screenScale, options,
"Pixel art", Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 0, screenScale);
// Option configurations
const string res = resIndex > -1 ? to_string(resolutions[resIndex].first) + "x" +
to_string(resolutions[resIndex].second) : "FULLSCREEN";
menuButtons.emplace_back(w.getSize().x / 2.f + 80.0f * screenScale, w.getSize().y / 2.f - 70.0f * screenScale,
200.0f * screenScale, 30.0f * screenScale, options,
res, Color(0, 255, 0), Color(255, 255, 0), Color(0, 255, 0), 1, screenScale);
menuButtons.emplace_back(w.getSize().x / 2.f + 80.0f * screenScale, w.getSize().y / 2.f, 200.0f * screenScale,
30.0f * screenScale, options,
enablePixelArt ? "ENABLED" : "DISABLED", Color(0, 255, 0), Color(255, 255, 0),
Color(0, 255, 0), 0, screenScale);
// Control the option selected by the user
int optionSelected = 0;
// Until the start keyword is not pressed
while (!startPressed && !currentResized) {
// Detect the possible events
Event e{};
while (window.pollEvent(e)) {
if (e.type == Event::Closed) {
return EXIT;
}
}
window.pollEvent(e);
if (Keyboard::isKeyPressed(menuDownKey)) {
// Up cursor pressed and change the soundtrack selected in the list
if (optionSelected != int(menuButtons.size() - 1) / 2) {
// Change the color appearance of both buttons
effects[0]->play();
optionSelected++;
menuButtons[optionSelected].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected - 1].setButtonState(BUTTON_IDLE);
menuButtons[optionSelected + 2].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 1].setButtonState(BUTTON_IDLE);
}
} else if (Keyboard::isKeyPressed(menuUpKey)) {
// Down cursor pressed and change the soundtrack selected in the list
if (optionSelected != 0) {
// Change the color appearance of both buttons
effects[0]->play();
optionSelected--;
menuButtons[optionSelected].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 1].setButtonState(BUTTON_IDLE);
menuButtons[optionSelected + 2].setButtonState(BUTTON_HOVER);
menuButtons[optionSelected + 3].setButtonState(BUTTON_IDLE);
}
}
window.pollEvent(e);
if (optionSelected == 0) {
// Volume music
// Check if left or right cursor keys have been pressed or not
if (Keyboard::isKeyPressed(leftKey)) {
if (resized) {
resized = false;
} else if (resIndex > -1) {
resIndex--;
menuButtons[optionSelected + 2].setTextButton(resIndex > -1 ?
to_string(resolutions[resIndex].first) + "x" +
to_string(resolutions[resIndex].second)
: "FULLSCREEN");
if (resIndex > -1) {
window.create(VideoMode(static_cast<unsigned int>(resolutions[resIndex].first),
static_cast<unsigned int>(resolutions[resIndex].second)),