-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource.cpp
2340 lines (2142 loc) · 70.1 KB
/
Source.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 <sstream>
#include <ctime>
#include<string>
#include<vector>
using namespace std;
using namespace sf;
int twoplayers_bothloseindex = -5, twoplayers_pauseindex = -7, twoplayers_gameoverindex = -4, twoplayersindex = -3, gameoverindex = -2
, namescreenindex = -1, gameindex = 0, instructionindex = 1, profileindex = 2, highscoresindex = 3,
soundoptionsindex = 4, creditsindex = 5, exitindex = 6, pauseindex = 7, modemenuindex = 8, mainmenuindex = 10;
Font font;
//game Functions
void main_menu();
void instructions_menu();
void profile_options();
void outleaderboard();
void re_sort_score();
void topfive_set();
struct player {
string name;
int score;
} liveplayer;
bool scorecompare(player player1, player player2);
void sound_options();
void game_reset();
void twoplayers_mode_set();
void twoplayers_mode();
void twoplayers_pausemenu();
void character_pick();
bool r = false, colliderre = false, colliderre1 = false;
int highjcounter = 0;
//Start menu variables
int mouse_pos = 0;
int selectedItemIndex = 0, selecteditemorder = 10;
const int MENU_ITEMS = 7;
Text menu[MENU_ITEMS];
Sprite menubackg, cursor[11];
Event tostart;
Texture curs;
//instruction variables
string instruct_names[4] = { "instructions1.jpg","instructions2.jpg","instructions3.jpg" ,"instructions4.jpg" };
Texture instruct[4];
Sprite instructions[4];
int shown_instruct = 0;
//Profile variables
Texture trump_icon, icy_icon, dancer_icon;
Text inprofile_menu[2];
Sprite character[3];
int UD = 0, RL = 0;
int picked_char = 0;
//High score variables
// Files
string rest;
int resu;
int players_number = 0;
ofstream scoreboardout("Dashboard.txt", ios::app);
ifstream scoreboardin("Dashboard.txt");
//High scores menu
Text topfive[6][2];
ostringstream billboardconvertor;
vector<player>billboard;
//sound options variables
Sprite sound_level[12], music_level[12];
Text inSound_menu[3];
Sound sound, music;
int musicpointer = 5, soundpointer = 5, soundmenuindex = 0;
Sound loswav;
Sound hoob;
Sound insid;
Sound alarm;
//mode selection variables
// 2 player name screen variables
Text entered_name;
Text modes[3];
Text character_choose;
string player1_name, player2_name;
RectangleShape pointer(Vector2f(80, 90));
CircleShape pointing(15);
Sprite characters[3];
int screennumber = 0;
int selectedplayersIndex = 0;
int player1_character, player2_character;
// 1 player name screen variables
Sprite namescreen;
long long livescore = 0;
string livename;
Text name_enter;
//Text entered_name;
//Pause Menu Select variables
const int PAUSED_ITEMS = 2;
Text pausetext[PAUSED_ITEMS];
int selectedPauseIndex = 0;
Sprite pause;
// *********************************************
//Game Main variable
// 1 player mode
Texture trumpcharacter0, icycharacter0, dancercharacter0;
RectangleShape collider(Vector2f(9, 10));
Sprite icy[3];
Clock highjclock;
Vector2u clocksize;
IntRect clockanim;
Clock watch, scrollspeedclock;
Clock stopwatchclock;
Sprite stopwatch;
//Hurry UP
Texture hurry;
Sprite hurryT;
Clock hurryclock;
bool isHurry = false;
//Backgrounds
Texture back1, back2;
Sprite backg11, backg12, backg21, backg22;
//blocks
int blocksno = 0, blockcounter = 1, color_number = 0;
int hor, ver = 540;
int blockvalue[8];
int b_scale;
float arr[6] = { 0.5,0.6,0.7,0.8,0.9,1 };
string b_colors[5] = { "level 1.png","level 2.png" ,"level 3.png" ,"level 4.png" ,"level 5.png" };
string levelsg_colors[5] = { "glevel 1.png","glevel 2.png" ,"glevel 3.png" ,"glevel 4.png" ,"glevel 5.png" };
Texture blockshape[5];
Texture levelsg[5];
Texture startg;
Sprite ground_b;
Sprite b_drawer[10];
//scrolling
//jump
Vector2f vi;
float g = 0;
int j = 0;
bool highj = false;
// 2 players mode variables
Sprite twoplayers_icy[3];
RectangleShape twoplayers_collider[3];
RectangleShape twoplayers_fightcollider[3];
Vector2f vi0[3];
bool twolastpc[3], twolastpc2[3];
float twodist[3];
float twolastp[3];
int jumpinghandler[3] = { 0 };
float gravity[3] = { 0 };
Clock highjclock2[3];
Text winner;
Text loser;
Texture winnerT;
Sprite winnerS;
Texture twoplayersloseT;
Sprite twoplayersloseS;
void main_menu() {
//Keyboard Event
/* Move Up */
if (tostart.type == Event::KeyReleased) {
if (tostart.key.code == Keyboard::Up) {
if (selectedItemIndex - 1 >= 0) {
menu[selectedItemIndex].setFillColor(Color::Black);
cursor[mainmenuindex].move(0, -49);
selectedItemIndex--;
menu[selectedItemIndex].setFillColor(Color::Red);
}
}
/* Move Down */
if (tostart.key.code == Keyboard::Down) {
if (selectedItemIndex + 1 < MENU_ITEMS) {
menu[selectedItemIndex].setFillColor(Color::Black);
cursor[mainmenuindex].move(0, 49);
selectedItemIndex++;
menu[selectedItemIndex].setFillColor(Color::Red);
}
}
}
//Mouse Event
if (tostart.type == Event::MouseMoved)
{
if (tostart.mouseMove.x >= 476 && tostart.mouseMove.x <= 760) {
if (tostart.mouseMove.y >= 235 && tostart.mouseMove.y <= 600) {
mouse_pos = (tostart.mouseMove.y - 235) / 50;
selectedItemIndex = mouse_pos;
for (int i = 0; i < MENU_ITEMS; i++)
menu[i].setFillColor(Color::Black);
menu[selectedItemIndex].setFillColor(Color::Red);
cursor[mainmenuindex].setPosition(420, 235 + mouse_pos * 49);
}
}
}
if (tostart.type == Event::KeyPressed) {
if (tostart.key.code == Keyboard::Space || tostart.key.code == Keyboard::Enter ||
(tostart.type == Event::MouseButtonPressed && tostart.mouseButton.button == Mouse::Left)
) {
switch (selectedItemIndex) {
case 0: selecteditemorder = modemenuindex; screennumber = 0; break;
case 1: selecteditemorder = instructionindex; break;
case 2: selecteditemorder = profileindex; break;
case 3: selecteditemorder = highscoresindex; break;
case 4: selecteditemorder = soundoptionsindex; break;
case 5: selecteditemorder = creditsindex; break;
case 6: selecteditemorder = exitindex; break;
}
}
}
}
//Instructions
void instructions_menu() {
if (Keyboard::isKeyPressed(Keyboard::Right)) {
if (shown_instruct < 3)shown_instruct++;
}
else if (Keyboard::isKeyPressed(Keyboard::Left)) {
if (shown_instruct > 0)shown_instruct--;
}
}
//Profiles
//int UD , RL ;
void profile_options() {
if (Keyboard::isKeyPressed(Keyboard::Down)) {
UD = 1;
cursor[profileindex].setPosition(430, 400);
inprofile_menu[1].setFillColor(Color::Red);
inprofile_menu[0].setFillColor(Color::Black);
}
else if (Keyboard::isKeyPressed(Keyboard::Up)) {
UD = 0;
cursor[profileindex].setPosition(430, 250);
inprofile_menu[0].setFillColor(Color::Red);
inprofile_menu[1].setFillColor(Color::Black);
}
if (UD == 0) {
if (tostart.type == Event::KeyPressed) {
if (Keyboard::isKeyPressed(Keyboard::Right)) {
if (RL < 2)
RL++;
}
else if (Keyboard::isKeyPressed(Keyboard::Left)) {
if (RL > 0)
RL--;
}
if (tostart.key.code == Keyboard::Enter || tostart.key.code == Keyboard::Space) {
switch (RL)
{
case 0:picked_char = 0; selecteditemorder = mainmenuindex; break;
case 1:picked_char = 1; selecteditemorder = mainmenuindex; break;
case 2:picked_char = 2; selecteditemorder = mainmenuindex; break;
}
}
}
}
else if (UD == 1) {
if (tostart.type == Event::KeyPressed) {
if (Keyboard::isKeyPressed(Keyboard::Enter)) {
selecteditemorder = mainmenuindex;
cursor[profileindex].setPosition(430, 250);
inprofile_menu[0].setFillColor(Color::Red);
inprofile_menu[1].setFillColor(Color::Black);
UD = 0;
}
}
}
}
//High Scores
/*
High score options has been merged with name screen options in line 190
High score setup will start from line 242
due to the need of that
*/
//sound options
void sound_options() {
if (Keyboard::isKeyPressed(Keyboard::Down)) {
sound.play();
if (soundmenuindex >= 2)cursor[soundoptionsindex].move(0, 0);
else
{
cursor[soundoptionsindex].move(0, 100); soundmenuindex++;
inSound_menu[soundmenuindex].setFillColor(Color::Red);
inSound_menu[soundmenuindex - 1].setFillColor(Color::Black);
}
}
else if (Keyboard::isKeyPressed(Keyboard::Up)) {
sound.play();
if (soundmenuindex <= 0) cursor[soundoptionsindex].move(0, 0);
else
{
cursor[soundoptionsindex].move(0, -100); soundmenuindex--;
inSound_menu[soundmenuindex].setFillColor(Color::Red);
inSound_menu[soundmenuindex + 1].setFillColor(Color::Black);
}
}
switch (soundmenuindex)
{
case 0:if (musicpointer <= 10) {
if (Keyboard::isKeyPressed(Keyboard::Right))musicpointer++;
if (Keyboard::isKeyPressed(Keyboard::Left) && musicpointer > 0)musicpointer--;
music.setVolume(10 * musicpointer);
insid.setVolume(10 * musicpointer);
}
else musicpointer = 10;
break;
case 1:if (soundpointer <= 10) {
if (Keyboard::isKeyPressed(Keyboard::Right))soundpointer++;
if (Keyboard::isKeyPressed(Keyboard::Left) && soundpointer > 0)soundpointer--;
sound.setVolume(10 * soundpointer);
loswav.setVolume(10 * soundpointer);
hoob.setVolume(10 * soundpointer);
alarm.setVolume(10 * soundpointer);
}
else soundpointer = 10;
break;
case 2:if (tostart.type == Event::KeyReleased) {
if (tostart.key.code == Keyboard::Space) {
cursor[soundoptionsindex].setPosition(430, 250);
soundmenuindex = 0;
inSound_menu[0].setFillColor(Color::Red);
inSound_menu[2].setFillColor(Color::Black);
selecteditemorder = 10;
selectedItemIndex = 4;
}
break;
}
}
}
//mode select
// 1 player Namescreen
void name_enter_loop() {
if (livename.size() < 10) {
if (tostart.type == Event::TextEntered)
{
livename += tostart.text.unicode;
entered_name.setString(livename);
}
}
}
// 2 platers Namescreen
void twoplayers_name_enter_loop() {
if (screennumber == 1) {
if (player1_name.size() < 10) {
if (tostart.type == Event::TextEntered)
{
player1_name += tostart.text.unicode;
entered_name.setString(player1_name);
}
}
}
if (screennumber == 3) {
if (player2_name.size() < 10) {
if (tostart.type == Event::TextEntered)
{
player2_name += tostart.text.unicode;
entered_name.setString(player2_name);
}
}
}
}
//players menu
void modeselection_menu() {
if (tostart.type == Event::KeyReleased) {
if (tostart.key.code == Keyboard::Down) {
if (selectedplayersIndex + 1 < 3) {
modes[selectedplayersIndex].setFillColor(Color::Black);
cursor[modemenuindex].move(0, 70);
selectedplayersIndex++;
modes[selectedplayersIndex].setFillColor(Color::Red);
}
} //move up
else if (tostart.key.code == Keyboard::Up) {
if (selectedplayersIndex - 1 >= 0) {
modes[selectedplayersIndex].setFillColor(Color::Black);
cursor[modemenuindex].move(0, -70);
selectedplayersIndex--;
modes[selectedplayersIndex].setFillColor(Color::Red);
}
}
}
if (tostart.type == Event::KeyPressed) {
if (Keyboard::isKeyPressed(Keyboard::Enter) || Keyboard::isKeyPressed(Keyboard::Space)) {
switch (selectedplayersIndex) {
case 0: selecteditemorder = namescreenindex;
entered_name.setString(livename); break;
case 1: screennumber = 1;
entered_name.setString(player1_name); break;
case 2: selecteditemorder = mainmenuindex; break;
}
}
}
}
int pickno = 0;
void character_pick() {
if (tostart.type == Event::KeyPressed && tostart.key.code == Keyboard::Right) {
if (pickno < 2) {
pickno++;
pointer.move(120, 0);
pointer.setFillColor(Color(0, 0, 0, 50));
}
}
else if (tostart.type == Event::KeyPressed && tostart.key.code == Keyboard::Left) {
if (pickno > 0) {
pickno--;
pointer.move(-120, 0);
pointer.setFillColor(Color(0, 0, 0, 50));
}
}
if (tostart.type == Event::KeyPressed && tostart.key.code == Keyboard::Enter) {
if (screennumber == 2) {
player1_character = pickno;
pickno = 0;
screennumber = 3;
entered_name.setString(player2_name);
pointer.setPosition(Vector2f(226, characters[0].getPosition().y - 1));
}
else if (screennumber == 4) {
if (player1_character != pickno) {
player2_character = pickno;
twoplayers_mode_set();
game_reset();
pickno = 0;
pointer.setPosition(Vector2f(226, characters[0].getPosition().y - 1));
selecteditemorder = twoplayersindex;
}
else
pointer.setFillColor(Color(255, 0, 0, 50));
}
}
}
//Game Over
Texture gameoverT;
Sprite gameover;
void game_over() {
if (tostart.type == Event::KeyReleased) {
if (tostart.key.code == Keyboard::Space)
selecteditemorder = mainmenuindex;
}
}
//Pause Menu Select
void pause_menu() {
/* Move Left */
if (tostart.type == Event::KeyReleased) {
if (tostart.key.code == Keyboard::Left) {
if (selectedPauseIndex - 1 >= 0) {
pausetext[selectedPauseIndex].setFillColor(Color::Black);
selectedPauseIndex--;
pausetext[selectedPauseIndex].setFillColor(Color::Red);
}
}
/* Move Right */
if (tostart.key.code == Keyboard::Right) {
if (selectedPauseIndex + 1 < PAUSED_ITEMS) {
pausetext[selectedPauseIndex].setFillColor(Color::Black);
selectedPauseIndex++;
pausetext[selectedPauseIndex].setFillColor(Color::Red);
}
}
if (tostart.key.code == Keyboard::Space || tostart.key.code == Keyboard::Enter) {
switch (selectedPauseIndex) {
case 0: selecteditemorder = gameindex; break;
case 1:selecteditemorder = mainmenuindex; screennumber = 0; break;
}
}
}
}
// #4
void topfive_set() {
for (int i = 1; i < 6; i++) {
for (int j = 0; j < 2; j++) {
topfive[i][j].setFillColor(Color::Black);
topfive[i][j].setCharacterSize(45);
topfive[i][0].setPosition(Vector2f(150, 180 + 50 * i));
topfive[i][1].setPosition(Vector2f(505, 180 + 50 * i));
}
}
for (int i = 1; i < 6; i++) {
billboardconvertor.str("");
topfive[i][0].setString(billboard[i - 1].name);
billboardconvertor << billboard[i - 1].score;
topfive[i][1].setString(billboardconvertor.str());
}
}
// #3
bool scorecompare(player player1, player player2) {
return player1.score > player2.score;
}
// #2
//score sort
void re_sort_score() {
sort(billboard.begin(), billboard.end(), scorecompare);
}
// #5
// Last store Export
void outleaderboard() {
liveplayer.score = livescore;
billboard.push_back(liveplayer);
scoreboardout << billboard[billboard.size() - 1].name;
scoreboardout << " ";
scoreboardout << billboard[billboard.size() - 1].score;
re_sort_score();
selecteditemorder = mainmenuindex;
}
// #1
//score restoring
void restorescore() {
while (scoreboardin) {
scoreboardin >> rest;
scoreboardin >> resu;
if (rest == "-1")
break;
liveplayer.name = rest;
liveplayer.score = resu;
billboard.push_back(liveplayer);
players_number++;
}
scoreboardin.close();
billboard.pop_back();
re_sort_score();
}
//blocks
void blocks() {
hor = 80 + rand() % 375;
ver -= 100;
b_scale = 0 + rand() % 6;
blocksno++;
blockcounter++;
}
int blok = 0;
Text blokno;
ostringstream convertblocks;
string inconvertblocks;
//scrolling
float remaining_time = 0, scrollspeed = 1;
bool isStart = false;
bool isscrolling = false;
int movespeed = 1;
void scrolling() {
backg11.move(Vector2f(0, 0.3));
backg12.move(Vector2f(0, scrollspeed * movespeed));
backg21.move(Vector2f(0, 0.3));
backg22.move(Vector2f(0, scrollspeed * movespeed));
for (int i = 0; i < 8; i++) {
b_drawer[i].move(Vector2f(0, scrollspeed * movespeed));
}
ground_b.move(Vector2f(0, scrollspeed * movespeed));
blokno.move(Vector2f(0, scrollspeed * movespeed));
if (backg21.getPosition().y >= 0 && backg21.getPosition().y <= 1) {
isStart = true;
backg11.setPosition(0, -599);
}
else if (backg11.getPosition().y >= 0 && backg11.getPosition().y <= 1 && isStart == true) {
backg21.setPosition(0, -599);
}
if (backg22.getPosition().y >= 0 && backg22.getPosition().y <= 1.5 * (scrollspeed * movespeed)) {
isStart = true;
backg12.setPosition(0, -599);
}
else if (backg12.getPosition().y >= 0 && backg12.getPosition().y <= 1.5 * (scrollspeed * movespeed) && isStart == true) {
backg22.setPosition(0, -599);
}
if (selecteditemorder == gameindex) {
icy[picked_char].move(Vector2f(0, scrollspeed * movespeed));
collider.move(Vector2f(0, scrollspeed * movespeed));
if (icy[picked_char].getPosition().y < -2) {
icy[picked_char].setPosition(Vector2f(icy[picked_char].getPosition().x, 1));
collider.setPosition(Vector2f(collider.getPosition().x, 61));
}
else if (icy[picked_char].getPosition().y < 20)
movespeed = 5;
else if (icy[picked_char].getPosition().y > 100)
movespeed = 1;
}
else if (selecteditemorder == twoplayersindex) {
twoplayers_icy[player1_character].move(Vector2f(0, scrollspeed * movespeed));
twoplayers_collider[player1_character].move(Vector2f(0, scrollspeed * movespeed));
twoplayers_fightcollider[player1_character].move(Vector2f(0, scrollspeed * movespeed));
twoplayers_icy[player2_character].move(Vector2f(0, scrollspeed * movespeed));
twoplayers_collider[player2_character].move(Vector2f(0, scrollspeed * movespeed));
twoplayers_fightcollider[player2_character].move(Vector2f(0, scrollspeed * movespeed));
if (twoplayers_icy[player1_character].getPosition().y < -2) {
twoplayers_icy[player1_character].setPosition(Vector2f(twoplayers_icy[player1_character].getPosition().x, 1));
twoplayers_collider[player1_character].setPosition(Vector2f(twoplayers_collider[player1_character].getPosition().x, 61));
}
else if (twoplayers_icy[player1_character].getPosition().y < 30 ||
twoplayers_icy[player2_character].getPosition().y < 30)
movespeed = 5;
else if (twoplayers_icy[player1_character].getPosition().y > 100 &&
twoplayers_icy[player2_character].getPosition().y > 100)
movespeed = 1;
if (twoplayers_icy[player2_character].getPosition().y < -2) {
twoplayers_icy[player2_character].setPosition(Vector2f(twoplayers_icy[player2_character].getPosition().x, 1));
twoplayers_collider[player2_character].setPosition(Vector2f(twoplayers_collider[player2_character].getPosition().x, 61));
}/*
else if (twoplayers_icy[player2_character].getPosition().y < 30)
movespeed = 5;
else if (twoplayers_icy[player2_character].getPosition().y > 100)
movespeed = 1;
*/
}
for (int i = 0; i < 7; i++) {
if (b_drawer[i].getPosition().y >= 600) {
if (i == 0)ver = b_drawer[6].getPosition().y;
else ver = b_drawer[i - 1].getPosition().y;
blocks();
b_drawer[i].setScale(arr[b_scale], 1);
b_drawer[i].setPosition(Vector2f(hor, ver));
blockvalue[i] = blocksno;
b_drawer[i].setTexture(blockshape[color_number]);
if (blockcounter == 10)
{
if (color_number < 4) {
b_drawer[7].setTexture(levelsg[color_number + 1]);
blok += 10;
convertblocks << blok;
inconvertblocks = convertblocks.str();
blokno.setString(inconvertblocks);
blokno.setPosition(400, ver + 10);
blokno.setFont(font);
blokno.setCharacterSize(20);
blokno.setFillColor(Color::White);
inconvertblocks.clear();
convertblocks.str("");
}
else {
b_drawer[7].setTexture(levelsg[0]);
blok += 10;
convertblocks << blok;
inconvertblocks = convertblocks.str();
blokno.setString(inconvertblocks);
blokno.setPosition(400, ver + 10);
blokno.setFont(font);
blokno.setCharacterSize(20);
blokno.setFillColor(Color::White);
inconvertblocks.clear();
convertblocks.str("");
}
b_drawer[7].setPosition(90, ver);
blockvalue[7] = blocksno;
blockcounter = 0;
color_number++;
if (color_number > 4)color_number = 0;
}
break;
}
}
}
//reset original game positions to re play
Text score[2];
//long long livescore = 0;
void game_reset() {
backg11.setPosition(0, 0);
backg12.setPosition(0, 0);
backg21.setPosition(0, -599);
backg22.setPosition(0, -599);
icy[picked_char].setRotation(0);
icy[picked_char].setOrigin(0, 0);
icy[picked_char].setPosition(Vector2f(400, 480));
collider.setPosition(Vector2f(435, 540));
highj = false;
ver = 540;
blockcounter = 0;
b_drawer[7].setPosition(90, 650);
ground_b.setPosition(90, 540);
blocksno = 0;
j = 0;
scrollspeed = 1;
for (int i = 0; i < 7; i++) {
blocks();
b_drawer[i].setPosition(hor, ver);
b_drawer[i].setScale(1.0f, 1.0f);
b_drawer[i].scale(arr[b_scale], 1);
blockvalue[i] = blocksno;
}
livescore = 0;
ostringstream scoreconverter; scoreconverter << livescore;
string inscreenscore = scoreconverter.str();
score[1].setString(inscreenscore);
vi.y = 0; g = 0;
isscrolling = false;
clockanim.left = 0;
stopwatch.setTextureRect(clockanim);
color_number = 0;
for (int i = 0; i < 7; i++)
b_drawer[i].setTexture(blockshape[color_number]);
blok = 0;
inconvertblocks.clear();
convertblocks.str("");
isHurry = false;
}
int main() {
restorescore();
RenderWindow window(VideoMode(800, 600), "ICY TOWER GEN33");
Image icon;
icon.loadFromFile("cursor.png");
window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
window.setFramerateLimit(120);
curs.loadFromFile("cursor.png");
for (int i = 0; i < 11; i++) {
cursor[i].setTexture(curs);
cursor[i].setScale(0.07, 0.09);
}
//starting menu
Texture intro;
intro.loadFromFile("intro-background.jpg");
menubackg.setTexture(intro);
/* Font */
font.loadFromFile("ARABOLIC.ttf");
/* Play */
menu[0].setFont(font);
menu[0].setFillColor(Color::Red);
menu[0].setString("Play Game");
menu[0].setPosition({ 476.0f,235.0f });
menu[0].setCharacterSize(45);
cursor[mainmenuindex].setPosition(Vector2f(420.0f, 243.0f));
//Mode selection
//Text modes[3];
for (int i = 0; i < 3; i++) {
modes[i].setFont(font);
modes[i].setFillColor(Color::Black);
modes[i].setCharacterSize(45);
modes[i].setPosition(476, 235 + (i * 70));
}
modes[0].setFillColor(Color::Red);
modes[0].setString("one player");
modes[1].setString("two players");
modes[2].setString("Back");
cursor[modemenuindex].setPosition(Vector2f(420.0f, 243.0f));
Text twoplayers_headertext[2];
for (int i = 0; i < 2; i++) {
twoplayers_headertext[i].setFont(font);
twoplayers_headertext[i].setCharacterSize(40);
twoplayers_headertext[i].setPosition(Vector2f(130, 200));
twoplayers_headertext[i].setFillColor(Color::Red);
}
twoplayers_headertext[0].setString("Enter player one Name:");
twoplayers_headertext[1].setString("Enter player two Name:");
character_choose.setFont(font);
character_choose.setCharacterSize(40);
character_choose.setPosition(Vector2f(145, 210));
character_choose.setFillColor(Color::Red);
character_choose.setString("Pick Your Character");
icy_icon.loadFromFile("icy character.png"); trump_icon.loadFromFile("Trump character.png");
dancer_icon.loadFromFile("icy character2.png");
icy_icon.setSmooth(true); trump_icon.setSmooth(true); dancer_icon.setSmooth(true);
characters[0].setTexture(trump_icon); characters[0].setPosition(230, 330);
characters[1].setTexture(icy_icon); characters[1].setPosition(350, 330);
characters[2].setTexture(dancer_icon); characters[2].setPosition(470, 330);
pointer.setFillColor(Color(0, 0, 0, 50));
pointer.setPosition(226, 329);
//Name screen
Texture namescreen_backg;
namescreen_backg.loadFromFile("namescreen.jpg");
namescreen.setTexture(namescreen_backg);
name_enter.setFont(font); name_enter.setCharacterSize(45);
name_enter.setString("Enter Your Name:"); name_enter.setFillColor(Color::Red);
name_enter.setPosition(Vector2f(130, 200));
//Entered Name
entered_name.setFont(font); entered_name.setCharacterSize(45);
entered_name.setFillColor(Color::Black);
entered_name.setPosition(Vector2f(175, 300));
/*Pause Screen */
Texture pausedd;
pausedd.loadFromFile("pause.png");
pause.setTexture(pausedd);
pause.setPosition(134, 118);
for (int i = 0; i < PAUSED_ITEMS; i++) {
pausetext[i].setFont(font);
pausetext[i].setCharacterSize(35);
}
pausetext[0].setFillColor(Color::Red);
pausetext[0].setString("Continue");
pausetext[0].setPosition(215, 338);
pausetext[1].setString("Exit");
pausetext[1].setPosition(523, 336);
pausetext[1].setFillColor(Color::Black);
/* instructions */
menu[1].setFont(font);
menu[1].setFillColor(Color::Black);
menu[1].setString("Instructions");
menu[1].setPosition({ 476.0f,285.0f });
menu[1].setCharacterSize(45);
for (int i = 0; i < 4; i++)
instruct[i].loadFromFile(instruct_names[i]);
for (int i = 0; i < 4; i++)
instructions[i].setTexture(instruct[i]);
/* Profile */
menu[2].setFont(font);
menu[2].setFillColor(Color::Black);
menu[2].setString("Profile");
menu[2].setPosition({ 476.0f,335.0f });
menu[2].setCharacterSize(45);
inprofile_menu[0].setString("CHARACTER");
inprofile_menu[1].setString("BACK");
for (int i = 0; i < 2; i++) {
inprofile_menu[i].setFont(font);
inprofile_menu[i].setCharacterSize(45);
inprofile_menu[i].setFillColor(Color::Black);
inprofile_menu[i].setPosition(Vector2f(470, 250 + (150 * i)));
}
inprofile_menu[0].setFillColor(Color::Red);
//cursor
cursor[profileindex].setPosition(430, 250);
character[0].setTexture(trump_icon); character[0].setPosition(550, 320);
character[1].setTexture(icy_icon); character[1].setPosition(550, 320);
character[2].setTexture(dancer_icon); character[2].setPosition(550, 320);
/* highscores */
menu[3].setFont(font);
menu[3].setFillColor(Color::Black);
menu[3].setString("High Scores");
menu[3].setPosition({ 476.0f,385.0f });
menu[3].setCharacterSize(45);
// Text topfive[6][2];
// ostringstream billboardconvertor;
topfive[0][0].setFont(font); topfive[0][1].setFont(font);
topfive[0][0].setFillColor(Color::Red); topfive[0][1].setFillColor(Color::Red);
topfive[0][0].setCharacterSize(40); topfive[0][1].setCharacterSize(40);
topfive[0][0].setString("Names:"); topfive[0][1].setString("Scores:");
topfive[0][0].setPosition(Vector2f(150, 170)); topfive[0][1].setPosition(Vector2f(505, 170));
for (int i = 1; i < 6; i++) {
for (int j = 0; j < 2; j++) {
topfive[i][j].setFont(font);
}
}
topfive_set();
/*Sound options */
menu[4].setFont(font);
menu[4].setFillColor(Color::Black);
menu[4].setString("Sound Options");
menu[4].setPosition({ 476.0f,435.0f });
menu[4].setCharacterSize(45);
menu[4].setScale(0.85, 1);
Texture soundicon;
soundicon.loadFromFile("volume.jpg");
for (int i = 0; i < 11; i++) {
sound_level[i].setTexture(soundicon);
music_level[i].setTexture(soundicon);
}
int q = 0;
for (int i = 0; i < 11; i++) {
int x = 475 + q;
music_level[i].setPosition(x, 300);
sound_level[i].setPosition(x, 400);
q += 25;
}
cursor[soundoptionsindex].setPosition(430, 250);
//Text Sound_menu[3];
inSound_menu[0].setString("MUSIC VOL");
inSound_menu[1].setString("Sound VOL");
inSound_menu[2].setString("BACK");
for (int i = 0; i < 3; i++) {
inSound_menu[i].setFont(font);
inSound_menu[i].setFillColor(Color::Black);
inSound_menu[i].setCharacterSize(45);
inSound_menu[i].setPosition(Vector2f(470, 250 + (100 * i)));
}
inSound_menu[0].setFillColor(Color::Red);
SoundBuffer musicbuffer, soundbuffer;
soundbuffer.loadFromFile("move.wav");
musicbuffer.loadFromFile("mainsong.wav");
music.setBuffer(musicbuffer); sound.setBuffer(soundbuffer);
music.setVolume(50); sound.setVolume(50);
music.play();
/* credits */
Texture credit;
credit.loadFromFile("credits.jpg");
Sprite credits(credit);
menu[5].setFont(font);
menu[5].setFillColor(Color::Black);
menu[5].setString("Credits");
menu[5].setPosition({ 476.0f,485.0f });
menu[5].setCharacterSize(45);
/* Exit */
menu[6].setFont(font);
menu[6].setFillColor(Color::Black);
menu[6].setString("Exit");
menu[6].setPosition({ 476.0f,535.0f });
menu[6].setCharacterSize(45);
/* Cursor */
//Texture curs;
//curs.loadFromFile("cursor.png");
//ICY Animation
Texture icytanimtion;
icytanimtion.loadFromFile("anim.png");
Sprite icytanim(icytanimtion);
icytanim.setPosition(95, 311);
Vector2u icytanimsize = icytanimtion.getSize();
icytanimsize.x /= 8;
IntRect icanim(icytanimsize.x * 0, 0, icytanimsize.x, icytanimsize.y);
icytanim.setTextureRect(icanim);
Clock icywatch;
//HurryUp
hurry.loadFromFile("hurry.png");
hurryT.setTexture(hurry);
hurryT.setPosition(Vector2f(200, 620));
//bloksno///////////////////////////////////////////
//scrolling backgrounds
if (!back1.loadFromFile("Backgroundnew1.jpg")) {
}
if (!back2.loadFromFile("Backgroundnew2.png")) {
}
backg11.setTexture(back1);
backg12.setTexture(back2);
backg21.setTexture(back1);
backg22.setTexture(back2);
backg21.setPosition(0, -599);
backg22.setPosition(0, -599);
//Main character