-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aim-Trainer.cpp
2921 lines (2453 loc) · 105 KB
/
Aim-Trainer.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
// Aim-Trainer.cpp : This file contains the 'main' function. Program execution begins and ends there.
// [DONE] IMPLEMENT THE FPP AIM
// [DONE - MAYBE] Fix Bug the Target spawn in gun area
// Fix the bullet, must be travel not like this
// Coba Buat tampilin 3D OBJ
// Add Timer
//
#include <iostream>
#include <raylib.h>
#include <string>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <ctime>
#include <map>
#include <filesystem>
#include <chrono>
// MAIN COLOR
#define MAINCOLOR CLITERAL(Color) { 36, 37, 46, 255 }
// MAIN MENU BUTTON
#define BUTTON_PLAY_COLOR_BASE CLITERAL(Color) { 118, 234, 192, 255 }
#define BUTTON_PLAY_COLOR_HOVER CLITERAL(Color) { 143, 255, 207, 255 }
#define BUTTON_QUIT_COLOR_BASE CLITERAL(Color) { 199, 60, 60, 255 }
#define BUTTON_QUIT_COLOR_HOVER CLITERAL(Color) { 223, 87, 87, 255 }
// SETUP MENU BUTTON
#define BUTTON_GUN_COLOR_BASE CLITERAL(Color) { 71, 206, 224, 255 }
#define BUTTON_GUN_COLOR_HOVER CLITERAL(Color) { 101, 232, 255, 255 }
#define BUTTON_TIME_COLOR_BASE CLITERAL(Color) { 68, 196, 150, 255 }
#define BUTTON_TIME_COLOR_HOVER CLITERAL(Color) { 91, 214, 183, 255 }
#define BUTTON_LEVEL_COLOR_BASE CLITERAL(Color) { 140, 196, 68, 255 }
#define BUTTON_LEVEL_COLOR_HOVER CLITERAL(Color) { 167, 212, 102, 255 }
#define BUTTON_START_COLOR_BASE CLITERAL(Color) { 245, 250, 0, 255 }
#define BUTTON_START_COLOR_HOVER CLITERAL(Color) { 255, 255, 77, 255 }
#define BUTTON_BACK_COLOR_BASE CLITERAL(Color) { 199, 60, 60, 255 }
#define BUTTON_BACK_COLOR_HOVER CLITERAL(Color) { 223, 87, 87, 255 }
#define LEADERBOARDS_CANVAS_COLOR CLITERAL(Color) { 217, 217, 217, 255 }
#define SETUPMENU_CLICKED_COLOR CLITERAL(Color) { 227, 227, 227, 255 }
// GUN CARD
#define GUN_CARD_COLOR CLITERAL(Color) { 28, 32, 65, 255 }
#define GUN_POV_CARD_COLOR CLITERAL(Color) { 40, 43, 68, 255 }
#define GUN_STATS_CARD_COLOR CLITERAL(Color) { 40, 43, 68, 255 }
#define GUN_CARD_TITLE_COLOR CLITERAL(Color) { 179, 217, 228, 225 }
#define GUN_CARD_BUTTON_COLOR_BASE CLITERAL(Color) { 28, 32, 65, 255 }
#define GUN_CARD_BUTTON_COLOR_HOVER CLITERAL(Color) { 55, 64, 110, 255 }
#define GUN_M416_FPP_LOCATION {"D:/Coding/Raylib C++/Aim-Trainer/Assets/Gun/Gun-M416-FPP-1080.png"}
#define GUN_M416_SIDE_LOCATION {"D:/Coding/Raylib C++/Aim-Trainer/Assets/Gun/Gun-M416-SIDE-1080.png"}
#define GUN_AK47_FPP_LOCATION {"D:/Coding/Raylib C++/Aim-Trainer/Assets/Gun/Gun-AK47-FPP-1080.png"}
#define GUN_AK47_SIDE_LOCATION {"D:/Coding/Raylib C++/Aim-Trainer/Assets/Gun/Gun-AK47-SIDE-1080.png"}
#define GUN_AWM_FPP_LOCATION {"D:/Coding/Raylib C++/Aim-Trainer/Assets/Gun/Gun-AWM-FPP-1080.png"}
#define GUN_AWM_SIDE_LOCATION {"D:/Coding/Raylib C++/Aim-Trainer/Assets/Gun/Gun-AWM-SIDE-1080.png"}
#define GUN_GLOCK_FPP_LOCATION {"D:/Coding/Raylib C++/Aim-Trainer/Assets/Gun/Gun-GLOCK-FPP-1080.png"}
#define GUN_GLOCK_SIDE_LOCATION {"D:/Coding/Raylib C++/Aim-Trainer/Assets/Gun/Gun-GLOCK-SIDE-1080.png"}
#define GUN_COLOR_STOCK CLITERAL(Color) { 23, 23, 23, 255 }
#define GUN_COLOR_STOCK_HOVER CLITERAL(Color) { 45, 45, 45, 255 }
#define GUN_COLOR_CAMO CLITERAL(Color) { 67, 72, 53, 255 }
#define GUN_COLOR_CAMO_HOVER CLITERAL(Color) { 90, 96, 77, 255 }
#define GUN_COLOR_CANDY CLITERAL(Color) { 49, 96, 166, 255 }
#define GUN_COLOR_CANDY_HOVER CLITERAL(Color) { 74, 124, 198, 255 }
#define GUN_COLOR_GOLDEN CLITERAL(Color) { 225, 192, 17, 255 }
#define GUN_COLOR_GOLDEN_HOVER CLITERAL(Color) { 240, 212, 55, 255 }
std::vector<std::vector<Color>> gunBtnColorHover{
{GUN_COLOR_STOCK, GUN_COLOR_STOCK_HOVER},
{GUN_COLOR_CAMO, GUN_COLOR_CAMO_HOVER},
{GUN_COLOR_CANDY, GUN_COLOR_CANDY_HOVER},
{GUN_COLOR_GOLDEN, GUN_COLOR_GOLDEN_HOVER}
};
#define STATS_BASE_BAR_COLOR CLITERAL(Color) { 217, 217, 217, 255 }
#define STATS_SPEED_COLOR CLITERAL(Color) { 176, 74, 74, 255 }
#define STATS_POWER_COLOR CLITERAL(Color) { 74, 115, 176, 255 }
#define STATS_CAPACITY_COLOR CLITERAL(Color) { 117, 98, 98, 255 }
// TIME CARD
#define TIME_CARD_COLOR CLITERAL(Color) { 34, 34, 34, 255 }
#define TIME_CARD_BUTTON_HOVER CLITERAL(Color) { 255, 255, 255, 255 }
#define TIME_CARD_BUTTON_CLICKED CLITERAL(Color) { 20, 20, 20, 255 }
#define TIME_120_COLOR CLITERAL(Color) { 110, 207, 108, 255 }
#define TIME_90_COLOR CLITERAL(Color) { 169, 209, 55, 255 }
#define TIME_60_COLOR CLITERAL(Color) { 246, 142, 45, 255 }
#define TIME_30_COLOR CLITERAL(Color) { 243, 71, 71, 255 }
// LEVEL CARD
#define LEVEL_CARD_COLOR CLITERAL(Color) { 34, 34, 34, 255 }
#define LEVEL_CARD_BUTTON_HOVER CLITERAL(Color) { 255, 255, 255, 255 }
#define LEVEL_CARD_BUTTON_CLICKED CLITERAL(Color) { 20, 20, 20, 255 }
#define LEVEL_1_COLOR CLITERAL(Color) { 110, 207, 108, 255 }
#define LEVEL_2_COLOR CLITERAL(Color) { 169, 209, 55, 255 }
#define LEVEL_3_COLOR CLITERAL(Color) { 246, 142, 45, 255 }
#define LEVEL_4_COLOR CLITERAL(Color) { 243, 71, 71, 255 }
#define ICON_APP_LOC {"Icons/bullseye.png"}
#define ICON_ARROW_LOC {"Icons/Arrow2.png"}
#define ICON_SCROLL_BUTTON_LOC {"Icons/Icon-Scroll3.png"}
#define ICON_SCROLL_BAR_ACC_LOC {"Icons/Icon-Scroll_Bar.png"}
#define ICON_CLOSE_FIGHT_LOC {"Icons/Close.png"}
#define FIGHT_BTN_COOLDOWN_FRAMES 100
#define LEADERBOARD_DATA_CAPACITY 25
static const char* CSV_FILENAME_LEADERBOARDS{ "Data/Leaderboards.txt" };
enum GamePage
{
MAIN_MENU = 0,
SETUP_MENU = 1,
IN_GAME = 2,
GAMEOVER_MENU = 3
};
enum SetupProperties
{
GUN = 0,
TIME = 1,
LEVEL = 2,
BACK = 3,
START = 4
};
enum Weapons {
M416 = 0,
AK47 = 1,
AWM = 2,
GLOCK = 3
};
enum Target_Visibility {
TARGET_VISIBLE = 0,
TARGET_INVISIBLE = 1
};
struct Game {
const int w{ 1920 };
const int h{ 1080 };
const char* title{ "AIM-TRAINER" };
int FPS{ 99 };
};
Game game = {};
struct MainMenu {
const char* title{ "AIM-TRAINER" };
int title_Pos_Y{ 180 };
float font_size{ 100 };
float font_space{ 1 };
float button_space{ 45 };
struct Button {
const char* text{};
Color color{};
Color text_color{};
int BtnPosY{};
int height{ 400 };
int width{ 95 };
float font_size{ 60 };
float font_space{ 1.F };
float roundness{ 0.05F };
int segments{ 10 };
Rectangle rect {
(float)game.w / 2 - height / 2,
(float)BtnPosY,
(float)height,
(float)width
};
};
Button play{ "PLAY", BUTTON_PLAY_COLOR_BASE, BLACK, (int)((game.h / 2) - (button_space / 2) - (button_space * 2)) };
Button quit{ "QUIT", BUTTON_QUIT_COLOR_BASE, WHITE, (int)((game.h / 2) + (button_space / 2)) };
std::vector<const char*> credit{ "First Game By", "UFTHaq" };
std::vector<float> credit_Pos_Y{ 850, 920 };
float credit_font_size{ 30 };
Color credit_color = WHITE;
};
MainMenu mainMenu{};
struct SetupMenu {
const char* title{ "AIM - TRAINER" };
int title_Pos_Y{ 80 };
float title_font_size{ 50 };
float font_size{ 36 };
float font_space{ 1 };
Rectangle clicked_effect_rect{ 200, 200, 180, 100 };
Color clicked_effect_color{ SETUPMENU_CLICKED_COLOR };
float roundness{ 0.005F };
int segments{ 10 };
Rectangle Base_Canvas_rect{ 200, 280, 1000, 500 };
Color canvas_color{ BUTTON_GUN_COLOR_BASE };
const char* leaderboard_text{ "LEADERBOARDS" };
Rectangle leaderboards_rect{ 1248, 280, 470, 700 };
Color leaderboards_color{ LEADERBOARDS_CANVAS_COLOR };
const char* choose_text{ "CHOOSE YOUR PROPERTIES" };
struct Button {
const char* text{};
Vector2 coor{};
Color color{};
Color text_color{};
int height{ 60 };
int width{ 180 };
float font_size{ 40 };
float font_space{ 1 };
float roundness{ 0.01F };
int segments{ 10 };
Rectangle rect{
coor.x,
coor.y,
(float)width,
(float)height
};
};
Button gun{ "GUN", { 200, 200 }, BUTTON_GUN_COLOR_BASE, BLACK };
Button time{ "TIME", { 400, 200 }, BUTTON_TIME_COLOR_BASE, BLACK };
Button level{ "LEVEL", { 600, 200 }, BUTTON_LEVEL_COLOR_BASE, BLACK };
Button start{ "START", { (Base_Canvas_rect.x + Base_Canvas_rect.width / 2 - gun.width / 2), 920 }, BUTTON_START_COLOR_BASE, BLACK };
Button back{ "BACK", { (float)(game.w - 180 - 40), 40 }, BUTTON_BACK_COLOR_BASE, WHITE };
};
SetupMenu setupMenu{};
//SetupMenu* setupMenu = new SetupMenu;
struct GunCard{
float roundness{ 0.01F };
int segments{ 10 };
Rectangle rect{ 300, 350, 800, 300 };
Color color{ GUN_CARD_COLOR };
struct MiniCard {
const char* text{};
Vector2 coor{};
Color color{};
Vector2 title_coor{};
float font_size{ 30 };
float font_space{ 0 };
float roundness{ 0.2F };
int segments{ 10 };
int width{ 180 };
int height{ 270 };
Rectangle rect{
coor.x,
coor.y,
(float)width,
(float)height
};
int title_width{ 140 };
int title_height{ 36 };
Rectangle title_rect{
title_coor.x,
title_coor.y,
(float)title_width,
(float)title_height
};
Color title_color{ GUN_CARD_TITLE_COLOR };
Color text_color{ GUN_CARD_COLOR };
};
MiniCard pov{ "POV",{ 320, 366 }, GUN_POV_CARD_COLOR, { 340, 360 } };
MiniCard stats{ "STATS", {900, 366}, GUN_STATS_CARD_COLOR, { 920, 360 } };
struct Button {
Vector2 coor{};
Color color{ GUN_CARD_COLOR };
Color texture_color{ WHITE };
int width{ 106 };
int height{ 42 };
float roundness{ 0.5F };
int segments{ 10 };
Rectangle rect{
coor.x,
coor.y,
(float)width,
(float)height
};
};
Button prev{ {592, 656} };
Button next{ {704, 656} };
const char* text_color{ "COLOR" };
float text_color_pos_y{ 558 };
float color_font_size{ 20.F };
float font_space{ 1 };
Color font_color{ WHITE };
struct ColorButton {
Rectangle rect{};
Color color{};
float roundness{ 0.01F };
int segments{ 10 };
};
float color_width_base{ 60 };
float color_height_base{ 40 };
float color_height_clicked{ 44 };
ColorButton BASE { {578, 586, 244, 44}, WHITE };
ColorButton STOCK { {580, 588, color_width_base, color_height_base}, GUN_COLOR_STOCK };
ColorButton CAMO { {640, 588, color_width_base, color_height_base}, GUN_COLOR_CAMO };
ColorButton CANDY { {700, 588, color_width_base, color_height_base}, GUN_COLOR_CANDY };
ColorButton GOLDEN { {760, 588, color_width_base, color_height_base}, GUN_COLOR_GOLDEN };
std::vector<ColorButton> GunsColor{ STOCK, CAMO, CANDY, GOLDEN };
float stats_font_size{ 20.F };
const char* text_type{ "TYPE" };
float text_type_y{ 410 };
float type_gun_y_coor{ 440 };
float bar_width{ 140 };
float bar_heigth{ 16 };
float text_to_bar_space_y{ 22 };
Color base_bar_color{ STATS_BASE_BAR_COLOR };
struct Stats {
const char* text{};
float bar_coor_y{};
Color color{};
};
Stats speed { "Speed", 510, STATS_SPEED_COLOR };
Stats power { "Power", 554, STATS_POWER_COLOR };
Stats capacity { "Capacity", 598, STATS_CAPACITY_COLOR };
std::vector<Stats> stats_base{ speed, power, capacity };
};
GunCard gunCard{};
struct Gun {
const char* name{};
const char* type{};
int speed{};
int power{};
int capacity{};
float recoil_distance{};
Texture2D FPP{};
Texture2D SIDE{};
Texture2D FPP_GAME{};
float bar_length{ 140 };
int speed_coef{ 1000 };
int power_coef{ 100 };
int capacity_coef{ 50 };
float speed_display() {
return static_cast<float>(speed) / speed_coef * bar_length;
}
float power_display() {
return static_cast<float>(power) / power_coef * bar_length;
}
float capacity_display() {
return static_cast<float>(capacity) / capacity_coef * bar_length;
}
};
enum GunColor {
STOCK = 0,
CAMO = 1,
CANDY = 2,
GOLDEN = 3
};
struct TimeCard {
float roundness{ 0.01F };
int segments{ 10 };
float width{ 606 };
float height{ 346 };
Color color{ TIME_CARD_COLOR };
struct Button {
int time{};
int points{};
Vector2 coor{};
const char* text_points{};
Color color{};
Color color_hover{TIME_CARD_BUTTON_HOVER};
Color color_cliked{TIME_CARD_BUTTON_CLICKED};
Color text_color{ BLACK };
float font_size{ 54 };
float font_size_points{ 38 };
float font_space{ 1 };
float roundness{ 0.01F };
int segments{ 10 };
float width = 300.F;
float height = 170.F;
Rectangle rect{
coor.x,
coor.y,
width,
height
};
};
Button btn_120{ 120, 2, {400, 348}, "Point = 2", TIME_120_COLOR };
Button btn_90{ 90, 3, {702, 348}, "Point = 3",TIME_90_COLOR };
Button btn_60{ 60, 4, {400, 516}, "Point = 4",TIME_60_COLOR };
Button btn_30{ 30, 6, {702, 516}, "Point = 6",TIME_30_COLOR };
std::vector<Button> timeButtons{ btn_120, btn_90, btn_60, btn_30 };
Color color_hover{ WHITE };
Color color_clicked{ TIME_CARD_COLOR };
};
TimeCard timeCard{};
enum TimeClicked {
SECONDS_120 = 120,
SECONDS_90 = 90,
SECONDS_60 = 60,
SECONDS_30 = 30
};
struct LevelCard {
float roundness{ 0.01F };
int segments{ 10 };
float width{ 606 };
float height{ 346 };
Color color{ LEVEL_CARD_COLOR };
struct Button {
float radius{};
int points{};
const char* text_points{};
Color color{};
Color circle_color{ LEVEL_CARD_COLOR };
Vector2 coor{};
Color color_hover{LEVEL_CARD_BUTTON_HOVER};
Color color_cliked{LEVEL_CARD_BUTTON_CLICKED};
Color text_color{ BLACK };
float font_size{ 54 };
float font_size_points{ 38 };
float font_space{ 1 };
float roundness{ 0.01F };
int segments{ 10 };
float width = 300.F;
float height = 170.F;
Rectangle rect{
coor.x,
coor.y,
width,
height
};
};
Button btn_1{ 30.F, 3, "Point = 3", LEVEL_1_COLOR };
Button btn_2{ 20.F, 5, "Point = 5",LEVEL_2_COLOR };
Button btn_3{ 15.F, 7, "Point = 7",LEVEL_3_COLOR };
Button btn_4{ 10.F, 9, "Point = 9",LEVEL_4_COLOR };
std::vector<Button> levelButtons{ btn_1, btn_2, btn_3, btn_4};
Color color_hover{ WHITE };
Color color_clicked{ LEVEL_CARD_COLOR };
};
LevelCard levelCard{};
enum LevelClicked {
SOFT = 30,
EASY = 20,
MED = 15,
HARD = 10
};
struct HighScoreEntry {
int score{};
std::string date{};
int time{};
std::string level{};
std::string weapon{};
size_t color{};
bool operator<(const HighScoreEntry& other) const {
return score > other.score;
}
std::string getTimeFormatted() const {
int minutes = time / 60;
int seconds = time % 60;
std::ostringstream formattedTime{};
formattedTime << std::setw(2) << std::setfill('0') << minutes << ":"
<< std::setw(2) << std::setfill('0') << seconds;
return formattedTime.str();
}
int getLevelFormatted(const std::string level) const {
//return level_map[level];
std::map<std::string, int> level_map{ {"SOFT", SOFT}, {"EASY", EASY}, {"MED", MED}, {"HARD", HARD} };
auto iterator = level_map.find(level);
if (iterator != level_map.end()) {
return iterator->second;
}
else {
return -1;
}
}
std::string getLevel(const int level_choice) {
std::map<std::string, int> level_map{ {"SOFT", SOFT}, {"EASY", EASY}, {"MED", MED}, {"HARD", HARD} };
for (const auto& i : level_map) {
if (i.second == level_choice) {
return i.first;
}
}
return "";
}
int getWeaponFormatted(const std::string weapon) const {
std::map<std::string, int> weapon_map{ {"M416", M416}, {"AK47", AK47}, {"AWM", AWM}, {"GLOCK", GLOCK} };
//return weapon_map[weapon];
auto iterator = weapon_map.find(weapon);
if (iterator != weapon_map.end()) {
return iterator->second;
}
else {
return -1;
}
}
std::string getWeapon(const int weapon_choice) {
std::map<std::string, int> weapon_map{ {"M416", M416}, {"AK47", AK47}, {"AWM", AWM}, {"GLOCK", GLOCK} };
for (auto& i : weapon_map) {
if (i.second == weapon_choice) {
return i.first;
}
}
return "";
}
};
//bool isFileExists(const char* filename) {
// std::ifstream file(filename);
// return file.good();
//}
bool isFileExists(const char* filename) {
return std::filesystem::exists(filename);
}
void InitFile(const char* filename)
{
if (!isFileExists(filename))
{
std::ofstream file(filename);
if (file.is_open())
{
file << 0;
file.close();
std::cout << "INFO: [SUCCESS] MAKE FILE TXT: " << filename << std::endl;
}
else {
std::cerr << "INFO: [FAILED] MAKE FILE FOR WRITING: " << filename << std::endl;
}
}
else {
std::cout << "INFO: FILE: [" << filename << "] ALREADY EXISTS." << std::endl;
}
}
void saveScore(const std::vector<HighScoreEntry>& highscores) {
std::ofstream outFile(CSV_FILENAME_LEADERBOARDS);
if (outFile.is_open()) {
for (const auto& entry : highscores) {
outFile << entry.score << " "
<< entry.date << " "
<< entry.time << " "
<< entry.level << " "
<< entry.weapon << " "
<< entry.color << std::endl;
}
outFile.close();
std::cout << "INFO: [SUCCESS] Save Score to: " << CSV_FILENAME_LEADERBOARDS << std::endl;
}
else {
std::cout << "INFO: [FAILED] To open file: " << CSV_FILENAME_LEADERBOARDS << std::endl;
}
}
std::vector<HighScoreEntry> loadLeaderboardsTxt() {
std::ifstream LeaderboardsFile(CSV_FILENAME_LEADERBOARDS);
std::vector<HighScoreEntry> highScoreData{};
if (LeaderboardsFile.is_open()) {
HighScoreEntry entry{};
while (LeaderboardsFile >> entry.score >> entry.date >> entry.time >> entry.level >> entry.weapon >> entry.color) {
highScoreData.push_back(entry);
}
LeaderboardsFile.close();
std::cout << "INFO: [SUCCESS] Load data from: " << CSV_FILENAME_LEADERBOARDS << std::endl;
}
return highScoreData;
}
void DisplayMainMenu(GamePage& gamePage, const Font& BigFont, const Font& MainstreamFont);
std::vector<Gun> LoadGunsData();
void DisplaySetupMenu(GamePage& gamePage, std::vector<Gun>& Guns, std::vector<HighScoreEntry>& LeaderboardData, SetupProperties& setupProperties, const Font& BigFont, const Font& MainstreamFont, const Font& NumberFont);
void GunCardDisplay(std::vector<Gun>& Guns, Vector2& mouse_position, const Font& font);
void TimeCardDisplay(Vector2& mouse_position, const Font& font);
void LevelCardDisplay(Vector2& mouse_position, const Font& font);
void DisplayInGame(GamePage& gamePage, std::vector<Gun>& Guns, int time_choice, size_t level_choice, std::chrono::system_clock::time_point& time_start, const Font& font);
Vector2 RandomizeTarget();
void PopupCooldownStart();
void IsPopopCooldownActive();
void DisplayGameOverMenu(GamePage& gamePage, std::vector<HighScoreEntry>& LeaderboardData, std::vector<Gun>& Guns, const Font& BigFont, const Font& MediumFont);
void ResizeContentPopupLeaderboard(std::vector<HighScoreEntry>& LeaderboardData);
std::string getDate();
void ScreenShot();
void btnTimeHoverClikcked(
Vector2& mouse_position, Vector2& btn_clicked, Vector2& btn_hover,
Rectangle& btn_120_rect,
Rectangle& btn_90_rect,
Rectangle& btn_60_rect,
Rectangle& btn_30_rect,
float& line_thick
);
void btnLevelHoverClicked(
Vector2& mouse_position, Vector2& btn_clicked, Vector2& btn_hover,
Rectangle& btn_1_rect,
Rectangle& btn_2_rect,
Rectangle& btn_3_rect,
Rectangle& btn_4_rect,
float& line_thick
);
static Font TitleFont = {};
static Font MediumFont = {};
static Font MainstreamFont = {};
static Font NumberFont = {};
Texture2D ARROW_TEX = {};
Texture2D SCROLL_UP_DOWN_TEX = {};
Texture2D SCROLL_BAR_TEX = {};
Texture2D CLOSE_FIGHT_TEX = {};
Vector2 btn_hover = {};
Vector2 btn_clicked{
(setupMenu.Base_Canvas_rect.x + (setupMenu.Base_Canvas_rect.width - timeCard.width) / 2) + 2 + 4,
(setupMenu.Base_Canvas_rect.y + (setupMenu.Base_Canvas_rect.height - timeCard.height) / 2) + 2 + 4,
};
size_t weapon_choice = {};
size_t weapon_color = {};
int time_choice = { SECONDS_120 };
size_t level_choice = { SOFT };
bool time_start_called = false;
auto time_start = std::chrono::system_clock::now();
int score = {};
bool is_leaderboard_saved_to_txt = true;
bool is_new_data_saved_to_vector_leaderboard = true;
bool popup_cooldown_active = false;
std::vector<bool> is_content_popup_opens{};
std::chrono::steady_clock::time_point popup_fight_timer_start{};
int main() {
SetConfigFlags(FLAG_MSAA_4X_HINT);
SetConfigFlags(FLAG_FULLSCREEN_MODE);
//SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(game.w, game.h, game.title);
//SetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
SetTargetFPS(game.FPS);
SetWindowIcon(LoadImage(ICON_APP_LOC));
TitleFont = LoadFontEx("D:/Coding/Raylib C++/Aim-Trainer/Fonts/Inter/static/Inter-SemiBold.ttf", 140, 0, FONT_DEFAULT);
SetTextureFilter(TitleFont.texture, TEXTURE_FILTER_BILINEAR);
MediumFont = LoadFontEx("D:/Coding/Raylib C++/Aim-Trainer/Fonts/Inter/static/Inter-SemiBold.ttf", 80, 0, FONT_DEFAULT);
SetTextureFilter(MediumFont.texture, TEXTURE_FILTER_BILINEAR);
MainstreamFont = LoadFontEx("D:/Coding/Raylib C++/Aim-Trainer/Fonts/Inter/static/Inter-SemiBold.ttf", 40, 0, FONT_DEFAULT);
SetTextureFilter(MainstreamFont.texture, TEXTURE_FILTER_BILINEAR);
NumberFont = LoadFontEx("D:/Coding/Raylib C++/Aim-Trainer/Fonts/Monomaniac_One/MonomaniacOne-Regular.ttf", 80, 0, FONT_DEFAULT);
SetTextureFilter(NumberFont.texture, TEXTURE_FILTER_BILINEAR);
GamePage gamePage = MAIN_MENU;
SetupProperties setupProperties = GUN;
std::vector<Gun> Guns = LoadGunsData();
Image ARROW = LoadImage(ICON_ARROW_LOC);
ARROW_TEX = LoadTextureFromImage(ARROW);
Color Arrow_TEX_Color = WHITE;
Image SCROLL_BUTTON = LoadImage(ICON_SCROLL_BUTTON_LOC);
SCROLL_UP_DOWN_TEX = LoadTextureFromImage(SCROLL_BUTTON);
SetTextureFilter(SCROLL_UP_DOWN_TEX, TEXTURE_FILTER_BILINEAR);
Image SCROLL_BAR_ACCENT = LoadImage(ICON_SCROLL_BAR_ACC_LOC);
SCROLL_BAR_TEX = LoadTextureFromImage(SCROLL_BAR_ACCENT);
Image CLOSE_FIGHT = LoadImage(ICON_CLOSE_FIGHT_LOC);
CLOSE_FIGHT_TEX = LoadTextureFromImage(CLOSE_FIGHT);
SetTextureFilter(CLOSE_FIGHT_TEX, TEXTURE_FILTER_BILINEAR);
InitFile(CSV_FILENAME_LEADERBOARDS);
std::vector<HighScoreEntry> LeaderboardData = loadLeaderboardsTxt();
ResizeContentPopupLeaderboard(LeaderboardData);
while (!WindowShouldClose()) {
ScreenShot();
BeginDrawing();
ClearBackground(MAINCOLOR);
DrawFPS(5, 5);
switch (gamePage)
{
case MAIN_MENU:
DisplayMainMenu(gamePage, TitleFont, MainstreamFont);
break;
case SETUP_MENU:
DisplaySetupMenu(gamePage, Guns, LeaderboardData, setupProperties, MediumFont, MainstreamFont, NumberFont);
break;
case IN_GAME:
DisplayInGame(gamePage, Guns, time_choice, level_choice, time_start, MediumFont);
break;
case GAMEOVER_MENU:
DisplayGameOverMenu(gamePage, LeaderboardData, Guns, TitleFont, MediumFont);
break;
default:
break;
}
EndDrawing();
}
CloseWindow();
UnloadFont(TitleFont);
return 0;
}
void ScreenShot()
{
if (IsKeyPressed(KEY_S)) {
TakeScreenshot("./Icons/SS.png");
}
}
void DisplayGameOverMenu(GamePage& gamePage, std::vector<HighScoreEntry>& LeaderboardData, std::vector<Gun>& Guns, const Font& BigFont, const Font& MediumFont)
{
ShowCursor();
if (!is_new_data_saved_to_vector_leaderboard) {
HighScoreEntry newData{};
newData.score = score;
newData.date = getDate();
newData.time = time_choice;
newData.level = newData.getLevel((int)level_choice);
newData.weapon = newData.getWeapon((int)weapon_choice);
newData.color = weapon_color;
LeaderboardData.push_back(newData);
is_new_data_saved_to_vector_leaderboard = true;
std::sort(LeaderboardData.begin(), LeaderboardData.end());
is_leaderboard_saved_to_txt = false;
if (LeaderboardData.size() >= LEADERBOARD_DATA_CAPACITY) {
LeaderboardData.pop_back();
}
if (!is_leaderboard_saved_to_txt) {
saveScore(LeaderboardData);
is_leaderboard_saved_to_txt = true;
}
ResizeContentPopupLeaderboard(LeaderboardData);
}
float source_width = (float)Guns.at(weapon_choice).FPP_GAME.width / 4;
float source_height = 1080;
static float gun_pos_y = 0;
float recoil = 0; // BELUM di IMPLEMENTASI
gun_pos_y += recoil;
Rectangle dest = {
0,
gun_pos_y,
source_width,
source_height
};
Rectangle source = { weapon_color * source_width, 0, source_width, source_height };
DrawTexturePro(Guns.at(weapon_choice).FPP_GAME, source, dest, { 0,0 }, 0, WHITE);
{
// SCORE INFO
float font_size = 40;
float font_space = 0.5F;
score = 245;
std::string score_text_string = "Score : " + std::to_string(score);
const char* score_text = score_text_string.c_str();
Vector2 top_pos_info = { 20, 20 };
Vector2 score_text_measure = MeasureTextEx(MediumFont, score_text, font_size, font_space);
Vector2 score_text_coor = {
top_pos_info.x,
top_pos_info.y
};
DrawTextEx(MediumFont, score_text, score_text_coor, font_size, font_space, WHITE);
// TIME INFO
int time = 0;
int minutes = time / 60;
int seconds = time % 60;
std::ostringstream formattedTime{};
formattedTime << std::setw(2) << std::setfill('0') << minutes << ":"
<< std::setw(2) << std::setfill('0') << seconds;
std::string time_string = formattedTime.str();
const char* time_text = time_string.c_str();
Vector2 time_text_measure = MeasureTextEx(MediumFont, time_text, font_size, font_space);
Vector2 time_text_coor = {
GetScreenWidth() - time_text_measure.x - top_pos_info.x,
top_pos_info.y
};
DrawTextEx(MediumFont, time_text, time_text_coor, font_size, font_space, WHITE);
}
// FILTER BLUR TRANSPARENT
DrawRectangleRec(
{ 0,0,(float)GetScreenWidth(), (float)GetScreenHeight() },
Fade(Color{ 38, 38, 41, 255 }, 0.6F)
);
{
// DRAW GAME OVER TITLE
float font_size = 150;
float font_space = 1;
float alpha = 0.75F;
const char* game_over_text = "GAME OVER";
Vector2 game_over_measure = MeasureTextEx(BigFont, game_over_text, font_size, font_space);
Vector2 game_over_coor = {
0 + ((GetScreenWidth() - game_over_measure.x) / 2),
GetScreenHeight() * 0.2F
};
if (CheckCollisionPointRec(GetMousePosition(), { game_over_coor.x, game_over_coor.y, game_over_measure.x, game_over_measure.y })) {
alpha = 0.95F;
}
DrawTextEx(BigFont, game_over_text, game_over_coor, font_size, font_space, Fade(WHITE, alpha));
}
std::vector<std::string> button_text{ "PLAY AGAIN", "SETUP MENU", "QUIT" };
std::vector<Color> button_color{ {140, 196, 68, 255}, {71, 206, 224, 255}, {243, 71, 71, 255} };
{
float width = GetScreenHeight() * 0.35F;
float height = width * 0.25F;
float space_rect = height * 0.4F;
float alpha_rect = {};
Color font_color = BLACK;
float alpha_text = {};
//Rectangle rect = {};
for (size_t i = 0; i < button_text.size(); i++) {
Color color = button_color[i];
Rectangle border_rect = {
(GetScreenWidth() - width) / 2,
(GetScreenHeight() / 2) - (height * 0.7F) + ((height + space_rect) * i),
width,
height
};
float button_padding = 0;
if (CheckCollisionPointRec(GetMousePosition(), border_rect)) {
alpha_rect = 0.85F;
alpha_text = 0.95F;
font_color = WHITE;
std::string text = button_text[i];
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
button_padding = border_rect.height * 0.035F;
}
else {
button_padding = 0;
}
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
if (text == "PLAY AGAIN") {
time_start_called = false;
gamePage = IN_GAME;
}
else if (text == "SETUP MENU") {
gamePage = SETUP_MENU;
}
else if (text == "QUIT") {
CloseWindow();
}
score = 0;
}
}
else {
alpha_rect = 0.4F;
alpha_text = 0.5F;
font_color = BLACK;
}
Rectangle button_rect = {
border_rect.x + button_padding,
border_rect.y + button_padding,
border_rect.width - (button_padding * 2),
border_rect.height - (button_padding * 2)
};
DrawRectangleRounded(button_rect, 0.05F, 10, Fade(color, alpha_rect));
float font_size = button_rect.height * 0.600F;
float font_space = 0;
const char* text = button_text[i].c_str();
Vector2 text_measure = MeasureTextEx(MediumFont, text, font_size, font_space);
Vector2 text_coor = {
button_rect.x + (button_rect.width - text_measure.x) / 2,
button_rect.y + (button_rect.height - text_measure.y) / 2
};
DrawTextEx(MediumFont, text, text_coor, font_size, font_space, Fade(font_color, alpha_text));
}
}
}
void ResizeContentPopupLeaderboard(std::vector<HighScoreEntry>& LeaderboardData)
{
is_content_popup_opens.resize(LeaderboardData.size(), false);
}
void DisplayInGame(GamePage& gamePage, std::vector<Gun>& Guns, int time, size_t level, std::chrono::system_clock::time_point& time_start, const Font& font)
{
HideCursor();
float dt = GetFrameTime();
Gun Gun_Used = Guns.at(weapon_choice);
float recoil_distance = Gun_Used.recoil_distance;
float fire_rate = 0.2F;
static float time_since_last_shot = 0.0F;
static bool is_draw_shoot_fire = false;
static bool is_recoiling = false;
static size_t all_bullet = 200;
size_t magazine_size = Gun_Used.capacity;
static size_t bullet_in_gun = magazine_size;