Anupznk

aww

Sep 9th, 2019
161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # include "iGraphics.h"
  2. # include "gl.h"
  3. # include <Windows.h>
  4. #include<math.h>
  5. #include<stdio.h>
  6. int man_x=10, man_y=150;
  7. int dx, dy;
  8. int sprint=0;
  9. int lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  10. //int laser_x[]={300,250},laser_y[]={200,150}
  11. int movingLaserRange_x1[]={40,500,100,50},movingLaserRange_x2[]={500,900,600,500},laserMove[]={1,1,1,1},laserLen=100;
  12. int laser_x[]={300,700,200,500},laser_y[]={190,270,400,500};
  13. int horizontal_laser_count=4;
  14. int vertical_movingLaserRange_y1[]={550,300},vertical_movingLaserRange_y2[]={650,500},vertical_laserMove[]={0,1};
  15. int vertical_laser_x[]={850,700},vertical_laser_y[]={600,400};
  16. int vertical_laser_count=2;
  17. int level=0;
  18. double health=100;
  19. double health_x[]={600,300,900},health_y[]={768,768,768},hel_initial_x,hel_initial_y;
  20. int health_taken=0,pack_len,pack_wid;//,health_yes
  21. int man_wid,man_height;
  22. int man_mov_right=1,man_mov_left=0,man_mov_up=0,man_mov_down=0;
  23. int mouse_clk=0;
  24. int stop_sound=0;
  25. int bg=1;
  26. double bomb_x[]={1336,1000,300,0},bomb_y[]={768,768,768,300},bomb_x_change[]={-2,-1.5,2,2},bomb_y_change[]={-1,-1.5,-1.5,1},
  27. bomb_initial_x,bomb_initial_y,bomb_r=8;
  28. double d[5];//for bomb_chk
  29. int hel_tm,health_pack_chk,hel_pck_num;
  30. int bomb_tm,bomb_chk,bomb_cnt;
  31. int back_from_howto=0,back_from_high=0;
  32. int cont=0,new_game=0,high_score=0,how_to_play=0,cont_chk=1;
  33. int gem_collected[]={0,0,0};
  34. int game_over=0, game_over_y=0,game_end;
  35. double max_score_count=0;
  36. int score_count[]={0,0,0,0,0},current_score=0;
  37. double timer=0;
  38. int score_multiplier=1;
  39. int dead_man_x,dead_man_y;
  40. float camx=0, camy=0;
  41. int leftkbhit = 0, rightkbhit = 0, camxLSCount = 0, camxRSCount = 0;
  42. float enemyFX = 1500, enemyFY=600;
  43.  
  44. ////======================== MENU PAGE DECORATION ================================
  45. //int cont_rectangle_sweep=0,newgame_rectangle_sweep=0,high_score_rectangle_sweep=0,how_to_play_rectangle_sweep=0;
  46. //int rec_swap_len=0;
  47.  
  48. //ENEMY VARIABLES:
  49. int enemyNum = 4;
  50. int enemyX[4] = {200, 400, 600, 1000}, enemyY[4] = {50,100,150,300};
  51. float enemyHealth[4] = {100,100,100,100};
  52. float enemyWidth[4] = {100,100,100,50};
  53. float enemyHeight[4] = {100,100,100,50};
  54. int enemyHitIndex;
  55.  
  56.  
  57. //******************************* ANUP NEW *************************
  58.  
  59.  
  60. //******************************* ANUP NEW *************************
  61.  
  62. //LASER VARIABLES:
  63. float laserEnd;
  64. int laserSwitch = 0, laserTimer=0, laserStat = 0;
  65. float laserHealth = 100;
  66. int manLeft = 0, manRight = 1;
  67.  
  68. int world_len_right=5000;
  69.  
  70. int test[]={0,9,18,27,36,45,54,63,72,81},bul[10],bul_ctrl=90;
  71. double bul_x[10],bul_y[10];
  72. double bul_l=10,bul_h=4;
  73. //int dis[10];
  74.  
  75. void menu_sound()
  76. {
  77. if(level==0)
  78. PlaySound("music\\menu background.wav", NULL, SND_LOOP | SND_ASYNC);
  79. else
  80. PlaySound(NULL, NULL, SND_ASYNC);
  81.  
  82. }
  83. void pause_menu_sound()
  84. {
  85. if(level==0)
  86. PlaySound("music\\Pause menu.wav", NULL, SND_LOOP | SND_ASYNC);
  87. else
  88. PlaySound(NULL, NULL, SND_ASYNC);
  89.  
  90. }
  91. void score_page_sound()
  92. {
  93. if( high_score)
  94. PlaySound("music\\high score.wav", NULL, SND_ASYNC);
  95. else if(high_score==0)
  96. PlaySound(NULL, NULL, SND_ASYNC);
  97.  
  98. }
  99. void level_one_sound()
  100. {
  101. if(level==1 && game_over==0)
  102. PlaySound("music\\game background.wav", NULL, SND_LOOP | SND_ASYNC);
  103. else
  104. PlaySound(NULL, NULL,SND_ASYNC);
  105.  
  106. }
  107.  
  108.  
  109. void game_over_sound()
  110. {
  111. if(game_over)
  112. PlaySound("music\\Game_Over.wav", NULL, SND_ASYNC);
  113. else
  114. PlaySound(NULL, NULL, SND_ASYNC);
  115.  
  116.  
  117. }
  118.  
  119. /*
  120. ********************************** FOLLOWING AND STATIC ENEMY CODE *********************************************************
  121. */
  122.  
  123. void enemy()
  124. {
  125. iSetColor(0,0,255);
  126. for(int i = 0; i<enemyNum; i++)
  127. {
  128. if(enemyHealth[i]>10)
  129. iRectangle((enemyX[i]-camx), (enemyY[i]-camy), enemyWidth[i], enemyHeight[i]);
  130. }
  131.  
  132. }
  133.  
  134. float laserEndDetect(float laserX, float laserY) //FUNCTION TO DETECT THE ENDING POINT OF A LASER
  135. {
  136. float matchX[100]; //KEEPS RECORD OF ALL X'S WHICH MATCH THE REQUIREMENTS
  137. int c=0; //KEEPS TRACK OF THE NUMBER OF ELEMENTS IN ARRAY AKA THE NUMBER OF MATCHES+1 (REASON BELOW)
  138.  
  139. if(manRight)
  140. {
  141. for(int i=0; i<enemyNum; i++)
  142. {
  143.  
  144. if(laserY-(enemyY[i]-camy)>0 && laserY-(enemyY[i]-camy)<enemyHeight[i] && laserX<(enemyX[i]-camx) && enemyHealth[i]>0.01)
  145. {
  146. //POPULATING THE ARRAY
  147. matchX[c] = (enemyX[i]-camx);
  148.  
  149. c++; //CAUSES C TO ALWAYS BE LARGER BY 1
  150.  
  151.  
  152. }
  153. }
  154.  
  155. if(!c)//IF THERE ARE NO MATCHES
  156. {
  157. enemyHitIndex = -1;
  158. return 1366; //INFINITE LASER
  159. }
  160.  
  161.  
  162. else
  163. {
  164. //finding the minimum
  165.  
  166. float minX = matchX[0];
  167. for(int i = 0; i<c; i++)
  168. {
  169. if(matchX[i]<minX)
  170. minX = matchX[i];
  171.  
  172. }
  173.  
  174. for(int i=0; i<enemyNum; i++)
  175. {
  176. if(minX == (enemyX[i]-camx))
  177. enemyHitIndex = i;
  178. }
  179.  
  180. return minX;
  181. }
  182. }
  183.  
  184. if(manLeft)
  185. {
  186. for(int i=0; i<enemyNum; i++)
  187. {
  188.  
  189. if(laserY-(enemyY[i]-camy)>0 && laserY-(enemyY[i]-camy)<enemyHeight[i] && laserX>(enemyX[i]-camx) && enemyHealth[i]>0.01)
  190. {
  191. //POPULATING THE ARRAY
  192. matchX[c] = (enemyX[i]-camx);
  193. c++; //CAUSES C TO ALWAYS BE LARGER BY 1
  194.  
  195.  
  196. }
  197. }
  198.  
  199. if(!c)//IF THERE ARE NO MATCHES
  200. {
  201. enemyHitIndex = -1;
  202. return 0; //INFINITE LASER
  203. }
  204.  
  205.  
  206. else
  207. {
  208. //finding the minimum
  209.  
  210. float minX = matchX[0];
  211. for(int i = 0; i<c; i++)
  212. {
  213. if(matchX[i]<minX)
  214. minX = matchX[i];
  215.  
  216. }
  217.  
  218. for(int i=0; i<enemyNum; i++)
  219. {
  220. if(minX == (enemyX[i]-camx))
  221. enemyHitIndex = i;
  222. }
  223.  
  224. return minX+enemyWidth[enemyHitIndex];
  225. }
  226. }
  227. }
  228.  
  229. void reduceEnemyHealth() //FUNCTION TO REDUCE ENEMY HEALTH TO 0
  230. {
  231. if(laserSwitch == 1 && enemyHitIndex != -1)
  232. {
  233. if(enemyHealth[enemyHitIndex]>=0)
  234. {
  235. enemyHealth[enemyHitIndex]-=2;
  236. }
  237. }
  238. }
  239.  
  240. void laser()
  241. {
  242.  
  243. if(manRight)
  244. {
  245. float laserX = man_x+60;
  246. float laserY = man_y+70;
  247. iSetColor(255,0,0);
  248. iLine(laserX, laserY, laserEndDetect(laserX, laserY), laserY);
  249.  
  250. }
  251.  
  252. if(manLeft)
  253. {
  254. float laserX = man_x;
  255. float laserY = man_y+70;
  256. iSetColor(255,0,0);
  257. iLine(laserX, laserY, laserEndDetect(laserX, laserY), laserY);
  258. }
  259.  
  260. }
  261.  
  262.  
  263.  
  264. void enemyF()
  265. {
  266. iSetColor(0,0,0);
  267. iRectangle(enemyFX-camx, enemyFY-camy, 10, 10);
  268. }
  269.  
  270. void changeEnemy()
  271. {
  272.  
  273. if((enemyFX-camx<man_x+200)&&(enemyFX-camx>man_x-100) && (enemyFY-camy<man_y+200) && (enemyFY-camy>man_y-100))
  274. return;
  275.  
  276.  
  277. if(enemyFX-camx-man_x>10 || man_x-enemyFX+camx>10)
  278. {
  279. if(enemyFX-camx>man_x)
  280. enemyFX-=10;
  281. else
  282. enemyFX+=10;
  283.  
  284. if(enemyFY-camy>man_y)
  285. {
  286. enemyFY-=10*((enemyFY-man_y)/abs(enemyFX-man_x));
  287. }
  288.  
  289. else if(enemyFY-camy<man_y)
  290. {
  291. enemyFY+=10*((man_y-(enemyFY-camy))/abs(enemyFX-camx-man_x));
  292. }
  293.  
  294. }
  295.  
  296.  
  297.  
  298. }
  299. void changelasercolor(){
  300.  
  301. if(changecolor==0 && lasercolorR!=255)
  302. {
  303. lasercolorR+=15; // to change color faster
  304. if(lasercolorR==255)
  305. {
  306. changecolor=1;
  307. }
  308. }
  309. if(changecolor==1 && lasercolorR!=0)
  310. {
  311. lasercolorR-=15; // to change color faster
  312. if(lasercolorR==0)
  313. {
  314. changecolor=0;
  315. }
  316. }
  317.  
  318. }
  319.  
  320.  
  321. /*
  322. function iMouseMove() is called when the user presses and drags the mouse.
  323. (mx, my) is the position where the mouse pointer is.
  324. */
  325. void iMouseMove(int mx, int my)
  326. {
  327. //place your codes here
  328. }
  329.  
  330. /*
  331. function iMouse() is called when the user presses/releases the mouse.
  332. (mx, my) is the position where the mouse pointer is.
  333. */
  334. void iMouse(int button, int state, int mx, int my)
  335. {
  336. if(button == GLUT_LEFT_BUTTON && state == GLUT_UP && level!=1)
  337. {
  338. if(mx>=185 && mx<=185+270 && my>=382 && my<=382+100)
  339. {
  340. cont=1;
  341. //cont_chk=1;
  342. new_game=0;
  343. how_to_play=0;
  344. high_score=0;
  345. back_from_howto=0;
  346. back_from_high=0;
  347. //iText(500,500,"Continue");
  348.  
  349. // FILE* fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9,*fp10,*fp11, *fp12;
  350. // fp1=fopen("man_x_man_y.txt","r");
  351. // fscanf(fp1,"%d %d",&man_x,&man_y);
  352. // fclose(fp1);
  353. //
  354. // fp2=fopen("dx_dy.txt","r");
  355. // fscanf(fp2,"%d %d",&dx,&dy);
  356. // fclose(fp2);
  357. //
  358. //
  359. // fp3=fopen("horizontal_laser.txt","r");
  360. // fscanf(fp3,"%d %d %d %d",&laser_x[0],&laser_x[1],&laser_x[2],&laser_x[3]);
  361. // fclose(fp3);
  362. //
  363. //
  364. // fp4=fopen("vertical_laser.txt","r");
  365. // fscanf(fp4,"%d %d",&vertical_laser_y[0],&vertical_laser_y[1]);
  366. // fclose(fp4);
  367. //
  368. //
  369. // fp5=fopen("bomb1.txt","r");
  370. // fscanf(fp5,"%d %d %d",&bomb_cnt,&bomb_chk,&bomb_tm);
  371. // fclose(fp5);
  372. //
  373. //
  374. // fp6=fopen("bomb2.txt","r");
  375. // fscanf(fp6,"%f %f %f %f %f %f",&bomb_x[bomb_cnt-1],&bomb_y[bomb_cnt-1],&bomb_x_change[bomb_cnt-1],&bomb_y_change[bomb_cnt-1],&bomb_initial_x,&bomb_initial_y);
  376. // fclose(fp6);
  377. //
  378. //
  379. // fp7=fopen("health.txt","r");
  380. // fscanf(fp7,"%f",&health);
  381. // fclose(fp7);
  382. //
  383. //
  384. // fp8=fopen("health_pack1.txt","r");
  385. // fscanf(fp8,"%d %d %d",&hel_pck_num,&health_pack_chk,&hel_tm);
  386. // fclose(fp8);
  387. //
  388. //
  389. // fp9=fopen("health_pack_2.txt","r");
  390. // fscanf(fp9,"%lf %lf %d %d",&health_x[hel_pck_num-1],&health_y[hel_pck_num-1],&hel_initial_x,&hel_initial_y);
  391. // fclose(fp9);
  392. //
  393. //
  394. // fp10=fopen("timer.txt","r");
  395. // fscanf(fp10,"%f",&timer);
  396. // fclose(fp10);
  397. //
  398. // fp11=fopen("score.txt","r");
  399. // fscanf(fp11,"%f",&score_count);
  400. // fclose(fp11);
  401. //
  402. // fp12=fopen("high score list.txt","r");
  403. // for(int i=0;i<5;i++)
  404. // {
  405. // fscanf(fp12,"%d ",&score_count[i]);
  406. // }
  407. // fclose(fp12);
  408.  
  409. level=1;
  410. menu_sound();
  411. level_one_sound();
  412. }
  413.  
  414. if(mx>=185 && mx<=185+295 && my>=302 && my<=382 && level!=1)
  415. {
  416.  
  417. new_game=1;
  418. camx=0,camy=0;
  419. score_multiplier=1;
  420. score_count[0]=0;
  421. score_count[1]=0;
  422. score_count[2]=0;
  423. score_count[3]=0;
  424. score_count[4]=0;
  425. current_score=0;
  426. man_x=30, man_y=150;
  427. health=100;
  428. sprint=0;
  429. cont=0;
  430. level=1;
  431. man_mov_right=1;
  432. man_mov_down=0;
  433. man_mov_left=0;
  434. man_mov_up=0;
  435. man_x=10;
  436. man_y=150;
  437. dx=3, dy=3;
  438. sprint=0;
  439. lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  440.  
  441. laserMove[0]=1;
  442. laserMove[1]=1;
  443. laserMove[2]=1;
  444. laserMove[3]=1;
  445.  
  446. laser_x[0]=300;
  447. laser_x[1]=700;
  448. laser_x[2]=200;
  449. laser_x[3]=500;
  450.  
  451. laser_y[0]=190;
  452. laser_y[1]=270;
  453. laser_y[2]=400;
  454. laser_y[3]=500;
  455.  
  456. vertical_laserMove[0]=0;
  457. vertical_laserMove[1]=1;
  458.  
  459.  
  460. vertical_laser_x[0]=850;
  461. vertical_laser_x[1]=700;
  462.  
  463. vertical_laser_y[0]=600;
  464. vertical_laser_y[1]=400;
  465.  
  466. vertical_laser_count=2;
  467. health=100;
  468. // health_x[]={600,300,900},health_y[]={768,768,768};
  469.  
  470. health_x[0]=600;
  471. health_x[1]=300;
  472. health_x[2]=900;
  473.  
  474. health_y[0]=768;
  475. health_y[1]=768;
  476. health_y[2]=768;
  477.  
  478. hel_tm=0,health_pack_chk=0,hel_pck_num=0;
  479.  
  480. health_taken=0;//health_yes
  481.  
  482. bomb_x[0]=1336;
  483. bomb_x[2]=1000;
  484. bomb_x[2]=300;
  485. bomb_x[3]=0;
  486.  
  487. bomb_y[0]=768;
  488. bomb_y[1]=768;
  489. bomb_y[2]=768;
  490. bomb_y[3]=300;
  491.  
  492. bomb_tm=0,bomb_chk=0,bomb_cnt=0;
  493.  
  494. gem_collected[0]=0;
  495. gem_collected[1]=0;
  496. gem_collected[2]=0;
  497.  
  498. how_to_play=0;
  499. high_score=0;
  500. back_from_howto=0;
  501. back_from_high=0;
  502. level=1;
  503. menu_sound();
  504. level_one_sound();
  505. }
  506.  
  507. if(mx>=185 && mx<=185+315 && my>=222&& my<=222+80 && level!=1)
  508. {
  509. cont=0;
  510. new_game=0;
  511. how_to_play=0;
  512. high_score=1;
  513. // level=-1;
  514. menu_sound();
  515. score_page_sound();
  516.  
  517. back_from_howto=0;
  518. back_from_high=0;
  519. //level=1;
  520. }
  521.  
  522. if(mx>=185 && mx<=185+350 && my>=142 && my<=142+80 && level!=1)
  523.  
  524. {
  525. cont=0;
  526. new_game=0;
  527. how_to_play=1;
  528. high_score=0;
  529. back_from_howto=0;
  530. back_from_high=0;
  531. //level=1;
  532. }
  533. if( how_to_play && mx>=603 && mx<=603+180 && my>=50 && my<=50+65 && level!=1)
  534. {
  535. back_from_howto=1;
  536. back_from_high=0;
  537. }
  538. if( high_score && mx>=603 && mx<=603+180 && my>=50 && my<=50+65 && level!=1)
  539. {
  540. back_from_howto=0;
  541. back_from_high=1;
  542. high_score=0;
  543. score_page_sound();
  544. menu_sound();
  545.  
  546. }
  547. }
  548.  
  549. // if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
  550. // {
  551. // if(mx>=185 && mx<=185+270 && my>=382 && my<=382+100)
  552. // {
  553. //// cont_rectangle_sweep=1;
  554. //// how_to_play_rectangle_sweep=0;
  555. //// high_score_rectangle_sweep=0;
  556. // newgame_rectangle_sweep=0;
  557. // }
  558. // }
  559. }
  560.  
  561. /*
  562. function iKeyboard() is called whenever the user hits a key in keyboard.
  563. key- holds the ASCII value of the key pressed.
  564. */
  565. void iKeyboard(unsigned char key)
  566. {
  567. if((key=='p'||key=='P') && game_over!=1){
  568. level=0;
  569. game_over=0;
  570. new_game=0;
  571. cont=0;
  572. level_one_sound();
  573. pause_menu_sound();
  574. }
  575.  
  576. if(key == 13 && !laserStat)
  577. {
  578. laserSwitch = 1;
  579. }
  580.  
  581. }
  582.  
  583. /*
  584. function iSpecialKeyboard() is called whenver user hits special keys like-
  585. function keys, home, end, pg up, pg down, arraows etc. you have to use
  586. appropriate constants to detect them. A list is:
  587. GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
  588. GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11, GLUT_KEY_F12,
  589. GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_DOWN, GLUT_KEY_PAGE UP,
  590. GLUT_KEY_PAGE DOWN, GLUT_KEY_HOME, GLUT_KEY_END, GLUT_KEY_INSERT
  591.  
  592. */
  593. void iSpecialKeyboard(unsigned char key)
  594. {
  595. if(key == GLUT_KEY_DOWN)
  596. {
  597. dy=3;
  598. if(sprint%2==1)
  599. dy=8;
  600.  
  601. if(man_y>10)
  602. man_y-=dy;
  603.  
  604.  
  605. man_mov_down=1;
  606. man_mov_left=0;
  607. man_mov_right=0;
  608. man_mov_up=0;
  609.  
  610. }
  611. if(key == GLUT_KEY_UP)
  612. {
  613. dy=3;
  614. if(sprint%2==1)
  615. dy=8;
  616.  
  617. if(man_y<700)
  618. man_y+=dy;
  619.  
  620. // else if(camy<500)
  621. // {
  622. // camy+=dy;
  623. // }
  624.  
  625. man_mov_down=0;
  626. man_mov_left=0;
  627. man_mov_right=0;
  628. man_mov_up=1;
  629. }
  630. if(key == GLUT_KEY_RIGHT)
  631. {
  632. dx=10;
  633. if(sprint%2==1)
  634. dx=8;
  635.  
  636. manLeft=0;
  637. manRight=1;
  638.  
  639. if(man_x<1246)
  640. {
  641.  
  642. //COORDINATION BETWEEN MAN AND CAMERA: FIRST 500 UNITS WITHOUT CHANGING THE CAMERA POSITION
  643. if(man_x<=500)
  644. {
  645. man_x+=dx;
  646. }
  647. //MIDDLE MOVEMENT HAPPENS WHEN MAN X TIRES TO EXCEED 400 AND CAMERA IS BETWEEN 0 AND 1000
  648. else if(man_x>500)
  649. {
  650. if(camx<=world_len_right)
  651. camx+=dx;
  652. }
  653.  
  654. //STOPPING THE CAMERA AFTER CAMERA X TRIES TO EXCEED 1000
  655. if(camx>world_len_right)
  656. {
  657. man_x+=dx;
  658. }
  659.  
  660.  
  661. }
  662.  
  663.  
  664. man_mov_down=0;
  665. man_mov_left=0;
  666. man_mov_right=1;
  667. man_mov_up=0;
  668.  
  669. }
  670. if(key == GLUT_KEY_LEFT)
  671. {
  672. dx=15;
  673. if(sprint%2==1)
  674. dx=8;
  675.  
  676. manLeft=1;
  677. manRight=0;
  678.  
  679. //BASE CONDITION: UNTIL THE MAN REACHES 10
  680. if(man_x>10)
  681. {
  682.  
  683. //ONCE CAMX TRIES TO GO TO A NEGATIVE VALUE, REDUCE man_x UP TILL BASE CONDITION AT THE TOP
  684.  
  685. if(camx<0)
  686. {
  687. man_x-=dx;
  688. }
  689.  
  690.  
  691. //IF CAMERA X IS GREATER THAN 1000 (5 added to make small buffer (ALWAYS LESS THAN dx))
  692. else if(camx>=1000)
  693. {
  694. // MOVE THE MAN UPTIL man_x=800
  695. if(man_x>=600)
  696. {
  697. man_x-=dx;
  698. }
  699.  
  700. }
  701.  
  702. //IF man_x TRIES TO GO BELOW 800, REDUCE CAMERA X UNTIL CAMERA X BECOMES EQUAL TO 0
  703. if(man_x<600)
  704. {
  705. if(camx>=0)
  706. camx-=dx;
  707. }
  708. }
  709.  
  710.  
  711. man_mov_down=0;
  712. man_mov_left=1;
  713. man_mov_right=0;
  714. man_mov_up=0;
  715.  
  716.  
  717. }
  718. if(key== GLUT_KEY_PAGE_DOWN)
  719. {
  720. sprint++;
  721. }
  722.  
  723. // while(key == GLUT_KEY_PAGE_UP)
  724. // {
  725. // }
  726.  
  727. if(key == GLUT_KEY_END)
  728. exit(0);
  729. }
  730.  
  731. void vertical_health_change(int i)
  732. {
  733.  
  734. if((man_y>=vertical_laser_y[i]-camy-man_height && man_y<=vertical_laser_y[i]-camy+100) && (man_x>=vertical_laser_x[i]-camx-man_wid && man_x<=vertical_laser_x[i]-camx+3))
  735. {
  736. man_x-=2;
  737. man_y-=2;
  738. if(health>0)
  739. health-=1;
  740. else health=0;
  741. //stop_sound=1;
  742.  
  743. }
  744.  
  745.  
  746. }
  747.  
  748. void horizontalLaser(int laserLen,int i)
  749. {
  750. iSetColor(lasercolorR,255,lasercolorB);
  751. iFilledRectangle(laser_x[i]-camx,laser_y[i]-camy,laserLen,3);
  752. iSetColor(0,255,0);
  753. iFilledRectangle(laser_x[i]-camx-10,laser_y[i]-camy-3,10,10);
  754.  
  755. iSetColor(0,255,0);
  756. iFilledRectangle(laser_x[i]-camx+100,laser_y[i]-camy-3,10,10);
  757.  
  758. }
  759. void verticalLaser(int laserLen,int i)
  760. {
  761. iSetColor(lasercolorR,255,lasercolorB);
  762. iFilledRectangle(vertical_laser_x[i]-camx,vertical_laser_y[i]-camy,3,laserLen);
  763. iSetColor(0,255,0);
  764. iFilledRectangle(vertical_laser_x[i]-camx-3,vertical_laser_y[i]-camy-10,10,10);
  765. iSetColor(0,255,0);
  766. iFilledRectangle(vertical_laser_x[i]-camx-3,vertical_laser_y[i]-camy+100,10,10);
  767. }
  768. void healthPack()
  769. {
  770. if(health_pack_chk){
  771. if(hel_pck_num<=3)
  772. {
  773. pack_len=26, pack_wid=22;
  774. iSetColor(211,211,211);
  775. iFilledRectangle(health_x[hel_pck_num-1]-camx,health_y[hel_pck_num-1]-camy,pack_len,pack_wid);
  776. iSetColor(0,0,0);
  777. iFilledRectangle(health_x[hel_pck_num-1]-camx+(pack_len/2)-2,health_y[hel_pck_num-1]+3-camy,4,pack_wid-6);
  778. iFilledRectangle(health_x[hel_pck_num-1]+3-camx,health_y[hel_pck_num-1]+(pack_wid/2)-2-camy,pack_len-6,4);
  779. if(health_y[hel_pck_num-1]>0)
  780. health_y[hel_pck_num-1]-=.5;
  781. }
  782. if((man_x>=health_x[hel_pck_num-1]-man_wid-camx && man_x<=health_x[hel_pck_num-1]+pack_len-camx) && (man_y>=health_y[hel_pck_num-1]-man_height-camy && man_y<=health_y[hel_pck_num-1]+pack_wid-camy))
  783. {
  784. //health_taken=1;
  785. health_x[hel_pck_num-1]=-10; //making the healthpacks disappear
  786. health_y[hel_pck_num-1]=-10;
  787. if (health>=80)
  788. health=100;
  789. else
  790. health+=20;
  791. health_pack_chk=0;
  792. }
  793. if(health_y[hel_pck_num-1]<=50){
  794. health_pack_chk=0;
  795. health_x[hel_pck_num-1]=hel_initial_x;
  796. health_y[hel_pck_num-1]=hel_initial_y;
  797. }
  798. }
  799.  
  800. }
  801. void bomb()
  802. {
  803. // BOMB ER RESPONSE CAM DEPENDENT KORA LAGBE
  804. // SUMON ER CODE
  805.  
  806. if(bomb_chk){
  807. iSetColor(255,0,0);
  808. iFilledCircle((bomb_x[bomb_cnt-1]-camx),bomb_y[bomb_cnt-1],bomb_r,100);
  809. (bomb_x[bomb_cnt-1])+=bomb_x_change[bomb_cnt-1];
  810. bomb_y[bomb_cnt-1]+=bomb_y_change[bomb_cnt-1];
  811. d[0]=sqrt((man_x-(bomb_x[bomb_cnt-1]-camx))*(man_x-(bomb_x[bomb_cnt-1]-camx))+(man_y-bomb_y[bomb_cnt-1])*(man_y-bomb_y[bomb_cnt-1]));
  812. d[1]=sqrt(((man_x+man_wid)-(bomb_x[bomb_cnt-1]-camx))*((man_x+man_wid)-(bomb_x[bomb_cnt-1]-camx))+(man_y-bomb_y[bomb_cnt-1])*(man_y-bomb_y[bomb_cnt-1]));
  813. d[2]=sqrt((man_x-(bomb_x[bomb_cnt-1]-camx))*(man_x-(bomb_x[bomb_cnt-1]-camx))+((man_y+man_height)-bomb_y[bomb_cnt-1])*((man_y+man_height)-bomb_y[bomb_cnt-1]));
  814. d[3]=sqrt(((man_x+man_wid)-(bomb_x[bomb_cnt-1]-camx))*((man_x+man_wid)-(bomb_x[bomb_cnt-1]-camx))+((man_y+man_height)-bomb_y[bomb_cnt-1])*((man_y+man_height)-bomb_y[bomb_cnt-1]));
  815. if(d[0]<=bomb_r||d[1]<=bomb_r||d[2]<=bomb_r||d[3]<=bomb_r){
  816. if(health>2)
  817. health-=2;
  818. else
  819. health=0;
  820. }
  821. if(bomb_y[bomb_cnt-1]<=50||bomb_y[3]>=768){
  822. bomb_chk=0;
  823. bomb_x[bomb_cnt-1]-=bomb_initial_x;
  824. bomb_y[bomb_cnt-1]=bomb_initial_y;
  825. }
  826. }
  827. }
  828.  
  829. void enemyplane(int m)
  830. {
  831. if(bul[m]==1){
  832. iSetColor(0,0,0);
  833. //dis[m]=dis[m]+3;
  834. bul_x[m]=bul_x[m]-3;
  835. iFilledRectangle(bul_x[m]-camx,bul_y[m],bul_l,bul_h);
  836.  
  837. if(bul_x[m]<-4){
  838. bul[m]=0;
  839. test[m]=1;
  840.  
  841. }
  842. if((man_x>=bul_x[m]-camx-man_wid && man_x<=bul_x[m]-camx+bul_l) && (man_y>=bul_y[m]-man_height && man_y<=bul_y[m]+bul_h))
  843. {
  844. FILE *fp;
  845. if(health>0.3)
  846. health-=.3;
  847. else health=0;
  848. fp=fopen("health.txt","w");
  849. fprintf(fp,"%f",health);
  850. fclose(fp);
  851. }
  852. }
  853. }
  854.  
  855. void score_show_live()
  856. {
  857. char curr_score[100], buf[100];
  858. strcpy(curr_score,"CURRENT SCORE: ");
  859. strcat(curr_score,itoa(current_score,buf,10));
  860. iSetColor(255,0,0);
  861. iText(10,750,curr_score);
  862.  
  863. char score_mul[100];
  864. strcpy(score_mul,"SCORE MULTIPLIER: X");
  865. strcat(score_mul,itoa(score_multiplier,buf,10));
  866. iSetColor(255,0,0);
  867. iText(10,730,score_mul);
  868.  
  869. char hi_score[100];
  870. strcpy(hi_score,"HIGH SCORE: ");
  871. strcat(hi_score,itoa(score_count[0],buf,10));
  872. iSetColor(255,0,0);
  873. iText(10,710,hi_score);
  874. }
  875.  
  876. void score()
  877. { if(!game_over){
  878. current_score+=1*score_multiplier;
  879. }
  880. }
  881. void health_change(int i)
  882. {
  883. if((man_x>=laser_x[i]-camx-man_wid && man_x<=laser_x[i]-camx+100) && (man_y>=laser_y[i]-camy-man_height && man_y<=laser_y[i]-camy+2))
  884. {
  885. FILE *fp;
  886. man_x-=2;
  887. man_y+=2;
  888. if(health>0)
  889. health-=1;
  890. else health=0;
  891. stop_sound=1;
  892. fp=fopen("health.txt","w");
  893. fprintf(fp,"%d",health);
  894. fclose(fp);
  895. }
  896. }
  897.  
  898. //******************************* ANUP NEW *************************
  899. void enemyTouch_health_change(int i)
  900. {
  901. if((man_x>=enemyX[i]-camx-man_wid && man_x<=enemyX[i]-camx+enemyHeight[i]) && (man_y>=enemyY[i]-camy-man_height && man_y<=enemyY[i]-camy+enemyWidth[i]))
  902. {
  903. FILE *fp;
  904. if(man_mov_left)
  905. man_x+=6;
  906. if(man_mov_right)
  907. man_x-=6;
  908. if(man_mov_down)
  909. man_y+=6;
  910. if(man_mov_up)
  911. man_y-=6;
  912. if(health>0)
  913. health-=1;
  914. else health=0;
  915. stop_sound=1;
  916. fp=fopen("health.txt","w");
  917. fprintf(fp,"%d",health);
  918. fclose(fp);
  919. }
  920. }
  921.  
  922. void laser_move(int i)
  923. {
  924. if(laserMove[i]==0 && laser_x[i]!=movingLaserRange_x2[i])
  925. {
  926. laser_x[i]+=1;
  927. if(laser_x[i]==movingLaserRange_x2[i])
  928. {
  929. laserMove[i]=1;
  930. }
  931. }
  932. if(laserMove[i]==1 && laser_x[i]!=movingLaserRange_x1[i])
  933. {
  934. laser_x[i]-=1;
  935. if(laser_x[i]==movingLaserRange_x1[i])
  936. {
  937. laserMove[i]=0;
  938. }
  939. }
  940. horizontalLaser(laserLen,i);
  941. health_change(i);
  942.  
  943. if(health>50)
  944. iSetColor(0,255,0);
  945. else if(health>20&&health<40)
  946. iSetColor(255,255,0);
  947. else
  948. iSetColor(255,0,0);
  949. //iFilledRectangle(1200,700,health,6);
  950. }
  951.  
  952. //******************************* ANUP NEW *************************
  953. //void gem_collection(int man_x, int man_y)
  954. //{
  955. // int gem_cou;
  956. // if(man_x>=1000 && man_x<=1000+40 && man_y>=700 && man_y<=700+40)
  957. // gem_collected[gem_cou]=1;
  958. // //if(gem_collected[])
  959. //}
  960.  
  961. void iDraw()
  962. {
  963.  
  964. iClear();
  965.  
  966. // if(leftkbhit)
  967. // {
  968. //
  969. // //NEEDS TO BE FIXED DEPENDING ON BMP
  970. // camx-=20;
  971. // man_x+=20;
  972. // camxLSCount++;
  973. //
  974. //
  975. // if(camxLSCount>20)
  976. // {
  977. // leftkbhit=0;
  978. //
  979. // if(man_x<=850)
  980. // camxLSCount=0;
  981. // }
  982. //
  983. // }
  984. //
  985. // if(rightkbhit)
  986. // {
  987. // //NEEDS TO BE FIXED DEPENDING ON BMP
  988. // camx+=20;
  989. // man_x-=20;
  990. // camxRSCount++;
  991. //
  992. //
  993. // if(camxRSCount>20)
  994. // {
  995. // rightkbhit=0;
  996. //
  997. // if(man_x<450)
  998. // camxRSCount=0;
  999. // }
  1000. //
  1001. // }
  1002.  
  1003.  
  1004.  
  1005.  
  1006. //level=0;
  1007.  
  1008.  
  1009. if(level==0)
  1010. {
  1011. if(bg>=1&&bg<15)
  1012. iShowBMP(0,0,"images\\1.bmp");
  1013. if(bg>=15&&bg<30)
  1014. iShowBMP(0,0,"images\\2.bmp");
  1015. if(bg>=30&&bg<55)
  1016. iShowBMP(0,0,"images\\3.bmp");
  1017. if(bg>=45&&bg<60)
  1018. iShowBMP(0,0,"images\\4.bmp");
  1019.  
  1020. bg++;
  1021. if(bg>=60)
  1022. bg=1;
  1023.  
  1024. // iRectangle(185,382,270,100);
  1025. // iRectangle(185,382-80,295,80);
  1026. // iRectangle(185,382-160,315,80);
  1027. // iRectangle(185,382-240,350,80);
  1028.  
  1029.  
  1030. //if(cont==1)
  1031. //{
  1032. FILE* fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9,*fp10,*fp11, *fp12;
  1033.  
  1034. fp1=fopen("man_x_man_y.txt","r");
  1035. fscanf(fp1,"%d %d",&man_x,&man_y);
  1036. fclose(fp1);
  1037.  
  1038. fp2=fopen("dx_dy.txt","r");
  1039. fscanf(fp2,"%d %d",&dx,&dy);
  1040. fclose(fp2);
  1041.  
  1042.  
  1043. fp3=fopen("horizontal_laser.txt","r");
  1044. fscanf(fp3,"%d %d %d %d",&laser_x[0],&laser_x[1],&laser_x[2],&laser_x[3]);
  1045. fclose(fp3);
  1046.  
  1047.  
  1048. fp4=fopen("vertical_laser.txt","r");
  1049. fprintf(fp4,"%d %d",vertical_laser_y[0],vertical_laser_y[1]);
  1050. fclose(fp4);
  1051.  
  1052.  
  1053. fp5=fopen("bomb1.txt","r");
  1054. fscanf(fp5,"%d %d %d",&bomb_cnt,&bomb_chk,&bomb_tm);
  1055. fclose(fp5);
  1056.  
  1057.  
  1058. fp6=fopen("bomb2.txt","r");
  1059. fscanf(fp6,"%lf %lf %lf %lf %lf %lf",&bomb_x[bomb_cnt-1],&bomb_y[bomb_cnt-1],&bomb_x_change[bomb_cnt-1],&bomb_y_change[bomb_cnt-1],&bomb_initial_x,&bomb_initial_y);
  1060. fclose(fp6);
  1061.  
  1062.  
  1063. fp7=fopen("health.txt","r");
  1064. fscanf(fp7,"%f",&health);
  1065. fclose(fp7);
  1066.  
  1067.  
  1068. fp8=fopen("health_pack1.txt","r");
  1069. fscanf(fp8,"%d %d %d",&hel_pck_num,&health_pack_chk,&hel_tm);
  1070. fclose(fp8);
  1071.  
  1072.  
  1073. fp9=fopen("health_pack_2.txt","r");
  1074. fscanf(fp9,"%lf %lf %d %d",&health_x[hel_pck_num-1],&health_y[hel_pck_num-1],&hel_initial_x,&hel_initial_y);
  1075. fclose(fp9);
  1076.  
  1077. fp10=fopen("timer.txt","r");
  1078. fscanf(fp10,"%f",&timer);
  1079. fclose(fp10);
  1080.  
  1081. fp11=fopen("score.txt","r");
  1082. fscanf(fp11,"%d %d",&current_score,&score_multiplier);
  1083. fclose(fp11);
  1084.  
  1085. fp12=fopen("high score list.txt","r");
  1086. for(int i=0;i<5;i++)
  1087. {
  1088. fscanf(fp12,"%d ",&score_count[i]);
  1089. }
  1090. fclose(fp12);
  1091.  
  1092. FILE *fp13;
  1093. fp13=fopen("bul.txt","r");
  1094. int m;
  1095. for(m=0;m<10;m++){
  1096. fscanf(fp13,"%d %d %lf %lf\n",&bul[m],&test[m],&bul_x[m],&bul_y[m]);
  1097. }
  1098. fclose(fp13);
  1099.  
  1100. FILE *fp14;
  1101. fp14=fopen("camera.txt","r");
  1102. fscanf(fp14,"%f %f",&camx,&camy);
  1103. fclose(fp14);
  1104.  
  1105. //iText(500,500,"Continue");
  1106. cont=0;
  1107.  
  1108.  
  1109. //}
  1110. if(how_to_play==1)
  1111. {
  1112. iShowBMP(0,0,"images\\howto.bmp");
  1113. if(back_from_howto)
  1114. how_to_play=0;
  1115. iRectangle(603,50,180,65);
  1116. //iText(500,500,"how");
  1117. }
  1118. if(new_game==1)
  1119. {
  1120. timer=0;
  1121. new_game=1;
  1122. score_multiplier=1;
  1123. score_count[0]=0;
  1124. score_count[1]=0;
  1125. score_count[2]=0;
  1126. score_count[3]=0;
  1127. score_count[4]=0;
  1128. current_score=0;
  1129. man_x=30, man_y=150;
  1130. health=100;
  1131. sprint=0;
  1132. cont=0;
  1133. level=1;
  1134. man_mov_right=1;
  1135. man_mov_down=0;
  1136. man_mov_left=0;
  1137. man_mov_up=0;
  1138. man_x=10;
  1139. man_y=150;
  1140. dx=3, dy=3;
  1141. sprint=0;
  1142. lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  1143.  
  1144. laserMove[0]=1;
  1145. laserMove[1]=1;
  1146. laserMove[2]=1;
  1147. laserMove[3]=1;
  1148.  
  1149. laser_x[0]=300;
  1150. laser_x[1]=700;
  1151. laser_x[2]=200;
  1152. laser_x[3]=500;
  1153.  
  1154. laser_y[0]=190;
  1155. laser_y[1]=270;
  1156. laser_y[2]=400;
  1157. laser_y[3]=500;
  1158.  
  1159. vertical_laserMove[0]=0;
  1160. vertical_laserMove[1]=1;
  1161.  
  1162.  
  1163. vertical_laser_x[0]=850;
  1164. vertical_laser_x[1]=700;
  1165.  
  1166. vertical_laser_y[0]=600;
  1167. vertical_laser_y[1]=400;
  1168.  
  1169. vertical_laser_count=2;
  1170. health=100;
  1171. // health_x[]={600,300,900},health_y[]={768,768,768};
  1172.  
  1173. health_x[0]=600;
  1174. health_x[1]=300;
  1175. health_x[2]=900;
  1176.  
  1177. health_y[0]=768;
  1178. health_y[1]=768;
  1179. health_y[2]=768;
  1180.  
  1181. hel_tm=0,health_pack_chk=0,hel_pck_num=0;
  1182.  
  1183. health_taken=0;//health_yes
  1184.  
  1185. bomb_x[0]=1336;
  1186. bomb_x[2]=1000;
  1187. bomb_x[2]=300;
  1188. bomb_x[3]=0;
  1189.  
  1190. bomb_y[0]=768;
  1191. bomb_y[1]=768;
  1192. bomb_y[2]=768;
  1193. bomb_y[3]=300;
  1194.  
  1195. bomb_tm=0,bomb_chk=0,bomb_cnt=0;
  1196.  
  1197. test[0]=0,test[1]=9,test[2]=18,test[3]=27,test[4]=36,test[5]=45,test[6]=54,test[7]=63,test[8]=72,test[9]=81;
  1198. int i;
  1199. for(i=0;i<10;i++){
  1200. bul[i]=0;
  1201. }
  1202. camx=0;
  1203. camy=0;
  1204.  
  1205. gem_collected[0]=0;
  1206. gem_collected[1]=0;
  1207. gem_collected[2]=0;
  1208. //iText(500,500,"new");
  1209. level=1;
  1210. new_game=0;
  1211. cont=0;
  1212. }
  1213. if(high_score==1)
  1214. {
  1215. //level=-1;
  1216. iShowBMP(0,0,"images\\highscore.bmp");
  1217. if(back_from_high)
  1218. {
  1219. high_score=0;
  1220. }
  1221. // iRectangle(603,50,180,65);
  1222. }
  1223.  
  1224. // if(cont_rectangle_sweep)
  1225. // {
  1226. // iSetColor(0,0,0);
  1227. // iRectangle(185,375,280,75);
  1228. // }
  1229.  
  1230. }
  1231.  
  1232. man_wid=60,man_height=80;
  1233. //level=1;
  1234. if(level==1)
  1235. {
  1236. //iRectangle(man_x,man_y,man_wid,man_height);
  1237.  
  1238. timer+=.01;
  1239.  
  1240. if(timer>=10)
  1241. score_multiplier=2;
  1242. if(timer>=50)
  1243. score_multiplier=5;
  1244. // if(timer>=10)
  1245. // health=110;
  1246. // takes 36 seconds to reach 0 to 10
  1247.  
  1248. iShowBMP(0,0,"images\\background-game-3.bmp");
  1249.  
  1250. score_show_live();
  1251.  
  1252. int gem_cou;
  1253. if(man_x>=1000-man_wid && man_x<=1000+40 && man_y>=700-man_height && man_y<=700+40) // make it like bomb touch
  1254. gem_collected[0]=1; //show the gem in one corner in small size if taken
  1255. if(!gem_collected[0])
  1256. iShowBMP2(1000,700,"images\\pink-gem.bmp",0xFFFFFF); //this is gem 1
  1257.  
  1258. if(gem_collected[0])
  1259. iText(80,700,"CONGRATULATIONS! You have collected a gem");
  1260. // GEM TEXT
  1261. iSetColor(255, 100, 10);
  1262.  
  1263. iRectangle(man_x,man_y,man_wid,man_height);
  1264. //iRectangle(dead_man_x,dead_man_y,man_wid,man_height);
  1265.  
  1266. if(man_mov_left && sprint%2==0)
  1267. iShowBMP2(man_x,man_y,"images\\left.bmp",0xFFFFFF);
  1268. if(man_mov_left && sprint%2!=0)
  1269. iShowBMP2(man_x,man_y,"images\\leftsprint.bmp",0xFFFFFF);
  1270. if(man_mov_right && sprint%2==0)
  1271. iShowBMP2(man_x,man_y,"images\\right.bmp",0xFFFFFF);
  1272. if(man_mov_right && sprint%2!=0)
  1273. iShowBMP2(man_x,man_y,"images\\rightsprint.bmp",0xFFFFFF);
  1274. if(man_mov_down || man_mov_up)
  1275. iShowBMP2(man_x,man_y,"images\\right.bmp",0xFFFFFF);
  1276.  
  1277. changelasercolor();
  1278. int i;
  1279. //******************************* ANUP NEW *************************
  1280.  
  1281. for(i=0;i<horizontal_laser_count;i++)
  1282. {
  1283. laser_move(i);
  1284. }
  1285.  
  1286.  
  1287. for(i=0;i<enemyNum;i++)
  1288. {
  1289. enemyTouch_health_change(i);
  1290. }
  1291.  
  1292. //******************************* ANUP NEW *************************
  1293.  
  1294. for(i=0;i<vertical_laser_count;i++)
  1295. {
  1296. if(vertical_laserMove[i]==0 && vertical_laser_y[i]>=vertical_movingLaserRange_y1[i])
  1297. {
  1298. vertical_laser_y[i]-=1;
  1299. if(vertical_laser_y[i]==vertical_movingLaserRange_y1[i])
  1300. {
  1301. vertical_laserMove[i]=1;
  1302. }
  1303. }
  1304. if(vertical_laserMove[i]==1 && vertical_laser_y[i]<=vertical_movingLaserRange_y2[i])
  1305. {
  1306. vertical_laser_y[i]+=1;
  1307. if(vertical_laser_y[i]==vertical_movingLaserRange_y2[i])
  1308. {
  1309. vertical_laserMove[i]=0;
  1310. }
  1311. }
  1312. verticalLaser(100,i);
  1313. vertical_health_change(i);
  1314.  
  1315. }
  1316.  
  1317. if(!health_pack_chk)
  1318. {
  1319. hel_tm++;
  1320. if(hel_pck_num==3)
  1321. hel_pck_num=0;
  1322. if(hel_tm%400==0){
  1323. health_pack_chk=1;
  1324. hel_tm=0;
  1325. hel_pck_num++;
  1326. hel_initial_x=health_x[hel_pck_num-1];
  1327. hel_initial_y=health_y[hel_pck_num-1];
  1328. }
  1329. }
  1330. if(health_pack_chk)
  1331. healthPack();
  1332. if(!bomb_chk)
  1333. {
  1334. bomb_tm++;
  1335. if(bomb_cnt==4)
  1336. bomb_cnt=0;
  1337. if(bomb_tm%200==0)
  1338. {
  1339. bomb_chk=1;
  1340. bomb_tm=0;
  1341. bomb_cnt++;
  1342. bomb_initial_x=bomb_x[bomb_cnt-1];
  1343. bomb_initial_y=bomb_y[bomb_cnt-1];
  1344. }
  1345. }
  1346. if(bomb_chk)
  1347. bomb();
  1348.  
  1349. // iSetColor(0,255,0);
  1350. // iFilledRectangle(1200,700,health,4);
  1351. iSetColor(0,255,0);
  1352.  
  1353.  
  1354. if(health==100)
  1355. iText(1200,700-13,"Health = Full");
  1356. else if(health<20 && health!=0)
  1357. iText(1200,700-13,"Health Critical");
  1358. else if(health==0)
  1359. iText(1200,700-13,"Zero Health");
  1360. else
  1361. iText(1200,700-13,"Health");
  1362. //health=0;
  1363. if(!health)
  1364. {
  1365. game_over = 1;
  1366. level_one_sound();
  1367. game_over_sound();
  1368. health = 0.1;
  1369. }
  1370.  
  1371. enemyF();
  1372.  
  1373. //LASER BAR
  1374. iSetColor(255,0,0);
  1375. iText(1200,660, "Laser Power");
  1376. iRectangle(1200,670,100,6);
  1377. iFilledRectangle(1200,670,laserHealth,6);
  1378.  
  1379.  
  1380. //LASER INITIATE CODE
  1381. if(!laserStat) //INDICATES ONE COMPLETE CYCLE OF LASER
  1382. {
  1383. if(laserSwitch) //INDICATES ON/OFF OF LASER
  1384. {
  1385. laser();
  1386. laserTimer++;
  1387. if(laserHealth>0)
  1388. laserHealth-=1; //PRODUCT OF LASERHEALTH AND LASERTIMER IS ALWAYS EQUAL TO 100 - THE SIZE OF THE LASER BAR
  1389.  
  1390. if(laserTimer>100) //INCREASE THIS NUMBER TO INCREASE DURATION OF LASER
  1391. {
  1392. laserStat=1;
  1393. laserTimer=0;
  1394. laserSwitch=0;
  1395. }
  1396.  
  1397. }
  1398.  
  1399. }
  1400. if(health>50)
  1401. iSetColor(0,255,0);
  1402. else if(health>20&&health<=50)
  1403. iSetColor(255,255,0);
  1404. else
  1405. iSetColor(255,0,0);
  1406. iRectangle(1200,700,100,8);
  1407. iFilledRectangle(1200,700,health,8);
  1408.  
  1409. //REFILLING THE LASER
  1410.  
  1411. if(laserStat)
  1412. {
  1413. laserHealth+=5; //CONTROLLING REFILLING OF LASER/REFILL THE LASER
  1414.  
  1415. if(laserHealth>=100)
  1416. laserStat=0;
  1417. }
  1418.  
  1419.  
  1420.  
  1421. //ENEMIES:
  1422. enemy();
  1423. reduceEnemyHealth();
  1424.  
  1425. int m;
  1426. FILE *fp13;
  1427. fp13=fopen("bul.txt","w");
  1428. for(m=0;m<10;m++){
  1429. if(bul[m]==0)
  1430. test[m]++;
  1431. if(test[m]%bul_ctrl==0){
  1432. bul[m]=1;
  1433. test[m]=1;
  1434. bul_x[m]=vertical_laser_x[1];
  1435. //dis[m]=0;
  1436. bul_y[m]=vertical_laser_y[1];
  1437. }
  1438. enemyplane(m);
  1439. fprintf(fp13,"%d %d %lf %lf\n",bul[m],test[m],bul_x[m],bul_y[m]);
  1440. }
  1441. fclose(fp13);
  1442.  
  1443. }
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450. if(game_over)
  1451. {
  1452. // dead_man_y=man_y,dead_man_x=man_x;
  1453. man_x=-1000, man_y=-1000;
  1454. //if(game_over)
  1455. // if(dead_man_y>=10)
  1456. // dead_man_y--;
  1457. // kam baki ase
  1458. // iFilledRectangle(man_x,man_y,30,40),
  1459.  
  1460. iShowBMP2(470,game_over_y,"images\\game_over.bmp",0xFFFFFF);
  1461. if(game_over_y<=280)
  1462. game_over_y+=4;
  1463. if(game_over_y>=280)
  1464. {
  1465. game_end++;
  1466. if(game_end==100){
  1467.  
  1468.  
  1469. man_x=30, man_y=150;
  1470. health=100;
  1471. sprint=0;
  1472. cont=0;
  1473. //level=1;
  1474. high_score=1;
  1475. game_over=0;
  1476. game_over_sound();
  1477. score_page_sound();
  1478.  
  1479.  
  1480. man_x=10;
  1481. man_y=150;
  1482. dx=3, dy=3;
  1483. sprint=0;
  1484. lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  1485.  
  1486. int laserMove[]={1,1,1,1},laser_x[]={300,700,200,500},laser_y[]={190,270,400,500};
  1487.  
  1488. vertical_laserMove[0]=0;
  1489. vertical_laserMove[1]=1;
  1490.  
  1491.  
  1492. vertical_laser_x[0]=850;
  1493. vertical_laser_x[1]=700;
  1494.  
  1495. vertical_laser_y[0]=600;
  1496. vertical_laser_y[1]=400;
  1497.  
  1498. vertical_laser_count=2;
  1499. health=100;
  1500. // health_x[]={600,300,900},health_y[]={768,768,768};
  1501.  
  1502. health_x[0]=600;
  1503. health_x[1]=300;
  1504. health_x[2]=900;
  1505.  
  1506. health_y[0]=768;
  1507. health_y[1]=768;
  1508. health_y[2]=768;
  1509.  
  1510. hel_tm=0,health_pack_chk=0,hel_pck_num=0;
  1511.  
  1512. health_taken=0;//health_yes
  1513.  
  1514. bomb_x[0]=1336;
  1515. bomb_x[2]=1000;
  1516. bomb_x[2]=300;
  1517. bomb_x[3]=0;
  1518.  
  1519. bomb_y[0]=768;
  1520. bomb_y[1]=768;
  1521. bomb_y[2]=768;
  1522. bomb_y[3]=300;
  1523.  
  1524. bomb_tm=0,bomb_chk=0,bomb_cnt=0;
  1525.  
  1526. test[0]=0,test[1]=9,test[2]=18,test[3]=27,test[4]=36,test[5]=45,test[6]=54,test[7]=63,test[8]=72,test[9]=81;
  1527. int i;
  1528. for(i=0;i<10;i++){
  1529. bul[i]=0;
  1530. }
  1531.  
  1532.  
  1533. gem_collected[0]=0;
  1534. gem_collected[1]=0;
  1535. gem_collected[2]=0;
  1536.  
  1537. score_multiplier=1;
  1538. camx=0;
  1539. camy=0;
  1540.  
  1541. level=0; // level=2 indicating the score page
  1542. game_over=0;
  1543. new_game=0;
  1544. cont=0;
  1545. game_end=0;
  1546.  
  1547.  
  1548. }
  1549.  
  1550. }
  1551. }
  1552.  
  1553. FILE * fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9, *fp10,*fp11, *fp12;
  1554. fp1=fopen("man_x_man_y.txt","w");
  1555. fprintf(fp1,"%d %d",man_x,man_y);
  1556. fclose(fp1);
  1557.  
  1558.  
  1559. fp2=fopen("dx_dy.txt","w");
  1560. fprintf(fp2,"%d %d",dx,dy);
  1561. fclose(fp2);
  1562.  
  1563. fp3=fopen("horizontal_laser.txt","w");
  1564. fprintf(fp3,"%d %d %d %d",laser_x[0],laser_x[1],laser_x[2],laser_x[3]);
  1565. fclose(fp3);
  1566.  
  1567.  
  1568. fp4=fopen("vertical_laser.txt","w");
  1569. fprintf(fp4,"%d %d",vertical_laser_y[0],vertical_laser_y[1]);
  1570. fclose(fp4);
  1571.  
  1572.  
  1573. fp5=fopen("bomb1.txt","w");
  1574. fprintf(fp5,"%d %d %d",bomb_cnt,bomb_chk,bomb_tm);
  1575. fclose(fp5);
  1576.  
  1577. fp6=fopen("bomb2.txt","w");
  1578. fprintf(fp6,"%lf %lf %lf %lf %lf %lf",bomb_x[bomb_cnt-1],bomb_y[bomb_cnt-1],bomb_x_change[bomb_cnt-1],bomb_y_change[bomb_cnt-1],bomb_initial_x,bomb_initial_y);
  1579. fclose(fp6);
  1580.  
  1581.  
  1582. fp7=fopen("health.txt","w");
  1583. fprintf(fp7,"%f",health);
  1584. fclose(fp7);
  1585.  
  1586.  
  1587. fp8=fopen("health_pack1.txt","w");
  1588. fprintf(fp8,"%d %d %d",hel_pck_num,health_pack_chk,hel_tm);
  1589. fclose(fp8);
  1590.  
  1591.  
  1592. fp9=fopen("health_pack_2.txt","w");
  1593. fprintf(fp9,"%f %f %f %f",health_x[hel_pck_num-1],health_y[hel_pck_num-1],hel_initial_x,hel_initial_y);
  1594. fclose(fp9);
  1595.  
  1596. fp10=fopen("timer.txt","w");
  1597. fprintf(fp10,"%f",timer);
  1598. fclose(fp10);
  1599.  
  1600. fp11=fopen("score.txt","w");
  1601. fprintf(fp11,"%d %d",current_score,score_multiplier);
  1602. fclose(fp11);
  1603.  
  1604. fp12=fopen("high score list.txt","w");
  1605. for(int i=0;i<5;i++)
  1606. {
  1607. fprintf(fp12,"%d ",score_count[i]);
  1608. }
  1609. fclose(fp12);
  1610.  
  1611. int i,j;
  1612. for(i=0;i<5;i++)
  1613. {
  1614. if(current_score>score_count[i])
  1615. {
  1616. for(j=4;j>i;j--)
  1617. {
  1618. score_count[j]=score_count[j-1];
  1619. }
  1620. score_count[i]=current_score;
  1621. break;
  1622. }
  1623. }
  1624.  
  1625. FILE *fp14;
  1626. fp14=fopen("camera.txt","w");
  1627. fprintf(fp14,"%f %f",camx,camy);
  1628. fclose(fp14);
  1629. // for(i=0;i<5;i++){
  1630. // printf("%d ",score_count[i]);
  1631. // }
  1632.  
  1633. }
  1634. int main()
  1635. {
  1636. menu_sound();
  1637. iSetTimer(50, changeEnemy);
  1638. iSetTimer(100,score);
  1639. // PlaySound((LPCSTR) "C:\\Users\\Public\\Music\\Sample Music\\Sleep Away.mp3", NULL, SND_FILENAME | SND_ASYNC);
  1640. //DWORD dwError = GetLastError();
  1641.  
  1642. //place your own initialization codes here.
  1643. // iSetTimer(5, ballChange);
  1644. //
  1645.  
  1646. iInitialize(1366, 768, "Superman Adventures ver 1.2");
  1647.  
  1648. return 0;
  1649. }
RAW Paste Data