Professional Documents
Culture Documents
h>
#include<stdio.h>
#include<string.h>
void displayloop(void);
void pscore(void);
int w,count=0,gflag=0,lev1=0,lev2=0,lev3=0,lev4=0,lev5=0,lev6=0;
char player[36];
char c1[20]={"PLAYER NAME: "};
float
x=0,a=5.0,b=5.5,c=7.0,d=7.5,e=8.0,f=12.0,g=12.5,h=14.0,i=14.5,j=1
5.0,flag=0;
float p=0.0,q=0.5,r=2.0,s=2.5,t=3.0;
char name[20]={"CRASH"};
char level1[10]={"LEVEL 1"};
char level2[10]={"LEVEL 2"};
char level3[10]={"LEVEL 3"};
char level4[10]={"LEVEL 4"};
char level5[10]={"LEVEL 5"};
char level6[10]={"LEVEL 6"};
char sc[20]={"Ur score is: "};
char go[20]={"GAME OVER"};
char es[20]={"Press ESC to exit"};
int sel,fl,crash=0,rem=0;
int score=0,sco;
float
aa=1.0,bb=4.0,cc=6.0,dd=9.0,ee=11.0,ff=14.0,gg=16,hh=19.0,pos[10]
,ss=11.75;
char inst1[50]={"Follow the instructions below"};
char inst2[50]={"1: Maximize the window"};
char inst3[80]={"2: Press 'DOWN ARROW' or 'S' to start and 'p' to
pause the game"};
char inst4[15]={"3: Controls:"};
char inst5[60]={"To move left -> Press LEFT ARROW KEY or LEFT
CLICK"};
char inst6[60]={"To move right -> Press RIGHT ARROW KEY or
RIGHT CLICK"};
char inst7[20]={"Submitted by "};
char inst8[50]={"Niranjan R Raikar & Manu S"};
char inst9[100]={"Sri Siddhartha Instititue Of Technology"};
void display(void)
{
if (gflag==0)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glRasterPos2f(1.0,13.0);
for(w=0;w<sizeof(inst1);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst1[w]);
glColor3f(0.5,0.5,0.5);
glRasterPos2f(2.0,11.0);
for(w=0;w<sizeof(inst2);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst2[w]);
glRasterPos2f(2.0,10.0);
for(w=0;w<sizeof(inst3);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst3[w]);
glRasterPos2f(2.0,9.0);
for(w=0;w<sizeof(inst4);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst4[w]);
glRasterPos2f(4.0,8.0);
for(w=0;w<sizeof(inst5);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst5[w]);
glRasterPos2f(4.0,7.0);
for(w=0;w<sizeof(inst6);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst6[w]);
glColor3f(1,0,0.5);
glRasterPos2f(5.0,14.0);
for(w=0;w<sizeof(inst9);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst9[w]);
glColor3f(0,0,1);
glRasterPos2f(10.0,3.0);
for(w=0;w<sizeof(inst7);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst7[w]);
glRasterPos2f(10.0,2.0);
for(w=0;w<sizeof(inst8);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,inst8[w]);
}
glClearColor(0.1,0.1,0.13,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glColor3f(1.0,1.0,0.0);
glVertex2f(0.1,0.0);
glVertex2f(0.1,15.0);
//lines
glVertex2f(0.5,0.0);
glVertex2f(0.5,15.0);
glVertex2f(8.6,0.0);
glVertex2f(8.6,15.0);
glVertex2f(9.0,0.0);
glVertex2f(9.0,15.0);
glColor3f(1.0,1.0,0.0);
for(int y=0;y<15;y++)
{
glVertex2f(0.1,y);
glVertex2f(0.5,y+1);
}
for(y=0;y<15;y++)
{
glVertex2f(8.6,y);
glVertex2f(9.0,y+1);
}
glEnd();
glColor3f(1.0,1.0,1.0);
rectangle
glRectf(4.2,aa,4.8,aa+3);
glRectf(4.2,cc,4.8,cc+3);
glRectf(4.2,ee,4.8,ee+3);
glRectf(4.2,gg,4.8,gg+3);
glColor3f(0.73,0.23,0.12);
started
glBegin(GL_POLYGON);
glVertex2f(1.7+x,0.0);
glVertex2f(3.2+x,0.0);
glVertex2f(3.45+x,0.1);
glVertex2f(3.48+x,0.18);
glVertex2f(3.5+x,0.2);
glVertex2f(3.5+x,2.8);
glVertex2f(3.4+x,2.95);
//lines
//shading
//shading
//middle
//making of car
glVertex2f(3.3+x,3.0);
glVertex2f(1.7+x,3.0);
glVertex2f(1.6+x,2.95);
glVertex2f(1.5+x,2.8);
glVertex2f(1.5+x,0.2);
glVertex2f(1.53+x,0.08);
glEnd();
glColor3f(0.73,0.23,0.12);
glBegin(GL_POLYGON);
glVertex2f(1.9+x,0.5);
glVertex2f(3.1+x,0.5);
glVertex2f(3.1+x,1.8);
glVertex2f(1.9+x,1.8);
glEnd();
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(2.0+x,1.9);
glVertex2f(3.0+x,1.9);
glVertex2f(3.2+x,2.3);
glVertex2f(1.8+x,2.3);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1.9+x,0.4);
glVertex2f(1.6+x,0.2);
glVertex2f(3.4+x,0.2);
glVertex2f(3.1+x,0.4);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(1.8+x,1.8);
glVertex2f(1.7+x,2.0);
glVertex2f(1.7+x,0.5);
glVertex2f(1.8+x,0.6);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(3.2+x,0.6);
glVertex2f(3.3+x,0.5);
glVertex2f(3.3+x,2.0);
glVertex2f(3.2+x,1.8);
glEnd();
glColor3f(0.0,0.0,0.0);
glRectf(1.4+x,0.2,1.5+x,1.0);
glRectf(1.4+x,1.7,1.5+x,2.5);
glRectf(3.5+x,0.2,3.6+x,1.0);
glRectf(3.5+x,1.7,3.6+x,2.5);
if(aa<-3)
of road seperation
aa=17.0;
if(cc<-3 )
cc=17.0;
if(ee<-3 )
ee=17.0;
if (gg<-3)
gg=17.0;
//for recreation
if (e<.1)
//Recreating the obstacle 1
{
e=15;
a=12;
b=12.5;
c=14;
d=14.5;
if (sel==1)
score+=100;
if (sel==2)
score+=200;
if (sel==3)
score+=300;
if (sel==4)
score+=400;
if (sel==5)
score+=500;
if (sel==6)
score+=600;
}
if (j<.1)
//Recreating the obstacle 2
{
f=12;
g=12.5;
h=14;
i=14.5;
j=15;
if (sel==1)
score+=100;
if (sel==2)
score+=200;
if (sel==3)
score+=300;
if (sel==4)
score+=400;
if (sel==5)
score+=500;
if (sel==6)
score+=600;
}
glColor3f(0.4,0.4,0.9);
obstacles
glRectf(5.15,a,7.85,b);
glRectf(5.65,c,7.35,d);
glRectf(6.25,a,6.75,e);
//static
glColor3f(0.4,0.4,0.9);
glRectf(1.15,f,3.85,g);
obstacles
glRectf(1.65,h,3.35,i);
glRectf(2.25,f,2.75,j);
//static
glColor3f(1.0,1.0,1.0);
glRasterPos2f(10.0,14.0);
for(w=0;w<sizeof(c1);w++)
//Printing as
"PLAYER NAME"
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,c1[w]);
glColor3f(0.0,1.0,0.0);
glRasterPos2f(10.0,13.5);
for(w=0;w<sizeof(player);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,player[w]);
if (sel<=1)
{
glColor3f(0.7,0.3,0.9);
//to
print LEVEL
glRasterPos2f(10.0,11.0);
for(w=0;w<sizeof(level1);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,level1[w]);
}
if(lev6<=1000)
{
if (gflag==1)
displayloop();
}
if (sel<=2 && (lev1>=1000 || fl==2))
{
sel=2;
glColor3f(0.7,0.3,0.9);
glRasterPos2f(10.0,10.5);
for(w=0;w<sizeof(level2);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,level2[w]);
}
if (sel<=3 && (lev2>=1000 || fl==3))
{
sel=3;
glColor3f(0.7,0.3,0.9);
glRasterPos2f(10.0,10.0);
for(w=0;w<sizeof(level3);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,level3[w]);
}
if (sel<=4 && (lev3>=1000 || fl==4) )
{
sel=4;
glColor3f(0.7,0.3,0.9);
glRasterPos2f(10.0,9.5);
for(w=0;w<sizeof(level4);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,level4[w]);
}
if (sel<=5 && (lev4>=1000 || fl==5))
{
sel=5;
glColor3f(0.7,0.3,0.9);
glRasterPos2f(10.0,9.0);
for(w=0;w<sizeof(level5);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,level5[w]);
}
if (sel<=6 && (lev5>=1000 || fl==6))
{
sel=6;
glColor3f(0.7,0.3,0.9);
glRasterPos2f(10.0,9.0);
for(w=0;w<sizeof(level6);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,level6[w]);
}
glColor3f(0.0,1.0,1.0);
if(flag==0 && f<2.8 && j>0.0)
{
glRasterPos2f(11.0,8.0);
for(w=0;w<sizeof(name);w++)
// BEGINING OF CRASH CONDITIONS
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,name[w]);
glFlush();
crash=1;
for (int n=1;n<=50000;n++) {}
}
if(flag==1 && a<2.8 && e>0.0)
{
glRasterPos2f(11.0,8.0);
for(w=0;w<sizeof(name);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,name[w]);
glFlush();
crash=1;
for (int n=1;n<=500000;n++) {}
}
if(flag==0 && f<2.8 && f>0.0)
{
glRasterPos2f(11.0,8.0);
for(w=0;w<sizeof(name);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,name[w]);
glFlush();
crash=1;
for (int n=1;n<=50000;n++) {}
}
if(flag==1 && a<2.8 && a>0.0)
{
glRasterPos2f(11.0,8.0);
for(w=0;w<sizeof(name);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,name[w]);
crash=1;
for (int n=1;n<=50000;n++) {}
}
//ENDING OF CRASH
CONDITIONS
}
if (crash==1)
display of score,Game over & ESC to exit.
{
for (int rr=0;rr<20;rr++)
{
pos[rr]=ss-0.15;
ss=pos[rr];
}
sco=score;
glColor3f(0.0,1.0,0.0);
glRasterPos2f(11.0,7.0);
for(w=0;w<sizeof(sc);w++)
//for
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,sc[w]);
for (int nn=1;nn<=50000;nn++)
{}
//for delay
rr=0;
while (score!=0)
//display of
score
rem=score%10;
glColor3f(1.0,1.0,0.0);
glRasterPos2f(pos[rr++],6.0);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,48+rem);
score=score/10;
glFlush();
}
score=sco;
ss=11.75;
glColor3f(1.0,0.0,0.0);
glRasterPos2f(11.0,5.0);
for(w=0;w<sizeof(go);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,go[w]);
glFlush();
glColor3f(0.0,0.0,1.0);
glRasterPos2f(11.0,4.0);
for(w=0;w<sizeof(es);w++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,es[w]);
glFlush();
for (int n=1;n<=50000;n++) {}
pscore();
}
glFlush();
flag!=1)
glutPostRedisplay();
}
void keyb(unsigned char key,int mx,int my)
{
if (key==27)
exit(0);
if(key=='p' || key=='P')
{
gflag=0;
}
if (key=='s' || key=='S')
{
gflag=1;
displayloop();
}
}
glutPostRedisplay();
glutPostRedisplay();
void displayloop()
{
if (sel==1 && lev1<1000)
//for increasing the speed of the obstacles
a=a-0.02;
b=b-0.02;
c=c-0.02;
d=d-0.02;
e=e-0.02;
f=f-0.02;
g=g-0.02;
h=h-0.02;
i=i-0.02;
j=j-0.02;
lev1++;
aa-=0.02;
bb-=0.02;
cc-=0.02;
dd-=0.02;
ee-=0.02;
ff-=0.02;
gg-=0.02;
}
if
{
}
if
{
if
{
}
if
{
}
if
{
// level 4 speed
i=i-0.16;
j=j-0.16;
}
lev6++;
}
}
glutPostRedisplay();
void myinit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,15.0,0.0,15.0);
glMatrixMode(GL_MODELVIEW);
}
void pscore()
{
printf("Ur Score is: %d\n",score);
crash=9;
return;
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitWindowSize(1280,1024);
glutCreateWindow("Race");
glClearColor(1,1,1,1);
myinit();
printf("Enter Your Name\n");
gets(player);
printf("Select ur choice of level\n");
printf("\t 1: Level 1\n\t 2: Level 2\n\t 3: Level 3\n\t 4:
Level 4\n\t 5: Level 5\n\t 6: Level 6\n");
scanf("%d",&sel);
if (sel>=7)
{
printf("WRONG CHOICE\n");
exit(0);
}
fl=sel;
glutDisplayFunc(display);
glutSpecialFunc(keyboard);
glutKeyboardFunc(keyb);
glutMouseFunc(mouse);
glutMainLoop();
return 0;