HeliCopter Code
HeliCopter Code
h>
#include<GL/glut.h>
#include<time.h>
//#include<dos.h>
#include<stdio.h>
//#include<conio.h>
//#include<windows.h>
char name[25];
char scs[20],slevel[20];
srand(time(0));
b1y=(rand()%45)+10;//b/w 10 to 44
glShadeModel (GL_SMOOTH);
glLoadIdentity ();
void drawcopter()
glColor3f(0.7,1.0,1.0);
glRectf(10,49.8,19.8,44.8);//body
glRectf(2,46,10,48);//tail
glRectf(2,46,4,51);//tail up
glRectf(14,49.8,15.8,52.2);//propeller stand
glRectf(7,53.6,22.8,52.2);//propeller*/
char *c;
glRasterPos3f(x, y,z);
glutBitmapCharacter(font, *c);
void display(void)
glClear(GL_COLOR_BUFFER_BIT);
//GameOver Checking
if(
(i==730||i==-700)
||
( ((int)b1x==10||(int)b1x==7||(int)b1x==4||(int)b1x==1)
&&(int)b1y<53+(int)hm&&(int)b1y+35>53+(int)hm)
||
( ((int)b1x==9||(int)b1x==3||(int)b1x==6) &&(int)b1y<45+(int)hm&&(int)b1y+35>45+(int)hm)
glColor3f(0.0,0.0,1.0);
glRectf(0.0,0.0,100.0,100.0);
glColor3f(1.0,0.0,0.0);
renderBitmapString(40,70,0,GLUT_BITMAP_HELVETICA_18,"GAME OVER!!!");
glColor3f(1.0,1.0,1.0);
renderBitmapString(25,58,0,GLUT_BITMAP_TIMES_ROMAN_24,"You");
renderBitmapString(45,58,0,GLUT_BITMAP_TIMES_ROMAN_24,"scored:");
renderBitmapString(70,58,0,GLUT_BITMAP_TIMES_ROMAN_24,scs);
glutSwapBuffers();
glFlush();
printf("\nGAME OVER\n\n");
//getch();
exit(0);
wflag=0;
glColor3f(0.0,0.5,0.7);
glRectf(0.0,0.0,100.0,10.0);//ceil
glRectf(0.0,100.0,100.0,90.0);//floor
glColor3f(1.0,1.0,1.0);
glColor3f(1.0,1.0,0.0);
renderBitmapString(45.5,70,0,GLUT_BITMAP_TIMES_ROMAN_24,"Helicopter");
glColor3f(1.0,0.0,0.0);
renderBitmapString(40,45,0,GLUT_BITMAP_TIMES_ROMAN_24,"Welcome");
renderBitmapString(53,45,0,GLUT_BITMAP_TIMES_ROMAN_24,name);
renderBitmapString(43,30,0,GLUT_BITMAP_TIMES_ROMAN_24,"Click To Start");
glColor3f(0.0,0.0,0.0);
drawcopter();
glutSwapBuffers();
glFlush();
else
if(sci%50==0&&lflag==1)
level++;//increase level by 1
else if(sci%50!=0&&lflag!=1)
lflag=1;
glPushMatrix();
glColor3f(0.0,0.5,0.7);
glRectf(0.0,0.0,100.0,10.0); //ceil
glRectf(0.0,100.0,100.0,90.0); //floor
glColor3f(0.0,0.0,0.0); //score
renderBitmapString(1,3,0,GLUT_BITMAP_TIMES_ROMAN_24,"Distance:");
//glColor3f(0.7,0.7,0.7);
sprintf(slevel,"%d",level); //level
renderBitmapString(80,3,0,GLUT_BITMAP_TIMES_ROMAN_24,"Level:");
renderBitmapString(93,3,0,GLUT_BITMAP_TIMES_ROMAN_24,slevel);
sci=(int)scf;
sprintf(scs,"%d",sci);
renderBitmapString(20,3,0,GLUT_BITMAP_TIMES_ROMAN_24,scs);
glTranslatef(0.0,hm,0.0);
drawcopter();
if(b1x<-10)
b1y=(rand()%25)+20;
else
b1x-=bspd;
glTranslatef(b1x,-hm,0.0);
glColor3f(1.0,0.0,0.0);
glRectf(b1x,b1y,b1x+5,b1y+35);//block 1
glPopMatrix();
glutSwapBuffers();
glFlush();
}
void moveHeliU(void)
hm+=0.05;
i++;
glutPostRedisplay();
void moveHeliD()
hm-=0.05;
i--;
glutPostRedisplay();
switch (button)
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(moveHeliU);
glutIdleFunc(moveHeliD);
break;
default: break;
if(key=='w') glutIdleFunc(moveHeliU);
if(key=='m') glutIdleFunc(moveHeliD);
scanf("%s",name);
glutInit(&argc, argv);
glutInitWindowPosition (200,200);
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keys);
glutMainLoop();
return 0;
helicopter
23
Dept of CSE,CEC