-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
1890 lines (1800 loc) · 101 KB
/
main.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
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
using namespace sf;
const int levels_count = 4;
bool levels_status[levels_count] = {0, 0, 0, 0};
unsigned short int graph_smoke_animation_delay = 0, current_smoke_animation_frame = 0;
short int index_of_the_last_commit = 0;
const int WINDOW_WIDTH = 1920;
const int WINDOW_HEIGHT = 1080;
string current_screen = "main menu";
string levels_screens[10] = { "intro level", "init level", "commit level", "checkout level" };
int current_level_screen_index = 0;
RenderWindow window(VideoMode::getDesktopMode(), "Git Started!");
// Structs
struct graphHead {
// We have 4 animation frames for the octocat movement (0, 1, 2, 3)
unsigned short int current_animation_frame = 0, idle_animation_delay = 0;
unsigned short int latest_commit_movement_delay = 0;
short int distance_to_checkout_commit = 0, distance_to_latest_commit = (50 + 135);
short int x_border_deflection_velocity = 3, y_border_deflection_velocity = 3;
}graph_head;
struct commit {
string message;
Sprite sprite;
string commit_num;
string commit_code;
};
struct gameLevel
{
vector <pair<int, string>> new_script;
string level_commands[5];
};
struct dialogueBox {
Font font;
Texture texture;
Sprite sprite;
Text title;
string title_content = "Mentor";
double title_size = 32;
string image_path = "resources/sprites/new-mentor-edited.png";
string font_type = "resources/fonts/Righteous-Regular.ttf";
}dialogue_box;
struct continuationMessage
{
Time continuation_fade_time;
Clock continuation_fade_clock;
Font font;
Text continuation_text;
double continuation_delay = 0.8f;
string continuation_content = "Press down to continue...";
bool continuation_message_running = 0;
bool sub_script_ended = 0; // For the sub-strings inside the whole script vector
string font_type = "resources/fonts/BreeSerif-Regular.ttf";
bool commands_flag = 0;
}continuation_message;
struct dialogueText
{
Font font;
Time time;
Clock typewrite_clock; // For the typewriting effect
Text script_text;
string font_type = "resources/fonts/BreeSerif-Regular.ttf";
Color color = Color::Black;
double size = 30;
double script_speed = 0.01f;
String script_content = " ";
int current_script_index = 0;
// The whole vector/dialogue/script
bool script_ended = 0;
}dialogue_text;
struct optionMenu {
Font font;
Text text;
String option_font_type = "resources/fonts/Righteous-Regular.ttf";
const int short size = 64;
};
// For the vectors of pairs
// If bool = 1
// Then it tells the dialogue that it should wait for a command before this dialogue sub-script
// If bool = 2
// Then it tells the dialogue that it should wait for the user to edit in the edit menu before this sub-script
gameLevel level[4] = {
/*level_0 (intro)*/{{
{0 ,""},
{0 ,"* Suddenly...*"},{0,"*someone appears in front of you, they look similar to you but older *"},
{0 ,"Hello! I finally succeeded in going back in time to help\nyou learn from your...umm our mistakes."},
{0 ,"I am you but from the future. I remember this day clearly.\nI was filled with disappointment because of my failure"},{0,"but fear not, i am here to introduce you to a system that changed my life."},
{0 ,"I am talking about \"GIT\"\nIt is a free version control system that tracks all versions of your code."},
{0, "It is created for the sake of aiding us in writing our code.\nIt has useful commands that help us in working with others\nquickly and efficiently."},
{0 ,"I will take you back with my time machine to the start\nof the contest and walk you through all the GIT commands."},
{0 ,"I will try my best to teach you everything about GIT so that you\ncan start your project again with GIT and have a shot\nin winning this contest"},{0,"Are you ready to Git started?"}}},
/*level_1 (git init)*/{{
{0,"Let me show you around our time machine.\nThis blue box is our IDE (like visual studio), where you will be able to\nwrite code."},{0,"The black box you see on your screen (the console) is your tool\nto tell Git what to do."},{0,"but be aware!"},
{0,"GIT will not understand what you wish to do unless you communicate\nwith it in a special syntax (like programming languages)."},
{0,"After showing you around, let's start our adventure by telling\nyou what the word \"command\" means in \"GIT\"."},{0,"\"Commands\" are a set of instructions, each one of them is responsible for\nmaking a certain job."},{0,"We will start with our first command \"Git init\"."},
{0,"Git init tells GIT to start watching your current folder which we call\na git repository (repo for short)."},{0," You won't be able to tell git anything unless you initialize a repository.\nThat's why \"Git init\" has to be the first command to be executed."},
{0,"Let's try executing it together.\nPlease type: \"git init\" in the command line (the black box)"},
{1,"Would you look at that!! That's Git's head \n(Now git has its eyes on you)"},{0, "It will accompany you throughout the game. You will get to know more\nabout the \"GIT head\" in the upcoming levels"}}
,{"git init"}},
/*level_2 (git commit)*/{{
{0,"Now that you've created your first repository (which we will call \"repo\"\nfrom now), you'll start by writing your code."} , {0, "Throughout each big step, you will need to keep track of your history."},
{0,"Imagine this; you are working on a huge project with your team,\none of your teammates messed up a part of their code,\nthey can't remember which part got messed up,\nneither can they go back to the code that worked fine.\nScary to imagine right?"},
{0,"That's where \"commits\" come in hand. \"commits\" are like checkpoints\nin games but for your code.\nWe will use the \"git commit\" command."},
{0,"But first, let's write some code together!\nIn the \"main.cpp\" edit window, we need to write code using C++"},
{0,"For example, try writing: \"int i = 5;\", then save your changes"},
{2,"Now you need to commit your changes to mark this checkpoint!\nIn the command line write: \"git commit\""},
{1,"Congratulations! you have just written your first commit."}, { 0, "This is your git graph, it is a diagram that shows how the commands\nare translated and makes it easier to understand how they work."},
{0,"The circle that just appeared represents our commit. As you can see,\nour Head (Octocat) has appeared above our commit.\nHe will be standing on the latest commit we create."},
{0,"Since he is standing on a commit, Git knows exactly what changes\nyou've made and now the code displayed on the edit window is what\nyou have last written when you formed that commit."},
{0,"You can hover over any commit to view it's commit message"},
{0,"It's your turn to write another piece of code and commit your changes!\nTry adding another variable in \"main.cpp\" edit window."},
{2,"Commit your changes with the message that describes it best!"},
{1,"Notice that the Head moves onto your new commit."},
{0,"And now we will start discovering how these commits come in handy!"}},
{"git commit","git commit"}},
/*level_3 (git checkout)*/{{
{0,"Look at all the commits you have; you must be proud of yourself!"}, {0, "Now as mentioned before our friend (the Head) is looking at the\nlatest commit that we created."},
{0,"But now we need to look at a previous checkpoint of your code,\nwhat do we need to do?"},{0,"We need to move the Head to the commit we want. Each commit\nhas a specified number to show it"},
{0,"We will use a new command which is \"git checkout\"."},{0,"Now, we want to checkout to our first commit (Number 1).\nWrite in the console: \"git checkout\""},
{1,"As you can see in the edit menu, Your code has changed to what you\nfirst wrote in the previous level!"}, {0,"Now let's checkout again to our\nlast commit (2)."}, {1,"Here you have your latest code again!"},
{0,"The \"git checkout\" command has a lot of benefits that you will\ndiscover more in the next levels."}},
{"git checkout" , "git checkout"}}};
// Functions declaration
bool checkInputEquality(string& current_edit_window_input, string& correct_string, bool& edit_window_changed);
void createCliInputShape(RectangleShape& form);
void createCliOutputShape(RectangleShape& form);
void createEditWindowShape(RectangleShape& form);
void setEditWindowText(Text& edit_text, string& edit_input, bool&, RectangleShape& rectangle);
void setCliTexts(Text& text, Text& cli_text_final, string& user_cli_input, string final_cli_input, bool& show_cursor, RectangleShape& rectangle, RectangleShape&, bool& correct_command);
void showCursor(Clock& cursor_clock, bool& show_cursor, bool&, Time& cursor_time);
void drawDialogue(RenderWindow& window, dialogueBox& dialogue_box);
void printDialogueText(dialogueText& dialogue_text);
void playMusicFromFile(string file_path, Music& music);
void updateButtonText(RectangleShape& rectangle, Text& text, string new_text);
void setButtonProperties(RectangleShape& rectangle, int red_intensity, int green_intensity, int blue_intensity, float x_position, float y_position, int transparency = 255);
void setButtonTextProperties(RectangleShape& rectangle, Text& text, Color color);
void setSfxTexts(optionMenu& sfx_text, Sprite& option_menu);
void controlSfxTexts(optionMenu& sfx_text, RectangleShape& mouse_cursor);
void controlOptionsExitButton(Sprite& options_exit_button, RectangleShape& mouse_cursor, Sprite& option_menu);
void setSliderMoveLimits(Sprite slider_bar[], CircleShape slider[]);
void controlSfxAndMusicVolume(optionMenu& sfx_text, Music& music, Sound& pop_commit, Sprite slider_bar[], CircleShape slider[], Sprite& option_menu, RectangleShape& mouse_cursor, Event& event, bool& change_sfx_volume, bool& change_music_volume);
void addCommit(unsigned short int& commits_count, commit commits[], Texture& commit_textures, string commit_message, string& commit_num, string& code);
void showGraphCommitMessage(commit commits[], RectangleShape& mouse_cursor, Text& graph_commit_msg, RectangleShape& graph_commit_msg_shape, bool& show_graph_commit_msg);
void headBorderDeflection(Sprite& head, bool& window_collision_mode, bool& additional_commit_created, RectangleShape& graph);
void headIdleAnimation(Sprite& head, bool& additional_commit_created);
void calculateHeadDistance(Sprite& head, string& checked_out_commit, commit commit[]);
void headAnimationAndMovement(Sprite& head, bool& git_checkout_entered);
void moveHeadToLatestCommit(Sprite& head, bool& additional_commit_created);
void makeSmoke(Sprite& smoke, bool& should_create_smoke);
void commandsInputChecker(string& user_input, bool& git_init_entered, bool& git_add_entered, bool& git_commit_entered, bool& git_checkout_entered, string& checked_out_commit);
void setTextOriginAndPosition(Text& text, float x_position, float y_position);
void showContinuationMessage(continuationMessage& continuation_message, bool& edit_window_changed);
void readProgressFile(string file_name, bool levels_status[], int levels_count);
void updateProgressFile(string file_name, bool levels_status[], int levels_count);
void changeButtonScaleAndColor(RectangleShape& rectangle, float scale, Color color, Color outline_color);
void resetLevels(commit commits[], Sprite& empty_entity, unsigned short int& commits_count, string& commit_num, string& code, bool& window_collision_mode);
void gitCheckoutLevel (unsigned short int& commits_count,bool& additional_commit_created, bool& git_checkout_entered, string& checked_out_commit, string& commit_num, commit commits[], Texture& commit_textures, Sprite& head);
void changeSfxVolume (Sound& correct_command_sound, Sound& incorrect_command_sound, Sound& level_up_sound, Sound& pop_commit);
int main()
{
readProgressFile("progress.txt", levels_status, levels_count);
// Dialogue box
dialogue_box.texture.loadFromFile(dialogue_box.image_path);
dialogue_box.texture.setSmooth(true);
dialogue_box.font.loadFromFile(dialogue_box.font_type);
dialogue_text.font.loadFromFile(dialogue_text.font_type);
continuation_message.font.loadFromFile(continuation_message.font_type);
// Fonts
Font buttons_font;
if (!buttons_font.loadFromFile("resources/fonts/Righteous-Regular.ttf")) {
cout << "Error has happened while loading the buttons font" << endl;
}
Font game_title_font;
if (!game_title_font.loadFromFile("resources/fonts/Glitch inside.otf")) {
cout << "Error has happened while loading the game title font" << endl;
}
Font cli_font;
//cli_font.loadFromFile("resources/fonts/arial.ttf");
if (!cli_font.loadFromFile("resources/fonts/Roboto-Black.ttf")) {
cout << "Error has happened while loading the command line font" << endl;
}
Font arial;
if (!arial.loadFromFile("resources/fonts/arial.ttf")) {
cout << "Error has happened while loading arial font" << endl;
}
Font quote;
quote.loadFromFile("resources/fonts/Righteous-Regular.ttf");
// View
View view;
//FloatRect((1700/2).f, (1080/2).f, 2400.f, 1400.f))
view.setCenter(sf::Vector2f(WINDOW_WIDTH / 2, (WINDOW_HEIGHT / 2)));
view.setSize(sf::Vector2f(WINDOW_WIDTH, WINDOW_HEIGHT));
// Music
Music music;
playMusicFromFile("resources/audio/background audio.wav", music);
music.setVolume(0);
SoundBuffer soundbuffer_1;
soundbuffer_1.loadFromFile("resources/audio/correct command.wav");
Sound correct_command_sound;
correct_command_sound.setBuffer(soundbuffer_1);
correct_command_sound.setVolume(300.0f);
SoundBuffer soundbuffer_2;
soundbuffer_2.loadFromFile("resources/audio/wrong command.wav");
Sound incorrect_command_sound;
incorrect_command_sound.setBuffer(soundbuffer_2);
incorrect_command_sound.setVolume(30.0f);
SoundBuffer soundbuffer_3;
soundbuffer_3.loadFromFile("resources/audio/level up.wav");
Sound level_up_sound;
level_up_sound.setBuffer(soundbuffer_3);
level_up_sound.setVolume(300.0f);
// Credits menu
Texture credits_menu,git_hub_logo_texture;
credits_menu.loadFromFile("resources/sprites/Credit menu v1.0 7-May-2023.png");
git_hub_logo_texture.loadFromFile("resources/sprites/git hub logo.png");
Sprite credits_menu_bg,git_hub_logo;
credits_menu_bg.setTexture(credits_menu);
credits_menu_bg.setScale(0.24f, 0.24f);
git_hub_logo_texture.setSmooth(true);
git_hub_logo.setTexture(git_hub_logo_texture);
git_hub_logo.setOrigin(git_hub_logo.getGlobalBounds().width/2,git_hub_logo.getGlobalBounds().height/2);
git_hub_logo.setPosition(1240,132);
git_hub_logo.setScale(0.5f,0.5f);
Text credits_to_text("Credits to:", buttons_font , 37);
credits_to_text.setPosition(200, 100);
credits_to_text.setStyle(Text::Bold | Text::Underlined);
Text contributers_text("Abdallah Mohamed (SFML Pro)\nAhmed Khaled Yousry (Team Leader)\nAhmed Khaled Eissa (Files Expert)\nHaneen Hany (Design Master)\nRahma Khattab (Bug Slayer)\nRehab Khaled (Innovative Mastermind)\n", cli_font , 50);
contributers_text.setStyle(Text::Italic);
contributers_text.setPosition(200, 160);
Text aim_title_text("Our aim:", cli_font , 37);
aim_title_text.setPosition(200,530);
aim_title_text.setStyle(Text::Bold | Text::Underlined);
Text aim_description_text("We aim to help new people/students who are looking to learn git\nto have the chance to do it while playing a game\nand having fun at the same time.", arial , 32);
aim_description_text.setPosition(200,590);
Text quote_text("\"Always walk through life as if\n\tyou have something new\n\t to learn and you will.\"", quote , 50);
quote_text.setStyle(Text::Italic);
quote_text.setPosition(350, 730);
RectangleShape credits_menu_close_button(Vector2f(215, 75)),credits_menu_back_button(Vector2f(215, 75));
setButtonProperties(credits_menu_close_button, 255, 0, 0, 1705, 180);
setButtonProperties(credits_menu_back_button,46, 139, 87, 1705, 80);
Text credits_menu_close_text("Close", buttons_font, 33),credits_menu_back_text("Back", buttons_font, 33);
setButtonTextProperties(credits_menu_close_button, credits_menu_close_text, Color::Black);
setButtonTextProperties(credits_menu_back_button, credits_menu_back_text, Color::Black);
// Transition slide
Texture transition_slide;
transition_slide.loadFromFile("resources/sprites/Transition background v1.0.png");
Sprite transition_slide_bg;
transition_slide_bg.setTexture(transition_slide);
transition_slide_bg.setScale(0.999f, 0.9999f);
// Transition array of strings (could be put in the levels struct)
string transition_level_texts[10] = { "Please enter your name:","The Git Beginning!\n(git init) \n\n\npress space to continue ","Committing to Success:\nCrafting Meaningful\nCommits \n(git commit) \n\npress space to continue","TimeWarper:\nNavigating the Timeline\n(git checkout) \npress space to continue","thank you" };
Text transition_text(transition_level_texts[current_level_screen_index], game_title_font, 29);
transition_text.setPosition(1310, 700);
transition_text.setFillColor(Color::White);
// Player name input
string player_name;
Text player_name_text("player_name", game_title_font , 32);
player_name_text.setPosition(1310, 750);
player_name_text.setFillColor(Color:: White);
const short int PLAYER_NAME_MAX_CHARS = 17;
bool show_player_name_cursor = 0, player_name_entry = 0;
// Levels menu
RectangleShape levels_menu_back_button(Vector2f(125, 60)), level_buttons_bg(Vector2f(1140, 830)), intro_level_button(Vector2f(1000, 150));
RectangleShape init_level_button(Vector2f(1000, 150)), commit_level_button(Vector2f(1000, 150)), checkout_level_button(Vector2f(1000, 150));
Color const AVAILABLE_LEVELS_BUTTONS_COLOR = Color(48, 74, 91);
Color const UNAVAILABLE_LEVELS_TEXT_COLOR = Color(255, 255, 255, 150);
Color const AVAILABLE_LEVELS_TEXT_COLOR = Color::White;
Color const COMPLETED_LEVELS_TEXT_COLOR = Color(0, 255, 0);
Color const LEVELS_BUTTONS_BORDER_COLOR = Color::Black;
setButtonProperties(levels_menu_back_button, 46, 139, 87, 77, 45);
setButtonProperties(level_buttons_bg, 200, 200, 200, 960, 510);
setButtonProperties(intro_level_button, 48, 74, 91, 960, 245, 200);
setButtonProperties(init_level_button, 48, 74, 91, 960, 430, 200);
setButtonProperties(commit_level_button, 48, 74, 91, 960, 650, 200);
setButtonProperties(checkout_level_button, 48, 74, 91, 960, 825, 200);
Texture levels_menu;
if (!levels_menu.loadFromFile("resources/sprites/levels-menu.jpg")) {
cout << "Error has happened while loading the levels_menu background" << endl;
}
Sprite levels_menu_bg;
levels_menu_bg.setTexture(levels_menu);
levels_menu_bg.setOrigin(levels_menu_bg.getLocalBounds().width / 2.0f, levels_menu_bg.getLocalBounds().height / 2.0f);
levels_menu_bg.setPosition(960, 540);
levels_menu_bg.setScale(1.52f, 1.52f);
// A way to 1 - text.setFont(); 2 - text.setString(); 3 - text.setCharacterSize(); in one line
Text levels_menu_back_button_text("Back", buttons_font, 32), intro_levels_category("Intro", buttons_font, 32);
Text commits_levels_category("Commits", buttons_font, 32);
Text intro_level_text("Tragic Failure: Introducing Git (intro)", buttons_font, 29);
Text init_level_text("The Git Beginning! (git init)", buttons_font, 29);
Text commit_level_text("Committing to Success (git commit)", buttons_font, 29);
Text checkout_level_text("TimeWarper: Navigating the Timeline (git checkout)", buttons_font, 29);
commits_levels_category.setFillColor(Color::Black);
intro_levels_category.setFillColor(Color::Black);
setButtonTextProperties(levels_menu_back_button, levels_menu_back_button_text, Color::Black);
setButtonTextProperties(intro_level_button, intro_level_text, Color::White);
setButtonTextProperties(init_level_button, init_level_text, UNAVAILABLE_LEVELS_TEXT_COLOR);
setButtonTextProperties(commit_level_button, commit_level_text, UNAVAILABLE_LEVELS_TEXT_COLOR);
setButtonTextProperties(checkout_level_button, checkout_level_text, UNAVAILABLE_LEVELS_TEXT_COLOR);
setTextOriginAndPosition(intro_levels_category, 960, 140);
setTextOriginAndPosition(commits_levels_category, 960, 545);
// Command line interface (CLI)
RectangleShape cli_output_shape, cli_input_shape;
int commands_entered_counter = 0;
string user_cli_input, final_cli_input, commit_message, checkout_id;
Text cli_text("", cli_font,32), cli_text_final("", cli_font);
string cli_commit_msg_request = " # Please enter the \ncommit message for\nyour changes in the\ncommand line.";
string cli_checkout_message_rqst = "Please enter number of\nthe commit you want \nto checkout to\n(1, 2 etc.)";
bool show_cli_cursor = 0, cli_selected = 0, commit_command_entered = 0, correct_command = 0, checkout_command_entered = 0,green_command;
Clock cursor_clock;
// Edit Window
RectangleShape edit_window_shape;
string current_edit_window_input = "type here", old_edit_window_input = "type here";
const short int EDIT_WINDOW_MAX_CHARS = 500;
Text edit_window_text(current_edit_window_input, cli_font);
edit_window_text.setCharacterSize(22);
Time cursor_time;
bool edit_window_selected = 0, show_edit_window_cursor = 0, edit_window_changed = 0;
// Next button
RectangleShape game_window_next_button(Vector2f(140, 50));
Text game_window_next_text("Next", buttons_font, 35);
setButtonProperties(game_window_next_button, 60, 154, 145, 1415, 950);
setButtonTextProperties(game_window_next_button, game_window_next_text, Color::Black);
// Save button
RectangleShape edit_window_save_button(Vector2f(333, 50));
Text edit_window_save_text("Save", buttons_font, 35);
setButtonProperties(edit_window_save_button, 110, 164, 198, 1706, 950);
setButtonTextProperties(edit_window_save_button, edit_window_save_text, Color::Black);
// Game window is the window containing the dialogue box, edit window, cli etc.
Texture game_window_bg;
game_window_bg.loadFromFile("resources/sprites/Game menu design.png");
Sprite game_window(game_window_bg);
game_window.setScale(0.618f,0.638f);
string level_title [10] = {"Introducing Git","The Git Beginning!","Committing to Success","TimeWarper: the Timeline"};
Text levels_title(level_title[current_level_screen_index], game_title_font, 45);
levels_title.setPosition(725,30);
levels_title.setFillColor(Color::White);
// Back button
RectangleShape game_window_back_button(Vector2f(333, 82));
Text game_window_back_text("Back", buttons_font, 35);
setButtonProperties(game_window_back_button, 121, 101, 190, 210, 58);
setButtonTextProperties(game_window_back_button, game_window_back_text, Color::Black);
// Options button
RectangleShape game_window_options_button(Vector2f(333, 82));
Text game_window_options_text("Options", buttons_font, 35);
setButtonProperties(game_window_options_button, 60, 154, 145, 1700, 58);
setButtonTextProperties(game_window_options_button, game_window_options_text, Color::Black);
// Main.cpp Rectangle
RectangleShape edit_window_title(Vector2f(340, 45));
Text edit_window_title_text("Main.cpp", buttons_font , 35);
setButtonProperties(edit_window_title, 110, 164, 198, 1705, 173);
setButtonTextProperties(edit_window_title, edit_window_title_text, Color::Black);
edit_window_title.setOutlineColor(Color ::White);
// Main Menu
Text game_title;
game_title.setString("\t Git \n Started");
game_title.setFont(game_title_font);
game_title.setOutlineThickness(-4);
game_title.setFillColor(Color(0, 0, 0)); // Dark grey fill
game_title.setOutlineColor(Color(157, 201, 221));
game_title.setCharacterSize(120);
game_title.setPosition(620, 80);
/*Git Green: RGB(52, 111, 69)
Git Blue: RGB(0, 116, 184)
Git Yellow: RGB(241, 196, 15)
Git Orange: RGB(235, 97, 0)
Green outline Color(100, 255, 30)
Dark grey fill Color(50, 50, 50)*/
// Main Menu Screen buttons
RectangleShape main_menu_start_button(Vector2f(406, 121)), main_menu_options_button(Vector2f(323, 80));
RectangleShape main_menu_close_button(Vector2f(230, 75));
setButtonProperties(main_menu_start_button, 0, 128, 0, 960, 520);
setButtonProperties(main_menu_options_button, 255, 255, 0, 960, 670);
setButtonProperties(main_menu_close_button, 255, 0, 0, 1720, 180);
Text main_menu_start_text("Start", buttons_font, 53), main_menu_options_text("Options", buttons_font, 40);
Text main_menu_close_text("Close", buttons_font, 33);
setButtonTextProperties(main_menu_start_button, main_menu_start_text, Color::Black);
setButtonTextProperties(main_menu_options_button, main_menu_options_text, Color::Black);
setButtonTextProperties(main_menu_close_button, main_menu_close_text, Color::Black);
Texture main_menu_bg;
main_menu_bg.loadFromFile("resources/sprites/main_menu_bg.png");
Sprite main_menu(main_menu_bg);
// Option menu
RectangleShape mouse_cursor(Vector2f(15, 15));
Texture slider_bar_texture, option_menu_texture, options_exit_button_texture;
options_exit_button_texture.loadFromFile("resources/sprites/Exit.png");
option_menu_texture.loadFromFile("resources/sprites/Option menu.png");
slider_bar_texture.loadFromFile("resources/sprites/slide.png");
option_menu_texture.setSmooth(true);
options_exit_button_texture.setSmooth(true);
Sprite slider_bar[2], option_menu, options_exit_button;
CircleShape slider[2];
for (int i = 0; i < 2; i++) {
slider_bar[i].setTexture(slider_bar_texture);
slider[i].setRadius(15);
slider[i].setOrigin(15, 15);
}
option_menu.setTexture(option_menu_texture);
options_exit_button.setTexture(options_exit_button_texture);
option_menu.setOrigin(400, 300);
option_menu.setPosition(WINDOW_WIDTH / 2.0, WINDOW_HEIGHT / 2.0);
options_exit_button.setPosition(option_menu.getGlobalBounds().left + 739, option_menu.getGlobalBounds().top + 16);
optionMenu sfx_text;
slider[0].setPosition(option_menu.getGlobalBounds().left + 151, option_menu.getGlobalBounds().top + 414);
slider[1].setPosition(option_menu.getGlobalBounds().left + 151, option_menu.getGlobalBounds().top + 245);
slider_bar[0].setPosition(option_menu.getGlobalBounds().left + 151, option_menu.getGlobalBounds().top + 409);
slider_bar[1].setPosition(option_menu.getGlobalBounds().left + 151, option_menu.getGlobalBounds().top + 240);
bool change_music_volume = 0, change_sfx_volume = 0;
setSfxTexts(sfx_text, option_menu);
// Option menu
// Graph
RectangleShape graph_commit_msg_shape, graph(Vector2f(1080, 500));
graph.setPosition(420, 155);
graph.setFillColor({ 223, 221, 221 });
graph.setOutlineThickness(8);
graph.setOutlineColor(Color::Black);
Sprite head, smoke, empty_entity;
Texture octacat, commit_textures, smoke_texture, show_commit_message_texture;
show_commit_message_texture.loadFromFile("resources/sprites/show_message.png");
show_commit_message_texture.setSmooth(true);
octacat.loadFromFile("resources/sprites/octocat.png");
octacat.setSmooth(true);
commit_textures.loadFromFile("resources/sprites/commits_sprites.png");
commit_textures.setSmooth(true);
smoke_texture.loadFromFile("resources/sprites/smoke.png");
smoke_texture.setSmooth(true);
smoke.setTexture(smoke_texture);
graph_commit_msg_shape.setTexture(&show_commit_message_texture);
head.setTexture(octacat);
head.setTextureRect(IntRect(0, 0, 200.25, 301));
head.setScale(0.8, 0.8);
head.setOrigin(100.125, 150.5);
head.setPosition(graph.getGlobalBounds().left + 100, 300);
bool additional_commit_created = 0;
bool window_collision_mode = 1, entered_checkout_level = 0;
bool should_create_smoke = 0;
bool show_graph_commit_msg = 0;
bool git_init_entered = 0, git_add_entered = 0, git_commit_entered = 0, git_checkout_entered = 0, animate_commit = 0;
unsigned short int commits_count = 0, commit_code = 1;
const unsigned short int MAX_COMMITS = 100;
SoundBuffer pop_buff;
pop_buff.loadFromFile("resources/audio/pop.wav");
Sound pop_commit;
pop_commit.setBuffer(pop_buff);
pop_commit.setVolume(0);
commit commits[MAX_COMMITS];
window.setFramerateLimit(60);
string checked_out_commit, commit_num = "1", code = " ";
Font graph_commit_msg_font;
graph_commit_msg_font.loadFromFile("resources/fonts/Roboto-Black.ttf");
Text graph_commit_msg;
graph_commit_msg.setCharacterSize(20);
graph_commit_msg.setFont(graph_commit_msg_font);
string code_for_second_commit = "int i = 5;\ncout << i++ << endl;\nint res = calc(i)";
Event event;
while (window.isOpen())
{
Mouse mouse;
Vector2i position = mouse.getPosition(window);
Vector2f world_pos = window.mapPixelToCoords(position);
mouse_cursor.setPosition(world_pos.x, world_pos.y);
while (window.pollEvent(event))
{
if (current_screen == "options" || current_screen == "options_in_game")
controlSfxAndMusicVolume(sfx_text, music, pop_commit, slider_bar, slider, option_menu, mouse_cursor, event, change_sfx_volume, change_music_volume);
if (event.type == Event::Closed || current_screen == "close")
{
updateProgressFile("progress.txt", levels_status, levels_count);
window.close();
}
// Player name entry screen
if(transition_level_texts[current_level_screen_index] == "Please enter your name:")
{
player_name_entry = 1;
}
else
{
player_name_entry = 0;
}
if((Keyboard::isKeyPressed(Keyboard:: Space)) && current_screen == "transition slide" && player_name_entry != 1)
{
current_screen = levels_screens[current_level_screen_index];
transition_text.setString(transition_level_texts[current_level_screen_index+1]);
}
// Mouse click CLI
if (event.type == Event::MouseButtonPressed && event.mouseButton.button == Mouse::Left)
{
if (current_screen == levels_screens[current_level_screen_index])
{
if (game_window_back_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_screen = "levels menu";
current_level_screen_index = 0;
dialogue_text.script_text.setString("");
dialogue_text.current_script_index = 0;
continuation_message.sub_script_ended = 1;
user_cli_input.clear();
final_cli_input.clear();
commands_entered_counter = 0;
dialogue_text.script_ended = 0;
player_name_entry = 0;
resetLevels(commits, empty_entity, commits_count, commit_num, code, window_collision_mode);
entered_checkout_level = 0;
}
if (game_window_next_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))) && dialogue_text.script_ended)
{
//level_up_sound.play();
current_level_screen_index++;
dialogue_text.script_ended = 0;
current_screen = levels_screens[current_level_screen_index];
current_screen = "transition slide";
if(current_level_screen_index>=4){
current_screen = "credits menu";
}
//reset the dialogues in the array of structs
dialogue_text.script_text.setString("");
continuation_message.sub_script_ended = 1;
player_name_entry = 0;
entered_checkout_level = 0;
dialogue_text.current_script_index = 0;
user_cli_input.clear();
final_cli_input.clear();
commands_entered_counter = 0;
levels_title.setString(level_title[current_level_screen_index]);
if (current_level_screen_index == 1)
{
levels_title.setPosition(690, 30);
}
else if (current_level_screen_index == 2)
{
levels_title.setPosition(640, 30);
}
else if (current_level_screen_index == 3)
{
levels_title.setPosition(610, 30);
}
}
if (edit_window_save_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
edit_window_changed = checkInputEquality(current_edit_window_input, old_edit_window_input, edit_window_changed);
code = current_edit_window_input;
}
if (game_window_options_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_screen = "options_in_game";
}
if (cli_input_shape.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
cli_selected = true;
}
else
{
cli_selected = false;
show_cli_cursor = false;
}
// Mouse clicked on edit window
if (edit_window_shape.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
edit_window_selected = true;
}
else
{
edit_window_selected = false;
show_edit_window_cursor = false;
}
}
else if (current_screen == "main menu") {
if (main_menu_start_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_screen = "levels menu";
}
if (main_menu_options_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_screen = "options";
}
if (main_menu_close_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_screen = "close";
}
}
else if (current_screen == "levels menu") {
if (levels_menu_back_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_screen = "main menu";
}
else if (intro_level_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_level_screen_index = 0;
player_name_entry = 0;
current_screen = levels_screens[0];
current_screen = "transition slide";
current_edit_window_input = "type here", old_edit_window_input = "type here";
transition_text.setString(transition_level_texts[current_level_screen_index]);
levels_title.setString("Introducing Git");
levels_title.setPosition(725, 30);
}
else if (init_level_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))) && levels_status[0])
{
git_init_entered = 0;
player_name_entry = 0;
git_commit_entered = 0;
git_checkout_entered = 0;
current_level_screen_index = 1;
current_screen = levels_screens[1];
current_screen = "transition slide";
current_edit_window_input = "type here", old_edit_window_input = "type here";
transition_text.setString(transition_level_texts[current_level_screen_index]);
levels_title.setString("The Git Beginning!");
levels_title.setPosition(690, 30);
}
else if (commit_level_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))) && levels_status[1])
{
git_init_entered = 1;
git_commit_entered = 0;
git_checkout_entered = 0;
current_level_screen_index = 2;
current_screen = levels_screens[2];
current_screen = "transition slide";
player_name_entry = 0;
current_edit_window_input = "type here", old_edit_window_input = "type here";
transition_text.setString(transition_level_texts[current_level_screen_index]);
levels_title.setString("Committing to Success");
levels_title.setPosition(640, 30);
}
else if (checkout_level_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))) && levels_status[2])
{
current_level_screen_index = 3;
player_name_entry = 0;
current_screen = levels_screens[3];
current_screen = "transition slide";
current_edit_window_input = "type here", old_edit_window_input = "type here";
transition_text.setString(transition_level_texts[current_level_screen_index]);
levels_title.setString("TimeWarper: the Timeline");
levels_title.setPosition(610, 30);
entered_checkout_level = 1;
gitCheckoutLevel (commits_count, additional_commit_created, git_checkout_entered, checked_out_commit, commit_num, commits, commit_textures, head);
edit_window_text.setString("int i = 5;\ncout << i++ << endl;\nint res = calc(i)");
}
}
else if (current_screen == "credits menu")
{
if (credits_menu_close_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_screen = "close";
}
if (git_hub_logo.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
string url = "https://github.com/Ahmed-Khaled-dev/git-started";
string command = "start " + url;
system(command.c_str());
}
if (credits_menu_back_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
current_screen = "levels menu";
}
}
}
if (event.type == Event::TextEntered)
{
if(player_name_entry == 1 && player_name.size() <= PLAYER_NAME_MAX_CHARS && current_screen == "transition slide")
{
if (isprint(event.text.unicode))
player_name += event.text.unicode;
}
if (edit_window_selected && current_screen == levels_screens[current_level_screen_index] && level[current_level_screen_index].new_script[dialogue_text.current_script_index].first == 2)
{
if ((edit_window_text.findCharacterPos(current_edit_window_input.size()).y < edit_window_shape.getGlobalBounds().height))
{
// Write in edit window
if (isprint(event.text.unicode)) {
current_edit_window_input += event.text.unicode;
}
// Bounds for text
Vector2f edit_window_char_pos = edit_window_text.findCharacterPos(current_edit_window_input.size());
if (!((edit_window_shape.getGlobalBounds()).contains(edit_window_char_pos))) {
char temp_last = current_edit_window_input[current_edit_window_input.size() - 1];
char temp_before_last = current_edit_window_input[current_edit_window_input.size() - 2];
current_edit_window_input.pop_back();
current_edit_window_input.pop_back();
current_edit_window_input += ("\n");
current_edit_window_input += temp_before_last;
current_edit_window_input += temp_last;
}
}
else
edit_window_selected = false;
}
// Filter out symbols (only characters in ascii code enters)
if (cli_selected && current_screen == levels_screens[current_level_screen_index])
// User inputs in the cli
if (isprint(event.text.unicode))
{
user_cli_input += event.text.unicode;
// Bounds for the cli text
Vector2f cli_char_pos = cli_text.findCharacterPos(user_cli_input.size());
if (!(cli_output_shape.getGlobalBounds().contains(cli_char_pos)))
{
user_cli_input.pop_back();
}
}
}
string str1 = "And last place goes to... ";
string str2 = "!\n*You are devastated but you saw it coming* because your\nteam's code was full of errors and was disorganized";
string output = str1 + player_name + str2;
if(event.type == Event::KeyPressed)
{
if(player_name_entry == 1 && current_screen == "transition slide")
{
if (event.key.code == Keyboard::BackSpace)
{
if(!player_name.empty())
player_name.pop_back();
}
if (event.key.code == Keyboard::Return && !player_name.empty())
{
current_level_screen_index = 0;
current_screen = levels_screens[current_level_screen_index];
player_name_entry = 0;
transition_text.setString(transition_level_texts[current_level_screen_index + 1]);
player_name_text.setString("");
}
}
if(cli_selected)
{
// Delete option
if (event.key.code == Keyboard::BackSpace)
{
if (!user_cli_input.empty())
user_cli_input.pop_back();
}
// User clicks enter and the text will be transfered at the top of the screen
if (event.key.code == Keyboard::Return && (!dialogue_text.script_ended) && !continuation_message.commands_flag && (!user_cli_input.empty()))
{
if (level[current_level_screen_index].new_script[dialogue_text.current_script_index].first == 1)
// Continuation flag is used for stopping input from user after the correct command
{
commandsInputChecker(user_cli_input, git_init_entered, git_add_entered, git_commit_entered, git_checkout_entered, checked_out_commit);
if (user_cli_input == level[current_level_screen_index].level_commands[commands_entered_counter] || (commit_command_entered) || (checkout_command_entered))
correct_command = 1;
else
correct_command = 0;
if (correct_command)
{
// Commit message
if (commit_command_entered && level[current_level_screen_index].level_commands[commands_entered_counter] == "git commit")
{
correct_command_sound.play();
green_command = 1;
final_cli_input = "commit successful \n";
commit_message = user_cli_input;
if (git_commit_entered) {
git_checkout_entered = 0;
addCommit(commits_count, commits, commit_textures, commit_message, commit_num, code);
window_collision_mode = 0;
pop_commit.play();
should_create_smoke = 1;
if (index_of_the_last_commit == 0)
head.setPosition(commits[index_of_the_last_commit].sprite.getPosition().x + 40, commits[0].sprite.getPosition().y - 100);
else if (index_of_the_last_commit == 1) {
head.setPosition(commits[index_of_the_last_commit - 1].sprite.getPosition().x + (40), commits[0].sprite.getPosition().y - 100);
additional_commit_created = 1;
}
else {
head.setPosition(commits[index_of_the_last_commit - 1].sprite.getPosition().x + (40 + 125), commits[0].sprite.getPosition().y - 100);
additional_commit_created = 1;
}
git_add_entered = 0;
git_commit_entered = 0;
}
else
window_collision_mode = 1;
user_cli_input.clear();
commands_entered_counter++;
correct_command = 0;
commit_command_entered = 0;
continuation_message.commands_flag = 1;
}
else if (checkout_command_entered && level[current_level_screen_index].level_commands[commands_entered_counter] == "git checkout")
{
correct_command_sound.play();
checkout_id = user_cli_input;
checked_out_commit = checkout_id;
green_command = 1;
if (checked_out_commit[0] - 48 > index_of_the_last_commit)
git_checkout_entered = 0;
else
git_checkout_entered = 1;
final_cli_input = "checkout successful \n";
user_cli_input.clear();
commands_entered_counter++;
correct_command = 0;
checkout_command_entered = 0;
continuation_message.commands_flag = 1;
}
// This condition needs a follow up, each command is special
// So we use this if condition to adjust the uniqueness of each one
else if (level[current_level_screen_index].level_commands[commands_entered_counter] == "git commit")
{
green_command = 1;
final_cli_input.clear();
final_cli_input = (cli_commit_msg_request + '\n');
commit_command_entered = 1;
continuation_message.commands_flag = 0;
}
else if (level[current_level_screen_index].level_commands[commands_entered_counter] == "git checkout")
{
green_command = 1;
final_cli_input.clear();
final_cli_input = (cli_checkout_message_rqst + '\n');
checkout_command_entered = 1;
continuation_message.commands_flag = 0;
}
else
{
correct_command_sound.play();
green_command = 1;
final_cli_input = ("$ " + user_cli_input);
continuation_message.commands_flag = 1;
commands_entered_counter++;
//correct_command = 0;
}
}
else
{
incorrect_command_sound.play();
green_command = 0;
final_cli_input = "$ " + user_cli_input;
}
user_cli_input.clear();
}
}
}
// Delete and enter for edit window
if (edit_window_selected && level[current_level_screen_index].new_script[dialogue_text.current_script_index].first == 2)
{
if (event.key.code == Keyboard::BackSpace && level[current_level_screen_index].new_script[dialogue_text.current_script_index].first == 2)
{
if (!current_edit_window_input.empty())
current_edit_window_input.pop_back();
}
if (event.key.code == Keyboard::Return && level[current_level_screen_index].new_script[dialogue_text.current_script_index].first == 2)
{
current_edit_window_input += ("\n");
}
}
}
if (event.type == Event::MouseMoved) {
if (main_menu_start_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
changeButtonScaleAndColor(main_menu_start_button, 0.9f, Color(34, 139, 34), Color::Black);
}
else
{
changeButtonScaleAndColor(main_menu_start_button, 1.0f, Color::Green, Color::Black);
}
if (main_menu_options_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
changeButtonScaleAndColor(main_menu_options_button, 0.9f, Color(153, 153, 0), Color::Black);
}
else
{
changeButtonScaleAndColor(main_menu_options_button, 1.0f, Color(Color::Yellow), Color::Black);
}
if (main_menu_close_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
changeButtonScaleAndColor(main_menu_close_button, 0.9f, Color(139, 0, 0), Color::Black);
}
else
{
changeButtonScaleAndColor(main_menu_close_button, 1.0f, Color::Red, Color::Black);
}
if (credits_menu_close_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
changeButtonScaleAndColor(credits_menu_close_button, 0.9f, Color(139, 0, 0), Color::Black);
}
else
{
changeButtonScaleAndColor(credits_menu_close_button, 1.0f, Color::Red, Color::Black);
}
if (git_hub_logo.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
git_hub_logo.setScale(0.6f,0.6f);
}
else
{
git_hub_logo.setScale(0.5f,0.5f);
}
if (edit_window_save_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
edit_window_save_button.setFillColor(Color(130, 185, 205));
edit_window_save_button.setScale(0.9f, 0.9f);
}
else
{
edit_window_save_button.setFillColor(Color(110, 164, 198));
edit_window_save_button.setScale(1.0f, 1.0f);
}
if (game_window_options_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
game_window_options_button.setFillColor(Color(40, 134, 125));
game_window_options_button.setScale(0.9f, 0.9f);
}
else
{
game_window_options_button.setFillColor(Color(60, 154, 145));
game_window_options_button.setScale(1.0f, 1.0f);
}
if (game_window_back_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
game_window_back_button.setFillColor(Color(101, 81, 170));
game_window_back_button.setScale(0.9f, 0.9f);
}
else
{
game_window_back_button.setFillColor(Color(121,101,190));
game_window_back_button.setScale(1.0f, 1.0f);
}
if (credits_menu_back_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
changeButtonScaleAndColor(credits_menu_back_button, 0.9f, Color(153, 153, 0), Color::Black);
}
else
{
changeButtonScaleAndColor(credits_menu_back_button, 1.0f, Color::Yellow, Color::Black);
}
if (levels_menu_back_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
changeButtonScaleAndColor(levels_menu_back_button, 0.9f, Color(140, 140, 140), Color::Black);
}
else
{
changeButtonScaleAndColor(levels_menu_back_button, 1.0f, Color(46, 139, 87), Color::Black);
}
/* if you write the if conditions related to the colors and hover on effect that are determined by the state of the level (passed or not) as only ifs
the code always execute the first if that is written and satisfied only and discards the others even if the argument is satisfied
(so basically i had to make the conditions in decending order and related in entangled if - if else relationship)*/
if (levels_status[3]) {
if (checkout_level_button.getGlobalBounds().contains(window.mapPixelToCoords(Mouse::getPosition(window))))
{
setButtonTextProperties(checkout_level_button, checkout_level_text, COMPLETED_LEVELS_TEXT_COLOR);
changeButtonScaleAndColor(checkout_level_button, 0.9f, AVAILABLE_LEVELS_BUTTONS_COLOR, LEVELS_BUTTONS_BORDER_COLOR);
}
else
{
setButtonTextProperties(checkout_level_button, checkout_level_text, COMPLETED_LEVELS_TEXT_COLOR);
changeButtonScaleAndColor(checkout_level_button, 1.0f, AVAILABLE_LEVELS_BUTTONS_COLOR, LEVELS_BUTTONS_BORDER_COLOR);