Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iGraphics.h>
- #include<stdio.h>
- #include<math.h>
- #include<stdlib.h>
- #include<string.h>
- void life();
- void page1();
- void page2();
- void page3();
- void page4();
- void policemove();
- void enemy1emove();
- void enemy2emove();
- int policex=150;
- int policey=375;
- int enemy1x=250;
- int enemy1y=375;
- int enemy2x=195;
- int enemy2y=200;
- int coursor=0;
- int ij=0;
- int car=0;
- int car1=0;
- int carx=0;
- int cary=0;
- int page=1;
- int score=0;
- int lives=30;
- int poli=0;
- int eni1=0;
- int eni2=0;
- char a;
- char b;
- char e;
- char f;
- char c;
- char scorestr[1000];
- char namegame[10];
- char scorefile[10];
- char scoregame[10];
- char name[10];
- char scorefinal[10];
- char scr[10];
- char nme[10];
- int scorefileint;
- int i=0;
- int xc=0;
- int yc=0;
- int j=0;
- int k=0;
- int high=0;
- int scoreshow=0;
- double x[]={0,0,150};
- double y[]={60,430,430};
- double g[]={350,500,500};
- double h[]={430,430,60};
- FILE *f1;
- FILE *f2;
- FILE *f3;
- FILE *f4;
- FILE *f5;
- FILE *f6;
- void iDraw()
- {
- iClear();
- if(page==1)
- {
- page1();
- }
- if(page==2)
- {
- page2();
- }
- if(page==3)
- {
- page3();
- }
- if(page==4)
- {
- page4();
- }
- }
- void iMouseMove(int mx, int my)
- {
- }
- void iMouse(int button, int state, int mx, int my)
- {
- if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
- {
- if(mx<=464 && mx>=300 && my<=380 && my>=340)
- {
- page=2;
- }
- if(mx<=464 && mx>=300 && my<=310 && my>=270)
- {
- page=4;
- }
- if(mx<=464 && mx>=300 && my<=240 && my>=200)
- {
- exit(0);
- }
- if(mx>=190 && mx<=290 && my>=340 && my<=380 && page==3)
- {
- coursor=1;
- }
- if(mx<=490 && mx>=290 && my<=50 && my>=0)
- {
- page=1;
- lives=30;
- score=0;
- scoreshow=0;
- }
- if(mx<=494 && mx>=330 && my<=40 && my>=0)
- {
- page=1;
- }
- }
- }
- void iKeyboard(unsigned char key)
- {
- if(coursor==1 && page==3)
- {
- if(key!=8)
- {
- if(key!='\r')
- {
- namegame[ij]=key;
- ij++;
- }
- if(key=='\r')
- {
- scoreshow=1;
- namegame[ij]='\0';
- coursor=0;
- }
- }
- else if(key==8 && strlen(namegame)!=0)
- {
- ij--;
- namegame[ij]='\0';
- }
- }
- else if(key=='d')
- {
- if(car==0)
- {
- if(carx<420)
- {
- carx+=25;
- }
- if(carx==420)
- {
- car=1;
- }
- }
- }
- else if(key=='a')
- {
- if(carx>0)
- {
- carx-=25;
- }
- if(carx==0)
- {
- car=0;
- }
- }
- else if(key=='w')
- {
- if(car1==0)
- {
- if(cary<375)
- {
- cary+=25;
- }
- if(cary==375)
- {
- car1=1;
- }
- }
- }
- else if(key=='s')
- {
- if(cary>0)
- {
- cary-=25;
- }
- if(cary==0)
- {
- car1=0;
- }
- }
- else if(key == 'q')
- {
- exit(0);
- }
- }
- void page1()
- {
- iSetcolor(255,255,255);
- iFilledRectangle(0,0,500,650);
- iShowBMP(300,340,"new.bmp");
- iShowBMP(300,270,"highscore.bmp");
- iShowBMP(300,200,"quit.bmp");
- iShowBMP(50,0,"cover.bmp");
- iShowBMP(0,160,"crash.bmp");
- }
- void page2()
- {
- if(page==2)
- {
- iClear();
- iSetcolor(0,0,0);
- iShowBMP(carx,cary,"mycar.bmp");
- iShowBMP(policex,policey,"police.bmp");
- iShowBMP(enemy1x,enemy1y,"enemy1.bmp");
- iShowBMP(enemy2x,enemy2y,"enemy2.bmp");
- iShowBMP(0,430,"background.bmp");
- iSetcolor(0,255,0);
- iFilledPolygon(x,y,3);
- iFilledPolygon(g,h,3);
- if(poli==1)
- {
- iShowBMP(carx,cary,"KaBoom.bmp");
- }
- if(eni1==1)
- {
- iShowBMP(carx,cary,"KaBoom.bmp");
- }
- if(eni2==1)
- {
- iShowBMP(carx,cary,"KaBoom.bmp");
- }
- if(lives<=30 && lives>20)
- {
- iShowBMP(0,620,"life.bmp");
- iShowBMP(40,620,"life.bmp");
- iShowBMP(80,620,"life.bmp");
- }
- if(lives<=20 && lives>10)
- {
- iShowBMP(0,620,"life.bmp");
- iShowBMP(50,620,"life.bmp");
- }
- if(lives>0 && lives<=10)
- {
- iShowBMP(0,620,"life.bmp");
- }
- if(lives==0)
- {
- page=3;
- }
- }
- iSetcolor(0,0,0);
- itoa(score,scorestr,10);
- iText(350,630,"SCORES:",GLUT_BITMAP_TIMES_ROMAN_24);
- iText(450,630,scorestr,GLUT_BITMAP_TIMES_ROMAN_24);
- }
- void page3()
- {
- iClear();
- iSetcolor(0,0,0);
- iFilledRectangle(0,0,500,650);
- iShowBMP(80,450,"gameover.bmp");
- iSetcolor(0,0,0);
- iSetcolor(1,1,1);
- iText(50,350,"Enter your Name:",GLUT_BITMAP_HELVETICA_18);
- iSetcolor(1,0,0);
- iText(200,350,namegame,GLUT_BITMAP_HELVETICA_18);
- if(high==1)
- {
- iShowBMP(100,230,"high.bmp");
- }
- iShowBMP(290,0,"tryagain.bmp");
- if(scoreshow==1)
- {
- f1=fopen("score1.txt","r");
- fscanf(f1,"%s",scorefile);
- fclose(f1);
- scorefileint=atoi(scorefile);
- itoa(score,scoregame,10);
- if(scorefileint<score)
- {
- high=1;
- f1=fopen("score1.txt","w");
- fprintf(f1,"%s",scoregame);
- fclose(f1);
- f2=fopen("name1.txt","w");
- fprintf(f2,"%s",namegame);
- fclose(f2);
- }
- f3=fopen("name1.txt","r");
- fscanf(f3,"%s",name);
- fclose(f3);
- f4=fopen("score1.txt","r");
- fscanf(f4,"%s",scorefinal);
- fclose(f4);
- iSetcolor(1,1,1);
- iText(50,150,"HIGHSCORE: ",GLUT_BITMAP_HELVETICA_18);
- iText(200,150,name,GLUT_BITMAP_HELVETICA_18);
- iSetcolor(1,0,0);
- iText(300,150,scorefinal,GLUT_BITMAP_HELVETICA_18);
- iText(50,100,"Your Score: ",GLUT_BITMAP_HELVETICA_18);
- iSetcolor(1,1,1);
- itoa(score,scoregame,10);
- iText(160,100,namegame,GLUT_BITMAP_HELVETICA_18);
- iSetcolor(1,0,0);
- iText(260,100,scoregame,GLUT_BITMAP_HELVETICA_18);
- }
- }
- void page4()
- {
- iClear();
- f5=fopen("score1.txt","r");
- fscanf(f5,"%s",scr);
- fclose(f5);
- f6=fopen("name1.txt","r");
- fscanf(f6,"%s",nme);
- fclose(f6);
- iSetcolor(1,1,1);
- iText(50,300,nme,GLUT_BITMAP_TIMES_ROMAN_24);
- iSetcolor(1,0,0);
- iText(250,300,scr,GLUT_BITMAP_TIMES_ROMAN_24);
- iShowBMP(0,475,"score.bmp");
- iShowBMP(330,0,"back.bmp");
- }
- void policemove()
- {
- if(page==2)
- {
- poli=0;
- if(policey>=0)
- {
- policey-=5;
- }
- if(policey==0)
- {
- policey=375;
- }
- if(policex>=0)
- {
- policex-=2;
- }
- if(policex==0)
- {
- if(lives>0)
- {
- score++;
- }
- policex=150;
- }
- int po=0;
- if(abs(carx-policex)<=80 && abs(cary-policey)<=60)
- {
- lives--;
- poli=1;
- }
- }
- }
- void enemy1emove()
- {
- if(page==2)
- {
- eni1=0;
- if(enemy1y>=0)
- {
- enemy1y-=5;
- }
- if(enemy1y==0)
- {
- if(lives>0)
- {
- score++;
- }
- enemy1y=375;
- }
- if(enemy1x<=410)
- {
- enemy1x+=2;
- }
- if(enemy1x==400)
- {
- enemy1x=250;
- }
- if(abs(carx-enemy1x)<=80 && abs(cary-enemy1y)<=60)
- {
- lives--;
- eni1=1;
- }
- }
- }
- void enemy2emove()
- {
- if(page==2)
- {
- eni2=0;
- if(enemy2y>=0)
- {
- enemy2y-=5;
- }
- if(enemy2y==0)
- {
- if(lives>0)
- {
- score++;
- }
- enemy2y=375;
- }
- if(abs(carx-enemy2x)<=80 && abs(cary-enemy2y)<=60)
- {
- lives--;
- eni2=1;
- }
- }
- }
- int main()
- {
- iSettimer(25,enemy2emove);
- iSettimer(30,policemove);
- iSettimer(35,enemy1emove);
- iInitialize(500,650,"Crash & Burn");
- return 0;
- }
Add Comment
Please, Sign In to add comment