rootUser

Crash amd Burn Using Visual Studio 6 and iGraphics

May 24th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.42 KB | None | 0 0
  1. #include<iGraphics.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<stdlib.h>
  5. #include<string.h>
  6.  
  7. void life();
  8.  
  9. void page1();
  10. void page2();
  11. void page3();
  12. void page4();
  13.  
  14. void policemove();
  15. void enemy1emove();
  16. void enemy2emove();
  17.  
  18. int policex=150;
  19. int policey=375;
  20.  
  21. int enemy1x=250;
  22. int enemy1y=375;
  23.  
  24. int enemy2x=195;
  25. int enemy2y=200;
  26.  
  27. int coursor=0;
  28. int ij=0;
  29.  
  30. int car=0;
  31. int car1=0;
  32.  
  33. int carx=0;
  34. int cary=0;
  35.  
  36. int page=1;
  37. int score=0;
  38. int lives=30;
  39. int poli=0;
  40. int eni1=0;
  41. int eni2=0;
  42.  
  43. char a;
  44. char b;
  45. char e;
  46. char f;
  47. char c;
  48.  
  49.  
  50. char scorestr[1000];
  51. char namegame[10];
  52. char scorefile[10];
  53. char scoregame[10];
  54. char name[10];
  55. char scorefinal[10];
  56. char scr[10];
  57. char nme[10];
  58. int scorefileint;
  59. int i=0;
  60. int xc=0;
  61. int yc=0;
  62. int j=0;
  63. int k=0;
  64. int high=0;
  65. int scoreshow=0;
  66.  
  67. double x[]={0,0,150};
  68. double y[]={60,430,430};
  69. double g[]={350,500,500};
  70. double h[]={430,430,60};
  71.  
  72. FILE *f1;
  73. FILE *f2;
  74. FILE *f3;
  75. FILE *f4;
  76. FILE *f5;
  77. FILE *f6;
  78.  
  79. void iDraw()
  80. {
  81.     iClear();
  82.     if(page==1)
  83.     {
  84.         page1();
  85.     }
  86.     if(page==2)
  87.     {
  88.         page2();
  89.     }
  90.     if(page==3)
  91.     {
  92.         page3();
  93.     }
  94.     if(page==4)
  95.     {
  96.         page4();
  97.     }
  98. }
  99.  
  100. void iMouseMove(int mx, int my)
  101. {
  102.    
  103. }
  104.  
  105. void iMouse(int button, int state, int mx, int my)
  106. {
  107.     if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
  108.     {
  109.         if(mx<=464 && mx>=300 && my<=380 && my>=340)
  110.         {
  111.            page=2;
  112.         }
  113.  
  114.         if(mx<=464 && mx>=300 && my<=310 && my>=270)
  115.         {
  116.             page=4;
  117.         }
  118.  
  119.         if(mx<=464 && mx>=300 && my<=240 && my>=200)
  120.         {
  121.             exit(0);
  122.         }
  123.  
  124.         if(mx>=190 && mx<=290 && my>=340 && my<=380 && page==3)
  125.         {
  126.             coursor=1;
  127.         }
  128.  
  129.         if(mx<=490 && mx>=290 && my<=50 && my>=0)
  130.         {
  131.             page=1;
  132.             lives=30;
  133.             score=0;
  134.             scoreshow=0;
  135.         }
  136.  
  137.         if(mx<=494 && mx>=330 && my<=40 && my>=0)
  138.         {
  139.             page=1;
  140.         }
  141.     }
  142. }
  143.  
  144. void iKeyboard(unsigned char key)
  145. {
  146.     if(coursor==1 && page==3)
  147.     {
  148.         if(key!=8)
  149.         {
  150.             if(key!='\r')
  151.             {
  152.                 namegame[ij]=key;
  153.                 ij++;
  154.             }
  155.  
  156.             if(key=='\r')
  157.             {
  158.                 scoreshow=1;
  159.                 namegame[ij]='\0';
  160.                 coursor=0;
  161.             }
  162.         }
  163.  
  164.         else if(key==8 && strlen(namegame)!=0)
  165.         {
  166.             ij--;
  167.             namegame[ij]='\0';
  168.         }
  169.     }
  170.  
  171.     else if(key=='d')
  172.     {
  173.             if(car==0)
  174.                 {
  175.                 if(carx<420)
  176.                 {
  177.                     carx+=25;
  178.                 }
  179.  
  180.                 if(carx==420)
  181.                 {
  182.                             car=1;
  183.                 }
  184.                 }
  185.     }
  186.  
  187.     else if(key=='a')
  188.     {
  189.         if(carx>0)
  190.         {
  191.             carx-=25;
  192.         }
  193.  
  194.         if(carx==0)
  195.         {
  196.             car=0;
  197.         }
  198.     }
  199.  
  200.     else if(key=='w')
  201.     {
  202.         if(car1==0)
  203.         {
  204.             if(cary<375)
  205.             {
  206.             cary+=25;
  207.             }
  208.  
  209.             if(cary==375)
  210.             {
  211.                     car1=1;
  212.             }
  213.         }
  214.     }
  215.  
  216.     else if(key=='s')
  217.     {
  218.         if(cary>0)
  219.         {
  220.             cary-=25;
  221.         }
  222.  
  223.         if(cary==0)
  224.         {
  225.             car1=0;
  226.         }
  227.     }
  228.  
  229.     else if(key == 'q')
  230.     {
  231.         exit(0);
  232.     }
  233. }
  234.  
  235. void page1()
  236. {
  237.     iSetcolor(255,255,255);
  238.     iFilledRectangle(0,0,500,650);
  239.     iShowBMP(300,340,"new.bmp");
  240.     iShowBMP(300,270,"highscore.bmp");
  241.     iShowBMP(300,200,"quit.bmp");
  242.     iShowBMP(50,0,"cover.bmp");
  243.     iShowBMP(0,160,"crash.bmp");
  244. }
  245.  
  246. void  page2()
  247. {
  248.     if(page==2)
  249.     {
  250.         iClear();
  251.         iSetcolor(0,0,0);
  252.         iShowBMP(carx,cary,"mycar.bmp");
  253.         iShowBMP(policex,policey,"police.bmp");
  254.         iShowBMP(enemy1x,enemy1y,"enemy1.bmp");
  255.         iShowBMP(enemy2x,enemy2y,"enemy2.bmp");
  256.         iShowBMP(0,430,"background.bmp");
  257.         iSetcolor(0,255,0);
  258.         iFilledPolygon(x,y,3);
  259.         iFilledPolygon(g,h,3);
  260.  
  261.         if(poli==1)
  262.         {
  263.             iShowBMP(carx,cary,"KaBoom.bmp");
  264.         }
  265.  
  266.         if(eni1==1)
  267.         {
  268.             iShowBMP(carx,cary,"KaBoom.bmp");
  269.         }
  270.  
  271.         if(eni2==1)
  272.         {
  273.         iShowBMP(carx,cary,"KaBoom.bmp");
  274.         }
  275.  
  276.         if(lives<=30 && lives>20)
  277.         {
  278.             iShowBMP(0,620,"life.bmp");
  279.         iShowBMP(40,620,"life.bmp");
  280.         iShowBMP(80,620,"life.bmp");
  281.         }
  282.  
  283.         if(lives<=20 && lives>10)
  284.         {
  285.             iShowBMP(0,620,"life.bmp");
  286.         iShowBMP(50,620,"life.bmp");
  287.         }
  288.  
  289.         if(lives>0 && lives<=10)
  290.         {
  291.         iShowBMP(0,620,"life.bmp");
  292.         }
  293.  
  294.         if(lives==0)
  295.         {
  296.             page=3;
  297.         }
  298.     }
  299.  
  300.     iSetcolor(0,0,0);
  301.     itoa(score,scorestr,10);
  302.     iText(350,630,"SCORES:",GLUT_BITMAP_TIMES_ROMAN_24);
  303.     iText(450,630,scorestr,GLUT_BITMAP_TIMES_ROMAN_24);
  304. }
  305.  
  306. void page3()
  307. {
  308.  
  309.     iClear();
  310.     iSetcolor(0,0,0);
  311.     iFilledRectangle(0,0,500,650);
  312.     iShowBMP(80,450,"gameover.bmp");
  313.     iSetcolor(0,0,0);
  314.     iSetcolor(1,1,1);
  315.     iText(50,350,"Enter your Name:",GLUT_BITMAP_HELVETICA_18);
  316.     iSetcolor(1,0,0);
  317.     iText(200,350,namegame,GLUT_BITMAP_HELVETICA_18);
  318.  
  319.     if(high==1)
  320.     {
  321.         iShowBMP(100,230,"high.bmp");
  322.     }
  323.     iShowBMP(290,0,"tryagain.bmp");
  324.  
  325.     if(scoreshow==1)
  326.     {
  327.         f1=fopen("score1.txt","r");
  328.             fscanf(f1,"%s",scorefile);
  329.             fclose(f1);
  330.  
  331.             scorefileint=atoi(scorefile);
  332.             itoa(score,scoregame,10);
  333.  
  334.             if(scorefileint<score)
  335.             {
  336.                 high=1;
  337.                     f1=fopen("score1.txt","w");
  338.                 fprintf(f1,"%s",scoregame);
  339.                     fclose(f1);
  340.                     f2=fopen("name1.txt","w");
  341.                 fprintf(f2,"%s",namegame);
  342.                     fclose(f2);
  343.             }
  344.  
  345.             f3=fopen("name1.txt","r");
  346.             fscanf(f3,"%s",name);
  347.             fclose(f3);
  348.  
  349.             f4=fopen("score1.txt","r");
  350.             fscanf(f4,"%s",scorefinal);
  351.             fclose(f4);
  352.  
  353.         iSetcolor(1,1,1);
  354.         iText(50,150,"HIGHSCORE: ",GLUT_BITMAP_HELVETICA_18);
  355.         iText(200,150,name,GLUT_BITMAP_HELVETICA_18);
  356.         iSetcolor(1,0,0);
  357.             iText(300,150,scorefinal,GLUT_BITMAP_HELVETICA_18);
  358.         iText(50,100,"Your Score: ",GLUT_BITMAP_HELVETICA_18);
  359.         iSetcolor(1,1,1);
  360.         itoa(score,scoregame,10);
  361.         iText(160,100,namegame,GLUT_BITMAP_HELVETICA_18);
  362.         iSetcolor(1,0,0);
  363.         iText(260,100,scoregame,GLUT_BITMAP_HELVETICA_18);
  364.     }
  365. }
  366.  
  367. void page4()
  368. {
  369.     iClear();
  370.     f5=fopen("score1.txt","r");
  371.         fscanf(f5,"%s",scr);
  372.         fclose(f5);
  373.  
  374.     f6=fopen("name1.txt","r");
  375.         fscanf(f6,"%s",nme);
  376.         fclose(f6);
  377.  
  378.     iSetcolor(1,1,1);
  379.     iText(50,300,nme,GLUT_BITMAP_TIMES_ROMAN_24);
  380.  
  381.     iSetcolor(1,0,0);
  382.     iText(250,300,scr,GLUT_BITMAP_TIMES_ROMAN_24);
  383.    
  384.     iShowBMP(0,475,"score.bmp");
  385.  
  386.     iShowBMP(330,0,"back.bmp");
  387. }
  388.  
  389. void policemove()
  390. {
  391.     if(page==2)
  392.         {
  393.         poli=0;
  394.  
  395.         if(policey>=0)
  396.         {
  397.             policey-=5;
  398.         }
  399.  
  400.         if(policey==0)
  401.         {
  402.             policey=375;
  403.         }
  404.  
  405.         if(policex>=0)
  406.         {
  407.             policex-=2;
  408.         }
  409.  
  410.         if(policex==0)
  411.         {
  412.             if(lives>0)
  413.                 {
  414.                 score++;
  415.             }
  416.             policex=150;
  417.         }
  418.  
  419.         int po=0;
  420.  
  421.         if(abs(carx-policex)<=80 && abs(cary-policey)<=60)
  422.         {
  423.             lives--;
  424.             poli=1;
  425.         }
  426.     }
  427. }
  428.  
  429. void enemy1emove()
  430. {
  431.     if(page==2)
  432.     {
  433.        eni1=0;
  434.  
  435.        if(enemy1y>=0)
  436.        {
  437.             enemy1y-=5;
  438.        }
  439.  
  440.        if(enemy1y==0)
  441.        {
  442.             if(lives>0)
  443.             {
  444.                 score++;
  445.             }
  446.  
  447.             enemy1y=375;
  448.        }
  449.  
  450.        if(enemy1x<=410)
  451.        {
  452.             enemy1x+=2;
  453.        }
  454.  
  455.        if(enemy1x==400)
  456.        {
  457.             enemy1x=250;
  458.        }
  459.  
  460.        if(abs(carx-enemy1x)<=80 && abs(cary-enemy1y)<=60)
  461.        {
  462.             lives--;
  463.             eni1=1;
  464.        }
  465.     }
  466. }
  467.  
  468. void enemy2emove()
  469. {
  470.     if(page==2)
  471.     {
  472.         eni2=0;
  473.  
  474.         if(enemy2y>=0)
  475.         {
  476.         enemy2y-=5;
  477.         }
  478.  
  479.         if(enemy2y==0)
  480.         {
  481.         if(lives>0)
  482.             {
  483.             score++;
  484.         }
  485.         enemy2y=375;
  486.         }
  487.  
  488.         if(abs(carx-enemy2x)<=80 && abs(cary-enemy2y)<=60)
  489.         {
  490.             lives--;
  491.         eni2=1;
  492.         }
  493.     }
  494. }
  495.  
  496. int main()
  497. {
  498.     iSettimer(25,enemy2emove);
  499.  
  500.     iSettimer(30,policemove);
  501.  
  502.     iSettimer(35,enemy1emove);
  503.  
  504.     iInitialize(500,650,"Crash & Burn");
  505.  
  506.     return 0;
  507. }
Add Comment
Please, Sign In to add comment