Anupznk

now

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