-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewobj.cpp
1220 lines (1132 loc) · 30.3 KB
/
newobj.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 <iostream>
#include <GL/freeglut.h>
#include "src/SOIL.h"
#include <string.h>
#include <stdio.h>
#include<stdlib.h>
#define UP 1
#define DOWN 0
#define MAX 10
#define SIZE_MIS_X 55 //determines the size of missiles
#define SIZE_MIS_y 30 //determines the size of missiles
#define MAX_MISSILES 3 //maximum number of missiles in game
#define SPEED 1
using namespace std;
int frames=60;
// The number of frames
int frameCount = 0;
// Number of frames per second
float fps = 0;
// currentTime - previousTime is the time elapsed
// between every call of the Idle function
int currentTime = 0, previousTime = 0;
//for choose scene
char scene[50]="res/war01_scene.jpg";
//my dup char holder
char imageloc[50];
//high scores
int max_dist, max_miss;
//flag to check if you were hit by a missile
int hit_missile=0;
//flad to determint the plane chosen by the user
int plane_choice=2;
//flag for setting
int setting=0;
void* currentfont;
float x_step=-171.0; //for loading bar movement (in pg=0)
float y_cre=0; //for credits text moveemnt
float y_pos=0; //y axis position of plane
float theta=0; //angle of the plane
bool state; //state of plane (either going up or down)
bool local_screen = true;
int update_mis;
GLfloat x = 0.0f; //background screen position
GLfloat fuel=98; //fuel left in plane
GLfloat dist, missiles; //dustance travelled and missiled douged
GLfloat missile_x=250,missile_y[MAX_MISSILES]= {0};//position of missiles
int no_of_missiles=3; //determines number of missiles in the game
int full = 1;
int i_bck,i_mis1,i_mis2,i_mis3,i_plane,i_inst21;
int i_cre22,i_sel31,i_sel32,i_0=0;
int j[20]={0};
int i_s,i;
GLfloat windowWidth;
GLfloat windowHeight;
GLuint tex_2d, tex_2d_mis[4], tex_2d_plane;
GLuint tex_2d_0, tex_2d_1, tex_2d_2, tex_2d_21, tex_2d_22, tex_2d_31, tex_2d_4, tex_2d_23;
//determines the current screen
int page=0;
//new
int m1=0,int_m1=0;//mission1_status?
float planex=0,planey=0,bomx=0,bomy=0;
int no_of_bombs=3,allow_next=1;
float hit_position_x= 140 ,hit_position_y=40;
float bom_rad_i=0,bom_rad_o=0,bom_rad_i1=0,bom_rad_o1=1;
int con_hit=0,count=1;
float color[] = {1,1,1};
//
int max_dest=0,max_missile=0;
void drawBitmap(float x,float y,void *f,const unsigned char* s) {
int i;
glRasterPos2f(x,y);
glutBitmapString(f,s);
printf("Bitmap drawing at %f,%f\n %s\r\n",x,y,s);
}
void drawStroke(const unsigned char* s,float tx,float ty,float tz,float sx,float sy,float sz) {
glPushMatrix();
glTranslatef(tx,ty,tz);
glScalef(sx,sy,sz);
glColor3f(1.0,1.0,1.0);
glutStrokeString(GLUT_STROKE_ROMAN,s);
glPopMatrix();
}
//class to draw the plane
class plane {
public:
float x[MAX], y[MAX], i;
float ymax, ymin;
int button;
plane()
{
x[1]=-30, x[2]=30, x[3]=30, x[4]=-30;
y[1]=15, y[2]=15, y[3]=-15, y[4]=-15;
}
void draw_plane()
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if(plane_choice==2)
{
if (i_plane == 0)
{
tex_2d_plane = SOIL_load_OGL_texture
(
"res/plane2.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MULTIPLY_ALPHA
);
i_plane = 1;
}
}
glBindTexture(GL_TEXTURE_2D, tex_2d_plane);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0);
glVertex2f(x[1], y[1]);
glTexCoord2f(1.0, 0.0);
glVertex2f(x[2], y[2]);
glTexCoord2f(1.0, 1.0);
glVertex2f(x[3], y[3]);
glTexCoord2f(0.0, 1.0);
glVertex2f(x[4], y[4]);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}
} plane1;
void plane11(){
//printf("Inside Plane\n");
glBegin(GL_TRIANGLES);
glShadeModel(GL_SMOOTH);
glColor3f(1.0,0.0,0.0);
glVertex2d(0.0,50.0);
glVertex2d(150.0,130.0);
glColor3f(0.7,0.7,0.7);
glVertex2d(150,50);
glColor3f(1.0,0.0,0.0);
glVertex2d(250,50);
glVertex2d(250,130);
glColor3f(0.7,0.7,0.7);
glVertex2d(400,50);
glColor3f(1.0,0.0,0.0);
glVertex2d(150,130);
glVertex2d(200,400);
glColor3f(0.7,0.7,0.7);
glVertex2d(250,130);
glColor3f(0.0,0.0,1.0);
glVertex2d(150,130);
glVertex2d(200,250);
glColor3f(0.7,0.7,0.7);
glVertex2d(250,130);
glEnd();
glBegin(GL_POLYGON);
glVertex2d(150,0);
glVertex2d(150,50);
glVertex2d(190,50);
glVertex2d(190,0);
glEnd();
glColor3f(0.7,0.7,0.7);
glBegin(GL_POLYGON);
glVertex2d(150,0);
glVertex2d(150,50);
glVertex2d(190,50);
glVertex2d(190,0);
glEnd();
glBegin(GL_POLYGON);
glVertex2d(210,0);
glVertex2d(210,50);
glVertex2d(250,50);
glVertex2d(250,0);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,0.7);
glVertex2d(150,130);
glVertex2d(250,130);
glColor3f(0.7,0.7,0.7);
glVertex2d(250,50);
glVertex2d(150,50);
glEnd();
}
void SpecialInput(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP:
//do something here
break;
case GLUT_KEY_DOWN:
//do something here
break;
case GLUT_KEY_LEFT:
printf("Detecting Left key");
if(page==4 && m1==1)
planex -= SPEED;
break;
break;
case GLUT_KEY_RIGHT:
if(page==4 && m1==1)
planex += SPEED;
//do something here
break;
}
glutPostRedisplay();
}
//Navigation for esc and fullscreen
void keyboard(unsigned char key, int x, int y) {
switch (key)
{
//27 is the ASCII value of the ESC key
case 27:
x=0.0;
if(page!=2)
{
i_bck=0,i_mis1=0,i_mis2=0,i_mis3=0,i_plane=0,i_sel31=0,i_sel32=0,i_0=0;
j[0]=j[1]=j[2]=j[3]=j[4]=j[5]=j[6]=j[7]=j[8]=j[9]=j[10]=j[11]=j[12]=j[13]=j[14]=j[15]=0;
planex=planey=bomx=bomy=0;
no_of_bombs=3;
allow_next=1;
m1=0;
con_hit=0;
page=2;
missiles=0;
dist=0;
srand(time(0));
int p = rand()%150;
p%2==0?hit_position_x=-p:hit_position_x=p;
// hit_position_x = rand()%150;
setting=0;
hit_missile=0;
theta=0;
y_pos=0;
state=false;
missile_x=250;
fuel=98;
y_cre=0;
x=0.0;
cout<<full<<endl;
cout<<x<<endl;
page=2;
}
else
//exit game
exit(0);
break;
case 32:
printf("Detecting Spacebar??\n allow: %d\n",allow_next);
if(no_of_bombs==0)
int_m1=0;
if(page==4 && m1==1 && allow_next==1){
no_of_bombs -= 1;
bomx = planex;
bomy = planey;
allow_next=0;
printf("Decreased no_of bombs: %d\n allow_next: %d\n",no_of_bombs,allow_next);
}
break;
case 'f': //full screen
if (full == 0)
{
glutFullScreen();
full = 1;
}
else
{
glutReshapeWindow(800, 450);
glutPositionWindow(320,150);
full = 0;
}
break;
}
glutPostRedisplay();
}
//Determines the action on mouse click event
void Mouse(int button, int m_state, int m_x, int m_y) {
if(page==1) {
if(m_x>720 && m_y>260 && m_state==GLUT_UP)
{
cout<<m_x<<" "<<m_y<<endl;
if(local_screen==1)
local_screen=0;
else
page=2;
}
}
else if(page==2) {
if(full==0) {
if(m_state==GLUT_UP)
cout<<m_x<<" "<<m_y<<endl;
if(m_y>92 && m_y<116 && m_state==GLUT_UP) {
cout<<"play"<<endl;
//page=31;
page=3;
}
if(m_y>158 && m_y<182 && m_state==GLUT_UP) {
cout<<"Instructions"<<endl;
page=21;
}
if(m_y>226 && m_y<256 && m_state==GLUT_UP) {
cout<<"High"<<endl;
page=23;
}
if(m_y>260 && m_state==GLUT_UP) {
cout<<"exit"<<endl;
exit(0);
}
}
else {
if(state==GLUT_UP)
cout<<m_x<<" "<<m_y<<endl;
if(m_y>154 && m_y<195 && m_state==GLUT_UP) {
cout<<"play"<<endl;
//page=31;
page=3;
}
if(m_y>213 && m_y<251 && m_state==GLUT_UP) {
cout<<"Settings"<<endl;
page=31;
setting=1;
}
if(m_y>269 && m_y<310 && m_state==GLUT_UP) {
cout<<"Instructions"<<endl;
page=21;
}
if(m_y>329 && m_y<366 && m_state==GLUT_UP) {
cout<<"Credit"<<endl;
page=22;
}
if(m_y>387 && m_y<425 && m_state==GLUT_UP) {
cout<<"High"<<endl;
page=23;
}
if(m_y>430 && m_state==GLUT_UP) {
cout<<"exit"<<endl;
exit(0);
}
}
}
else if(page==3) {
if(button==GLUT_LEFT_BUTTON && m_state==GLUT_DOWN) {
state=UP;
cout<<"Going Up!"<<endl;
}
else if(button==GLUT_LEFT_BUTTON && m_state==GLUT_UP) {
state=DOWN;
cout<<"Going Down"<<endl;
}
}
else if(page==4 && m1==3){
if(m_x>720 && m_y>260 && m_state==GLUT_UP){
page=4;
m1=1;
}
}
}
//draw text in finish screen (page=4)
void draw_fin_text() {
char string[6][40];
int i,lengthOfString;
strcpy(string[0],"Mission-1 Failed.");
sprintf(string[1],"You just travelled %d meters",(int)dist);
sprintf(string[2],"and dodged %d missiles",(int)missiles);
sprintf(string[3],"before you ran out of fuel!!");
sprintf(string[4],"before you were hit by one!!");
//update high scores;
if((int)dist>max_dist)
{
max_dist=dist;
cout<<max_dist<<" "<<dist<<endl;
}
if(missiles>max_miss)
{
max_miss=missiles;
//cout<<max_miss<<endl;
}
glLineWidth(4);
drawStroke(reinterpret_cast<const unsigned char *>(string[0]),-170,55,0,0.1,0.1,0.1);
glLineWidth(3);
drawStroke(reinterpret_cast<const unsigned char *>(string[1]),-155,35,0,0.1,0.1,0.1);
drawStroke(reinterpret_cast<const unsigned char *>(string[2]),-155,20,0,0.1,0.1,0.1);
drawStroke(reinterpret_cast<const unsigned char *>(hit_missile==0?string[3]:string[4]),-155,5,0,0.1,0.1,0.1);
drawStroke(reinterpret_cast<const unsigned char *>("Press Esc to Restart the mission"),-155,-20,0,0.1,0.1,0.1);
}
void draw_high_text() {
char string_high[10][20];
int lengthOfString,i;
strcpy(string_high[0],"High Scores: ");
sprintf(string_high[1],"Distance: %d",max_dist);
sprintf(string_high[2],"Missiles: %d",max_miss);
glLineWidth(3);
drawStroke(reinterpret_cast<const unsigned char *>(string_high[0]),0,30,0,0.2,0.2,0.2);
glLineWidth(2);
drawStroke(reinterpret_cast<const unsigned char *>(string_high[1]),70,0,0,0.1,0.1,0.1);
drawStroke(reinterpret_cast<const unsigned char *>(string_high[2]),70,-15,0,0.1,0.1,0.1);
}
//draw text in page 2 (menu screen)
void draw_menu_text() {
char string_menu[5][20];
int lengthOfString,i;
strcpy(string_menu[0],"Play!");
strcpy(string_menu[1],"Instructions");
strcpy(string_menu[2],"High Scores");
strcpy(string_menu[3],"Exit..");
glLineWidth(1);
drawStroke(reinterpret_cast<const unsigned char *>(string_menu[0]),-120,50,0,0.1,0.1,0.1);
drawStroke(reinterpret_cast<const unsigned char *>(string_menu[1]),-120,20,0,0.1,0.1,0.1);
drawStroke(reinterpret_cast<const unsigned char *>(string_menu[2]),-120,-10,0,0.1,0.1,0.1);
drawStroke(reinterpret_cast<const unsigned char *>(string_menu[3]),-120,-45,0,0.1,0.1,0.1);
}
//draw text in page 21 (instruction screen)
void draw_inst_text() {
char string[5][120];
int i,lengthOfString;
strcpy(string[0],"Instructions:\n");
strcpy(string[1],"This Game is split into 2 parts:\n\nMission-1\nHere, you have to travel across the border dodging the enemy planes. \nTry not to crash into them.\n\nMission-2\nAfter reaching the destination. You will have to shoot the\nenemy's safe house.\n\nAll the best champ!!!!!!");
drawStroke(reinterpret_cast<const unsigned char *>(string[0]),-80,50,0,0.3,0.3,0.3);
glLineWidth(1);
int y_pos_21=20;
drawStroke(reinterpret_cast<const unsigned char *>(string[1]),-80,y_pos_21-10,0,0.06,0.06,0.06);
}
//print the score in page 3 (prints the game scores during game play)
void draw_score() {
int length;
char score_text[15];
strcpy(score_text,"Distance: ");
glLineWidth(1);
drawStroke(reinterpret_cast<const unsigned char *>(score_text),85,82,0,0.08,0.08,0.08);
char dist_text_val[15];
sprintf(dist_text_val,"%d",(int)dist);
drawStroke(reinterpret_cast<const unsigned char *>(dist_text_val),130,82,0,0.08,0.08,0.08);
char missiles_text[15];
strcpy(missiles_text,"Missiles: ");
drawStroke(reinterpret_cast<const unsigned char *>(missiles_text),85,72,0,0.08,0.08,0.08);
char mis_text_val[15];
sprintf(mis_text_val,"%d",(int)missiles);
drawStroke(reinterpret_cast<const unsigned char *>(mis_text_val),130,72,0,0.08,0.08,0.08);
char fuel_text[15];
strcpy(fuel_text,"Fuel: %");
drawStroke(reinterpret_cast<const unsigned char *>(fuel_text),-149,82,0,0.08,0.08,0.08);
char fuel_text_val[15];
sprintf(fuel_text_val,"%d",(int)fuel);
drawStroke(reinterpret_cast<const unsigned char *>(fuel_text_val),-125,82,0,0.08,0.08,0.08);
}
void draw_intro(int i) {
glLineWidth(1);
drawStroke(reinterpret_cast<const unsigned char *>("SkyWars"),-20,75,0,0.08,0.08,0.08);
glPushMatrix();
glColor3f(1.0,1.0,1.0);
if(i==0){
drawBitmap(-90,40,GLUT_BITMAP_HELVETICA_18,
reinterpret_cast<const unsigned char *>("hello? This is 2D game inspired from the great balakot airstrike.\n\r\nThe 2019 Balakot airstrike was conducted by India in the early morning hours of\nFebruary 26 when Indian warplanes crossed the de facto border in the disputed \nregion of Kashmir, and dropped bombs in the vicinity of the town of Balakot in \nKhyber Pakhtunkhwa province in Pakistan."));
drawBitmap(-45,-20,GLUT_BITMAP_HELVETICA_18,
reinterpret_cast<const unsigned char *>("You will be briefed about the mission\nClick Next Button"));
drawBitmap(-90,-60,GLUT_BITMAP_HELVETICA_18,
reinterpret_cast<const unsigned char *>("NAME: S LOKESHWAR\nUSN: 1BI16CS187"));
}
else if(i==1) {
drawStroke(reinterpret_cast<const unsigned char *>("Mission-1"),-20,35,0,0.08,0.08,0.08);
drawBitmap(-60,20,GLUT_BITMAP_HELVETICA_18,
reinterpret_cast<const unsigned char *>("Cross the border to reach targetted site of balakot\nDo not be seen by enemy planes. Dodge them. \nYou passing the border shouldn't be known to them.\nAfter reaching the location wait for further instructions."));
}
glPopMatrix();
}
void draw_intro_boxes(int t=0) {
printf("Narration::\n");
glPushMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.0,0.0,0.0,0.9);
glBegin(GL_POLYGON);
glVertex2d(120,90);
printf("Drawing ??\n");
glVertex2d(120,70);
glVertex2d(-120,70);
glVertex2d(-120,90);
glEnd();
glBegin(GL_POLYGON);
glVertex2d(-100,-90);
printf("Drawing ??\n");
glVertex2d(-100,50);
glVertex2d(100,50);
glVertex2d(100,-90);
glEnd();
if(t==0){
glColor4f(0.1,0.1,0.9,0.9);
glBegin(GL_POLYGON);
glVertex2d(120,-28);
glVertex2d(120,-40);
glVertex2d(145,-40);
glVertex2d(145,-28);
glEnd();
glColor3f(1.0,1.0,1.0);
glClearColor(1.0,1.0,1.0,1.0);
drawBitmap(125.0,-35.0,GLUT_BITMAP_9_BY_15,reinterpret_cast<const unsigned char *>("NEXT=>>"));
}
glDisable(GL_BLEND);
glPopMatrix();
glFlush();
}
void rocket(int x_cor, int y_cor,int r_no) {
const unsigned char* t = reinterpret_cast<const unsigned char *>("res/rocket2.png");
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if (i_mis1 == 0){
tex_2d_mis[1] = SOIL_load_OGL_texture
(
"res/p03.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MULTIPLY_ALPHA
);
i_mis1 = 1;
}
glBindTexture(GL_TEXTURE_2D, tex_2d_mis[1]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 1.0);
glVertex2f(x_cor, y_cor);
glTexCoord2f(1.0, 1.0);
glVertex2f(x_cor+SIZE_MIS_X, y_cor);
glTexCoord2f(1.0, 0.0);
glVertex2f(x_cor+SIZE_MIS_X, y_cor+SIZE_MIS_y-10);
glTexCoord2f(0.0, 0.0);
glVertex2f(x_cor, y_cor+SIZE_MIS_y-10);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}
void draw_rockets() {
if(missile_x>200)
no_of_missiles=rand()%MAX_MISSILES+1;
if(missile_x>=195 && missile_x<=200)
for(int k=1; k<=no_of_missiles; k++)
missile_y[k]=-101+rand()%165;
switch(no_of_missiles) {
case 1:
rocket(missile_x,missile_y[1],1);
break;
case 2:
rocket(missile_x,missile_y[1],1);
rocket(missile_x,missile_y[2],2);
break;
case 3:
rocket(missile_x,missile_y[1],1);
rocket(missile_x,missile_y[2],2);
rocket(missile_x,missile_y[3],3);
break;
case 4:
rocket(missile_x,missile_y[1],1);
rocket(missile_x,missile_y[2],3);
rocket(missile_x,missile_y[3],2);
rocket(missile_x,missile_y[4],3);
break;
default:
case 5:
rocket(missile_x,missile_y[1],1);
rocket(missile_x,missile_y[2],3);
rocket(missile_x,missile_y[3],2);
rocket(missile_x,missile_y[4],3);
rocket(missile_x,missile_y[5],1);
break;
}
}
void draw_chosen_plane() {
glColor3f(1,1,1);
glBegin(GL_LINE_LOOP);
glVertex2f(-150,-40);
glVertex2f(-30,-40);
glVertex2f(-30,40);
glVertex2f(-150,40);
glEnd();
glPushMatrix();
glTranslatef(-90,0,0);
glScalef(1.6,1.6,0);
plane1.draw_plane();
glPopMatrix();
}
void drawfps() {
int length;
char d_fps[15];
sprintf(d_fps,"FPS: %.1f",fps);
glLineWidth(1);
drawStroke(reinterpret_cast<const unsigned char *>(d_fps),-160,-85,0,0.04,0.04,0.04);
}
void page1_dup(const char t[50],float x,float y, int index) {
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
if(j[index]==0) {
tex_2d_1 = SOIL_load_OGL_texture
(
t,
SOIL_LOAD_RGBA,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_NTSC_SAFE_RGB
);
j[index]=1;
}
glBindTexture(GL_TEXTURE_2D, tex_2d_1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 1.0);
glVertex2f(-x, -y);
glTexCoord2f(1.0, 1.0);
glVertex2f(x, -y);
glTexCoord2f(1.0, 0.0);
glVertex2f(x, y);
glTexCoord2f(0.0, 0.0);
glVertex2f(-x, y);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void page_dumy(const char t[50],float x,float y, int index) {
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if (j[index] == 0)
{
tex_2d_0 = SOIL_load_OGL_texture
(
t,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MULTIPLY_ALPHA
);
j[index] = 1;
}
glBindTexture(GL_TEXTURE_2D, tex_2d_0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0);
glVertex2f(-x, y);
glTexCoord2f(1.0, 0.0);
glVertex2f(x, y);
glTexCoord2f(1.0, 1.0);
glVertex2f(x, -y);
glTexCoord2f(0.0, 1.0);
glVertex2f(-x, -y);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}
void draw_quads(float dx, float dy,float tx=0,float ty=0,float tz=0,float sx=1,float sy=1,float sz=1){
glPushMatrix();
glTranslatef(tx,ty,tz);
glScalef(sx,sy,sz);
glBegin(GL_QUADS);
glVertex2f(-dx,dy);
glVertex2f(dx,dy);
glVertex2f(dx,-dy);
glVertex2f(-dx,-dy);
glEnd();
glPopMatrix();
}
void RenderScene() {
if(page==0) { //do not shorten this.
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0,0.0,0.0,1.0);
glColor3fv(color);
GLUquadricObj* quadratic1;
quadratic1 = gluNewQuadric();
gluDisk(quadratic1,bom_rad_i1,bom_rad_o1,32,10);
drawStroke(reinterpret_cast<const unsigned char *>("Loading...."),-15,-3,0,0.07,0.07,1);
glutSwapBuffers();
glFlush();
//local_screen=true;
}
else if(page==1) {
if(local_screen==1){
page1_dup("res/intro.jpg",178.0,100.0,0);
glColor3f(1.0,1.0,1.0);
draw_intro_boxes();
draw_intro(0);
}
else if(local_screen==0){
page1_dup("res/intro.jpg",178.0,100.0,1);
glColor3f(1.0,1.0,1.0);
draw_intro_boxes();
draw_intro(1);
glPushMatrix();
glTranslatef(0,-40,0);
page_dumy("res/map01.png",30,20,2);
glPopMatrix();
}
glutSwapBuffers();
glFlush();
}
//game menu
else if(page==2) {
page1_dup("res/rtr271ii.jpg",178.0,100.0,3);
draw_menu_text();
drawfps();
glutSwapBuffers();
}
//instruction
else if(page==21) {
page1_dup("res/pp.jpg",178.0,100.0,5);
draw_inst_text();
// glPushMatrix();
// glTranslatef(-130,45,0);
// page_dumy("res/p03.png",35,20,16);
// glPopMatrix();
// glPushMatrix();
// glTranslatef(0,-80,0);
// page_dumy("res/plane2.png",35,20,15);
// glPopMatrix();
glutSwapBuffers();
}
//highscores
else if(page==23) {
page1_dup("res/scene2.png",178.0,100.0,4);
draw_high_text();
glutSwapBuffers();
}
//game play
else if(page==3) { //do not shorten this.
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if (i_bck == 0)
{
tex_2d = SOIL_load_OGL_texture
(
scene,
SOIL_LOAD_RGBA,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_NTSC_SAFE_RGB
);
i_bck = 1;
}
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 1.0);
glVertex2f(-190.0f+x, -100.0f);
glTexCoord2f(1.0, 1.0);
glVertex2f(890.0f+x, -100.0f);
glTexCoord2f(1.0, 0.0);
glVertex2f(890.0f+x, 100.0f);
glTexCoord2f(0.0, 0.0);
glVertex2f(-190.0f+x, 100.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
//fuel indicator outline
glColor3f(0,0,0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex2f(-50-100,80);
glVertex2f(50-100,80);
glVertex2f(50-100,70);
glVertex2f(-50-100,70);
glEnd();
//fuel indicator
glColor3f(1,1,1);
glBegin(GL_POLYGON);
glVertex2f(-49-100,79);
glVertex2f(-49+fuel-100,79);
glVertex2f(-49+fuel-100,71);
glVertex2f(-49-100,71);
glEnd();
//seprator--to seprate score and game screen
glLineWidth(1);
glColor3f(1,1,1);
glBegin(GL_LINES);
glVertex2f(-200,64);
glVertex2f(200,64);
glEnd();
draw_score();
draw_rockets();
glPushMatrix();
glTranslatef(-130,y_pos,0);
glRotatef(theta,0,0,1);
plane1.draw_plane();
glPopMatrix();
drawfps();
glutSwapBuffers();
}
//finish
else if(page==4) { //add next game here.
if(m1==0){
page1_dup("res/finish.png",178.0,100.0,7);
draw_fin_text();
// draw_intro_boxes();
glutSwapBuffers();
}
else if(m1==1){
char string[5][50];
page1_dup("res/pp.jpg",178.0,100.0,8);
glPushMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0,0,0,0.8);
glBegin(GL_POLYGON);
glVertex2f(-170,95);
glVertex2f(-170,80);
glVertex2f(170,80);
glVertex2f(170,95);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(-180,-100);
glVertex2f(-180,-65);
glVertex2f(180,-65);
glVertex2f(180,-100);
glEnd();
glDisable(GL_BLEND);
glPopMatrix();
glPushMatrix();
glTranslatef(planex-9,-95,0);
glScalef(0.05,0.061,1);
// page_dumy("res/plane2.png",-40,15,9); //planex,-45,0
plane11();
glPopMatrix();
glColor4f(0.0,0.0,0.0,0.3);
glColor3f(1.0,1.0,1.0);
sprintf(string[1],"Bullets remaining: %d",(int)no_of_bombs);
drawStroke(reinterpret_cast<const unsigned char *>(string[1]),-170,85,0,0.05,0.05,1);
drawStroke(reinterpret_cast<const unsigned char *>("Use Left and Right arrows\nSpacebar to shoot"),115,87,0,0.03,0.03,1);
//bomb
GLUquadricObj* quadratic;
quadratic = gluNewQuadric();
glColor4f(189/255.0,45/255.0,89/255.0,0.6);
if(allow_next==0 and no_of_bombs<3){
printf("Drawing bomb?\n");
glPushMatrix();
glTranslatef(bomx,bomy,0);
gluDisk(quadratic,bom_rad_i,bom_rad_o,32,40);
gluDisk(quadratic,bom_rad_i+3,bom_rad_o+4,20,10);
// gluDisk(quadratic,1,5,10,10);
glPopMatrix();
}
//object to blast
if(con_hit==0){
glPushMatrix();
glTranslatef(hit_position_x,hit_position_y,0);
page_dumy("res/tex_h1.jpg",-15,10,9);
glPopMatrix();
glPushMatrix();
glTranslatef(hit_position_x,hit_position_y+10,0);
page_dumy("res/tex_h1.jpg",-20,1,14);
glPopMatrix();
glColor3f(0.0,0.0,0.0);
draw_quads(2.5,5,hit_position_x,hit_position_y-4);
glPushMatrix();
glTranslatef(hit_position_x,hit_position_y+11,0);
glBegin(GL_TRIANGLES);
glVertex2f(-15,0);
glVertex2f(0,5);
glVertex2f(15,0);
glEnd();
glPopMatrix();
draw_quads(5,1,hit_position_x,hit_position_y-11);
draw_quads(7,1,hit_position_x,hit_position_y-12);
}
glutSwapBuffers();
}
else if(m1==2){
char string[2][50];
sprintf(string[0],"Bullets used: %d/%d",3-no_of_bombs,3);
page1_dup("res/finish.png",178.0,100.0,10);
draw_intro_boxes(1);
drawStroke(reinterpret_cast<const unsigned char *>("Mission-2 Completed"),-50,75,0,0.08,0.08,1);
drawStroke(reinterpret_cast<const unsigned char *>("Congrats!\nMission-2 Completed.\nGame over"),-90,30,0,0.05,0.05,1);
drawStroke(reinterpret_cast<const unsigned char *>(string[0]),-90,0,0,0.05,0.05,1);
drawStroke(reinterpret_cast<const unsigned char *>("Press esc to return to the main menu."),-90,-80,0,0.06,0.06,1);
glPushMatrix();
glTranslatef(-25,-35,0);
page_dumy("res/hit01.jpeg",50,25,11);
glPopMatrix();
glutSwapBuffers();
}
else if(m1==3){
page1_dup("res/finish.png",178.0,100.0,12);
// draw_fin_text();
draw_intro_boxes();
drawStroke(reinterpret_cast<const unsigned char *>("Mission-1 completed"),-50,75,0,0.08,0.08,1);
drawStroke(reinterpret_cast<const unsigned char *>("Congrats!\nMission-1 Completed.\nFocus Captain!!!\n"),-90,30,0,0.05,0.05,1);
drawStroke(reinterpret_cast<const unsigned char *>("Your next mission is shoot the terrorist house.\nYou have 3-Torepodes."),-90,0,0,0.05,0.05,1);
drawStroke(reinterpret_cast<const unsigned char *>("Click next when ready...."),-90,-20,0,0.05,0.05,1);
glutSwapBuffers();
}
else if(m1==4){
char string[2][50];
sprintf(string[0],"Bullets used: %d/%d",3-no_of_bombs,3);
page1_dup("res/finish.png",178.0,100.0,10);
draw_intro_boxes(1);
drawStroke(reinterpret_cast<const unsigned char *>("Mission-2 Failed"),-50,75,0,0.08,0.08,1);
drawStroke(reinterpret_cast<const unsigned char *>("Ran out of bullets\nGame over\nRestart the mission champ"),-90,30,0,0.05,0.05,1);
drawStroke(reinterpret_cast<const unsigned char *>(string[0]),-90,0,0,0.05,0.05,1);
drawStroke(reinterpret_cast<const unsigned char *>("Press esc to return to the main menu."),-90,-80,0,0.06,0.06,1);
glPushMatrix();
glTranslatef(-25,-35,0);
page_dumy("res/map01.png",50,25,11);
glPopMatrix();
glutSwapBuffers();
}
}
}
void calculateFPS() {
// Increase frame count
frameCount++;
// Get the number of milliseconds since glutInit called
// (or first call to glutGet(GLUT ELAPSED TIME)).
currentTime = glutGet(GLUT_ELAPSED_TIME);
// Calculate time passed
int timeInterval = currentTime - previousTime;
if(timeInterval > 1000)
{
// calculate the number of frames per second
fps = frameCount / (timeInterval / 1000.0f);
// Set time
previousTime = currentTime;
// Reset frame count
frameCount = 0;
}
}
void TimerFunction(int v) {
calculateFPS();
if(page==0) {
bom_rad_i1 += 0.1*SPEED;
bom_rad_o1 += 0.05*SPEED;
if(bom_rad_i1>=bom_rad_o1){
bom_rad_i1 = 0;
bom_rad_o1 = count++;
color[1] -= 0.3;