Anupznk

current

Sep 4th, 2019
104
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=500;
  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. double score_count[]={0,0,0};
  37. double timer=0;
  38. int score_multiplier=1;
  39. int dead_man_x,dead_man_y;
  40.  
  41. void menu_sound()
  42. {
  43. if(level==0)
  44. PlaySound("music\\menu background.wav", NULL, SND_LOOP | SND_ASYNC);
  45. else
  46. PlaySound(NULL, NULL, SND_ASYNC);
  47.  
  48. }
  49. void pause_menu_sound()
  50. {
  51. if(level==0)
  52. PlaySound("music\\Pause menu.wav", NULL, SND_LOOP | SND_ASYNC);
  53. else
  54. PlaySound(NULL, NULL, SND_ASYNC);
  55.  
  56. }
  57. void score_page_sound()
  58. {
  59. if( high_score)
  60. PlaySound("music\\score.wav", NULL, SND_ASYNC);
  61. else if(high_score==0)
  62. PlaySound(NULL, NULL, SND_ASYNC);
  63.  
  64. }
  65. void level_one_sound()
  66. {
  67. if(level==1 && game_over==0)
  68. PlaySound("music\\game background.wav", NULL, SND_LOOP | SND_ASYNC);
  69. else
  70. PlaySound(NULL, NULL,SND_ASYNC);
  71.  
  72. }
  73.  
  74.  
  75. void game_over_sound()
  76. {
  77. if(game_over)
  78. PlaySound("music\\Game_Over.wav", NULL, SND_ASYNC);
  79. else
  80. PlaySound(NULL, NULL, SND_ASYNC);
  81.  
  82.  
  83. }
  84. void changelasercolor(){
  85.  
  86. if(changecolor==0 && lasercolorR!=255)
  87. {
  88. lasercolorR+=15; // to change color faster
  89. if(lasercolorR==255)
  90. {
  91. changecolor=1;
  92. }
  93. }
  94. if(changecolor==1 && lasercolorR!=0)
  95. {
  96. lasercolorR-=15; // to change color faster
  97. if(lasercolorR==0)
  98. {
  99. changecolor=0;
  100. }
  101. }
  102.  
  103. }
  104.  
  105.  
  106. /*
  107. function iMouseMove() is called when the user presses and drags the mouse.
  108. (mx, my) is the position where the mouse pointer is.
  109. */
  110. void iMouseMove(int mx, int my)
  111. {
  112. //place your codes here
  113. }
  114.  
  115. /*
  116. function iMouse() is called when the user presses/releases the mouse.
  117. (mx, my) is the position where the mouse pointer is.
  118. */
  119. void iMouse(int button, int state, int mx, int my)
  120. {
  121. if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && level!=1)
  122. {
  123. if(mx>=185 && mx<=185+270 && my>=382 && my<=382+100)
  124. {
  125. cont=1;
  126. //cont_chk=1;
  127. new_game=0;
  128. how_to_play=0;
  129. high_score=0;
  130. back_from_howto=0;
  131. back_from_high=0;
  132. //iText(500,500,"Continue");
  133.  
  134. FILE* fpx,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9,*fp10,*fp11;
  135. fpx=fopen("man_x_man_y.txt","r");
  136. fscanf(fpx,"%d %d",&man_x,&man_y);
  137. fclose(fpx);
  138.  
  139. fp2=fopen("dx_dy.txt","r");
  140. fscanf(fp2,"%d %d",&dx,&dy);
  141. fclose(fp2);
  142.  
  143.  
  144. fp3=fopen("horizontal_laser.txt","r");
  145. fscanf(fp3,"%d %d %d %d",&laser_x[0],&laser_x[1],&laser_x[2],&laser_x[3]);
  146. fclose(fp3);
  147.  
  148.  
  149. fp4=fopen("vertical_laser.txt","r");
  150. fscanf(fp4,"%d %d",&vertical_laser_y[0],&vertical_laser_y[1]);
  151. fclose(fp4);
  152.  
  153.  
  154. fp5=fopen("bomb1.txt","r");
  155. fscanf(fp5,"%d %d %d",&bomb_cnt,&bomb_chk,&bomb_tm);
  156. fclose(fp5);
  157.  
  158.  
  159. fp6=fopen("bomb2.txt","r");
  160. 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);
  161. fclose(fp6);
  162.  
  163.  
  164. fp7=fopen("health.txt","r");
  165. fscanf(fp7,"%f",&health);
  166. fclose(fp7);
  167.  
  168.  
  169. fp8=fopen("health_pack1.txt","r");
  170. fscanf(fp8,"%d %d %d",&hel_pck_num,&health_pack_chk,&hel_tm);
  171. fclose(fp8);
  172.  
  173.  
  174. fp9=fopen("health_pack_2.txt","r");
  175. fscanf(fp9,"%lf %lf %d %d",&health_x[hel_pck_num-1],&health_y[hel_pck_num-1],&hel_initial_x,&hel_initial_y);
  176. fclose(fp9);
  177.  
  178.  
  179. fp10=fopen("timer.txt","r");
  180. fscanf(fp10,"%f",&timer);
  181. fclose(fp10);
  182.  
  183. fp11=fopen("score.txt","r");
  184. fscanf(fp11,"%f",&score_count);
  185. fclose(fp11);
  186.  
  187.  
  188. level=1;
  189. menu_sound();
  190. level_one_sound();
  191. }
  192.  
  193. if(mx>=185 && mx<=185+295 && my>=302 && my<=382 && level!=1)
  194. {
  195.  
  196. new_game=1;
  197. double score_count[]={0,0,0};
  198. man_x=30, man_y=150;
  199. health=100;
  200. sprint=0;
  201. cont=0;
  202. level=1;
  203. man_mov_right=1;
  204. man_mov_down=0;
  205. man_mov_left=0;
  206. man_mov_up=0;
  207. man_x=10;
  208. man_y=150;
  209. dx=3, dy=3;
  210. sprint=0;
  211. lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  212.  
  213. laserMove[0]=1;
  214. laserMove[1]=1;
  215. laserMove[2]=1;
  216. laserMove[3]=1;
  217.  
  218. laser_x[0]=300;
  219. laser_x[1]=700;
  220. laser_x[2]=200;
  221. laser_x[3]=500;
  222.  
  223. laser_y[0]=190;
  224. laser_y[1]=270;
  225. laser_y[2]=400;
  226. laser_y[3]=500;
  227.  
  228. vertical_laserMove[0]=0;
  229. vertical_laserMove[1]=1;
  230.  
  231.  
  232. vertical_laser_x[0]=850;
  233. vertical_laser_x[1]=700;
  234.  
  235. vertical_laser_y[0]=600;
  236. vertical_laser_y[1]=400;
  237.  
  238. vertical_laser_count=2;
  239. health=100;
  240. // health_x[]={600,300,900},health_y[]={768,768,768};
  241.  
  242. health_x[0]=600;
  243. health_x[1]=300;
  244. health_x[2]=900;
  245.  
  246. health_y[0]=768;
  247. health_y[1]=768;
  248. health_y[2]=768;
  249.  
  250. hel_tm=0,health_pack_chk=0,hel_pck_num=0;
  251.  
  252. health_taken=0;//health_yes
  253.  
  254. bomb_x[0]=1336;
  255. bomb_x[2]=1000;
  256. bomb_x[2]=300;
  257. bomb_x[3]=0;
  258.  
  259. bomb_y[0]=768;
  260. bomb_y[1]=768;
  261. bomb_y[2]=768;
  262. bomb_y[3]=300;
  263.  
  264. bomb_tm=0,bomb_chk=0,bomb_cnt=0;
  265.  
  266. gem_collected[0]=0;
  267. gem_collected[1]=0;
  268. gem_collected[2]=0;
  269.  
  270. how_to_play=0;
  271. high_score=0;
  272. back_from_howto=0;
  273. back_from_high=0;
  274. level=1;
  275. menu_sound();
  276. level_one_sound();
  277. }
  278.  
  279. if(mx>=185 && mx<=185+315 && my>=222&& my<=222+80 && level!=1)
  280. {
  281. cont=0;
  282. new_game=0;
  283. how_to_play=0;
  284. high_score=1;
  285. // level=-1;
  286. menu_sound();
  287. score_page_sound();
  288.  
  289. back_from_howto=0;
  290. back_from_high=0;
  291. //level=1;
  292. }
  293.  
  294. if(mx>=185 && mx<=185+350 && my>=142 && my<=142+80 && level!=1)
  295.  
  296. {
  297. cont=0;
  298. new_game=0;
  299. how_to_play=1;
  300. high_score=0;
  301. back_from_howto=0;
  302. back_from_high=0;
  303. //level=1;
  304. }
  305. if( how_to_play && mx>=603 && mx<=603+180 && my>=50 && my<=50+65 && level!=1)
  306. {
  307. back_from_howto=1;
  308. back_from_high=0;
  309. }
  310. if( high_score && mx>=603 && mx<=603+180 && my>=50 && my<=50+65 && level!=1)
  311. {
  312. back_from_howto=0;
  313. back_from_high=1;
  314. high_score=0;
  315. score_page_sound();
  316. menu_sound();
  317.  
  318. }
  319. }
  320.  
  321. if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
  322. {
  323. //place your codes here
  324. }
  325. }
  326.  
  327. /*
  328. function iKeyboard() is called whenever the user hits a key in keyboard.
  329. key- holds the ASCII value of the key pressed.
  330. */
  331. void iKeyboard(unsigned char key)
  332. {
  333. if((key=='p'||key=='P') && game_over!=1){
  334. level=0;
  335. game_over=0;
  336. new_game=0;
  337. cont=0;
  338. level_one_sound();
  339. pause_menu_sound();
  340. }
  341.  
  342. }
  343.  
  344. /*
  345. function iSpecialKeyboard() is called whenver user hits special keys like-
  346. function keys, home, end, pg up, pg down, arraows etc. you have to use
  347. appropriate constants to detect them. A list is:
  348. GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
  349. GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11, GLUT_KEY_F12,
  350. GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_DOWN, GLUT_KEY_PAGE UP,
  351. GLUT_KEY_PAGE DOWN, GLUT_KEY_HOME, GLUT_KEY_END, GLUT_KEY_INSERT
  352.  
  353. */
  354. void iSpecialKeyboard(unsigned char key)
  355. {
  356. if(key == GLUT_KEY_DOWN && man_y>=150)
  357. {
  358. dy=3;
  359. if(sprint%2==1)
  360. dy=8;
  361. man_y-=dy;
  362. man_mov_down=1;
  363. man_mov_left=0;
  364. man_mov_right=0;
  365. man_mov_up=0;
  366.  
  367. }
  368. if(key == GLUT_KEY_UP && man_y<=728)
  369. {
  370. dy=3;
  371. if(sprint%2==1)
  372. dy=8;
  373. man_y+=dy;
  374. man_mov_down=0;
  375. man_mov_left=0;
  376. man_mov_right=0;
  377. man_mov_up=1;
  378. }
  379. if(key == GLUT_KEY_RIGHT && man_x<1330)
  380. {
  381. dx=3;
  382. if(sprint%2==1)
  383. dx=8;
  384. man_x+=dx;
  385.  
  386. man_mov_down=0;
  387. man_mov_left=0;
  388. man_mov_right=1;
  389. man_mov_up=0;
  390.  
  391. }
  392. if(key == GLUT_KEY_LEFT && man_x > 10)
  393. {
  394. dx=3;
  395. if(sprint%2==1)
  396. dx=8;
  397. man_x-=dx;
  398.  
  399. man_mov_down=0;
  400. man_mov_left=1;
  401. man_mov_right=0;
  402. man_mov_up=0;
  403.  
  404.  
  405. }
  406.  
  407. if(key== GLUT_KEY_PAGE_DOWN)
  408. {
  409. sprint++;
  410. }
  411.  
  412. // while(key == GLUT_KEY_PAGE_UP)
  413. // {
  414. // }
  415.  
  416. if(key == GLUT_KEY_END)
  417. exit(0);
  418. }
  419. void health_change(int i)
  420. {
  421. if((man_x>=laser_x[i]-man_wid && man_x<=laser_x[i]+100) && (man_y>=laser_y[i]-man_height && man_y<=laser_y[i]+2))
  422. {
  423. FILE *fp;
  424. // fp=fopen("health.txt","r");
  425. // fscanf(fp,"%d",health);
  426. // fclose(fp);
  427. man_x-=2;
  428. man_y+=2;
  429. if(health>0)
  430. health-=1;
  431. stop_sound=1;
  432. fp=fopen("health.txt","w");
  433. fprintf(fp,"%d",health);
  434. fclose(fp);
  435. }
  436.  
  437. }
  438. void vertical_health_change(int i)
  439. {
  440.  
  441. if((man_y>=vertical_laser_y[i]-man_height && man_y<=vertical_laser_y[i]+100) && (man_x>=vertical_laser_x[i]-man_wid && man_x<=vertical_laser_x[i]+3))
  442. {
  443. man_x-=2;
  444. man_y-=2;
  445. if(health>0)
  446. health-=1;
  447. //stop_sound=1;
  448.  
  449. }
  450.  
  451.  
  452. }
  453.  
  454. void horizontalLaser(int laserLen,int i)
  455. {
  456. iSetColor(lasercolorR,255,lasercolorB);
  457. iFilledRectangle(laser_x[i],laser_y[i],laserLen,3);
  458. iSetColor(0,255,0);
  459. iFilledRectangle(laser_x[i]-10,laser_y[i]-3,10,10);
  460.  
  461. iSetColor(0,255,0);
  462. iFilledRectangle(laser_x[i]+100,laser_y[i]-3,10,10);
  463.  
  464. }
  465. void verticalLaser(int laserLen,int i)
  466. {
  467. iSetColor(lasercolorR,255,lasercolorB);
  468. iFilledRectangle(vertical_laser_x[i],vertical_laser_y[i],3,laserLen);
  469. iSetColor(0,255,0);
  470. iFilledRectangle(vertical_laser_x[i]-3,vertical_laser_y[i]-10,10,10);
  471. iSetColor(0,255,0);
  472. iFilledRectangle(vertical_laser_x[i]-3,vertical_laser_y[i]+100,10,10);
  473. }
  474. void healthPack()
  475. {
  476. if(health_pack_chk){
  477. if(hel_pck_num<=3)
  478. {
  479. pack_len=26, pack_wid=22;
  480. iSetColor(211,211,211);
  481. iFilledRectangle(health_x[hel_pck_num-1],health_y[hel_pck_num-1],pack_len,pack_wid);
  482. iSetColor(0,0,0);
  483. iFilledRectangle(health_x[hel_pck_num-1]+(pack_len/2)-2,health_y[hel_pck_num-1]+3,4,pack_wid-6);
  484. iFilledRectangle(health_x[hel_pck_num-1]+3,health_y[hel_pck_num-1]+(pack_wid/2)-2,pack_len-6,4);
  485. if(health_y[hel_pck_num-1]>0)
  486. health_y[hel_pck_num-1]-=.5;
  487. }
  488. if((man_x>=health_x[hel_pck_num-1]-man_wid && man_x<=health_x[hel_pck_num-1]+pack_len) && (man_y>=health_y[hel_pck_num-1]-man_height && man_y<=health_y[hel_pck_num-1]+pack_wid))
  489. {
  490. //health_taken=1;
  491. health_x[hel_pck_num-1]=-10; //making the healthpacks disappear
  492. health_y[hel_pck_num-1]=-10;
  493. if (health>=80)
  494. health=100;
  495. else
  496. health+=20;
  497. health_pack_chk=0;
  498. }
  499. if(health_y[hel_pck_num-1]<=50){
  500. health_pack_chk=0;
  501. health_x[hel_pck_num-1]=hel_initial_x;
  502. health_y[hel_pck_num-1]=hel_initial_y;
  503. }
  504. }
  505.  
  506. }
  507. void bomb()
  508. {
  509.  
  510. if(bomb_chk){
  511. iSetColor(255,0,0);
  512. iFilledCircle(bomb_x[bomb_cnt-1],bomb_y[bomb_cnt-1],bomb_r,100);
  513. bomb_x[bomb_cnt-1]+=bomb_x_change[bomb_cnt-1];
  514. bomb_y[bomb_cnt-1]+=bomb_y_change[bomb_cnt-1];
  515. d[0]=sqrt((man_x-bomb_x[bomb_cnt-1])*(man_x-bomb_x[bomb_cnt-1])+(man_y-bomb_y[bomb_cnt-1])*(man_y-bomb_y[bomb_cnt-1]));
  516. d[1]=sqrt(((man_x+man_wid)-bomb_x[bomb_cnt-1])*((man_x+man_wid)-bomb_x[bomb_cnt-1])+(man_y-bomb_y[bomb_cnt-1])*(man_y-bomb_y[bomb_cnt-1]));
  517. d[2]=sqrt((man_x-bomb_x[bomb_cnt-1])*(man_x-bomb_x[bomb_cnt-1])+((man_y+man_height)-bomb_y[bomb_cnt-1])*((man_y+man_height)-bomb_y[bomb_cnt-1]));
  518. d[3]=sqrt(((man_x+man_wid)-bomb_x[bomb_cnt-1])*((man_x+man_wid)-bomb_x[bomb_cnt-1])+((man_y+man_height)-bomb_y[bomb_cnt-1])*((man_y+man_height)-bomb_y[bomb_cnt-1]));
  519. if(d[0]<=bomb_r||d[1]<=bomb_r||d[2]<=bomb_r||d[3]<=bomb_r){
  520. if(health>2)
  521. health-=2;
  522. else
  523. health=0;
  524. }
  525. if(bomb_y[bomb_cnt-1]<=50||bomb_y[3]>=768){
  526. bomb_chk=0;
  527. bomb_x[bomb_cnt-1]=bomb_initial_x;
  528. bomb_y[bomb_cnt-1]=bomb_initial_y;
  529. }
  530.  
  531. }
  532. // FILE *fp;
  533. // fp=fopen("bomb1.txt","w");
  534. // fprintf(fp,"%d %d %d",bomb_cnt,bomb_chk,bomb_tm);
  535. // fclose(fp);
  536. //
  537. // fp=fopen("bomb2.txt","w");
  538. // fprintf(fp,"%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]);
  539. // fclose(fp);
  540.  
  541. }
  542.  
  543. //void gem_collection(int man_x, int man_y)
  544. //{
  545. // int gem_cou;
  546. // if(man_x>=1000 && man_x<=1000+40 && man_y>=700 && man_y<=700+40)
  547. // gem_collected[gem_cou]=1;
  548. // //if(gem_collected[])
  549. //}
  550.  
  551. void iDraw()
  552. {
  553.  
  554. iClear();
  555. //level=0;
  556. if(level==0)
  557. {
  558. if(bg>=1&&bg<15)
  559. iShowBMP(0,0,"images\\1.bmp");
  560. if(bg>=15&&bg<30)
  561. iShowBMP(0,0,"images\\2.bmp");
  562. if(bg>=30&&bg<55)
  563. iShowBMP(0,0,"images\\3.bmp");
  564. if(bg>=45&&bg<60)
  565. iShowBMP(0,0,"images\\4.bmp");
  566.  
  567. bg++;
  568. if(bg>=60)
  569. bg=1;
  570.  
  571. // iRectangle(185,382,270,100);
  572. // iRectangle(185,382-80,295,80);
  573. // iRectangle(185,382-160,315,80);
  574. // iRectangle(185,382-240,350,80);
  575.  
  576.  
  577. //if(cont==1)
  578. //{
  579. FILE* fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9,*fp10,*fp11;
  580. fp1=fopen("man_x_man_y.txt","r");
  581. fscanf(fp1,"%d %d",&man_x,&man_y);
  582. fclose(fp1);
  583.  
  584. fp2=fopen("dx_dy.txt","r");
  585. fscanf(fp2,"%d %d",&dx,&dy);
  586. fclose(fp2);
  587.  
  588.  
  589. fp3=fopen("horizontal_laser.txt","r");
  590. fscanf(fp3,"%d %d %d %d",&laser_x[0],&laser_x[1],&laser_x[2],&laser_x[3]);
  591. fclose(fp3);
  592.  
  593.  
  594. fp4=fopen("vertical_laser.txt","r");
  595. fscanf(fp4,"%d %d",&vertical_laser_y[0],&vertical_laser_y[1]);
  596. fclose(fp4);
  597.  
  598.  
  599. fp5=fopen("bomb1.txt","r");
  600. fscanf(fp5,"%d %d %d",&bomb_cnt,&bomb_chk,&bomb_tm);
  601. fclose(fp5);
  602.  
  603.  
  604. fp6=fopen("bomb2.txt","r");
  605. 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);
  606. fclose(fp6);
  607.  
  608.  
  609. fp7=fopen("health.txt","r");
  610. fscanf(fp7,"%f",&health);
  611. fclose(fp7);
  612.  
  613.  
  614. fp8=fopen("health_pack1.txt","r");
  615. fscanf(fp8,"%d %d %d",&hel_pck_num,&health_pack_chk,&hel_tm);
  616. fclose(fp8);
  617.  
  618.  
  619. fp9=fopen("health_pack_2.txt","r");
  620. fscanf(fp9,"%lf %lf %d %d",&health_x[hel_pck_num-1],&health_y[hel_pck_num-1],&hel_initial_x,&hel_initial_y);
  621. fclose(fp9);
  622.  
  623.  
  624. fp10=fopen("timer.txt","r");
  625. fscanf(fp10,"%f",&timer);
  626. fclose(fp10);
  627.  
  628. fp11=fopen("score.txt","r");
  629. fscanf(fp11,"%f",&score_count);
  630. fclose(fp11);
  631.  
  632. //iText(500,500,"Continue");
  633. //level=1;
  634. // FILE* fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9;
  635. fp1=fopen("man_x_man_y.txt","r");
  636. fscanf(fp1,"%d %d",&man_x,&man_y);
  637. fclose(fp1);
  638.  
  639. fp2=fopen("dx_dy.txt","r");
  640. fscanf(fp2,"%d %d",&dx,&dy);
  641. fclose(fp2);
  642.  
  643.  
  644. fp3=fopen("horizontal_laser.txt","r");
  645. fscanf(fp3,"%d %d %d %d",&laser_x[0],&laser_x[1],&laser_x[2],&laser_x[3]);
  646. fclose(fp3);
  647.  
  648.  
  649. fp4=fopen("vertical_laser.txt","r");
  650. fprintf(fp4,"%d %d",vertical_laser_y[0],vertical_laser_y[1]);
  651. fclose(fp4);
  652.  
  653.  
  654. fp5=fopen("bomb1.txt","r");
  655. fscanf(fp5,"%d %d %d",&bomb_cnt,&bomb_chk,&bomb_tm);
  656. fclose(fp5);
  657.  
  658.  
  659. fp6=fopen("bomb2.txt","r");
  660. 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);
  661. fclose(fp6);
  662.  
  663.  
  664. fp7=fopen("health.txt","r");
  665. fscanf(fp7,"%f",&health);
  666. fclose(fp7);
  667.  
  668.  
  669. fp8=fopen("health_pack1.txt","r");
  670. fscanf(fp8,"%d %d %d",&hel_pck_num,&health_pack_chk,&hel_tm);
  671. fclose(fp8);
  672.  
  673.  
  674. fp9=fopen("health_pack_2.txt","r");
  675. fscanf(fp9,"%lf %lf %d %d",&health_x[hel_pck_num-1],&health_y[hel_pck_num-1],&hel_initial_x,&hel_initial_y);
  676. fclose(fp9);
  677. //iText(500,500,"Continue");
  678. cont=0;
  679. //}
  680. if(how_to_play==1)
  681. {
  682. iShowBMP(0,0,"images\\howto.bmp");
  683. if(back_from_howto)
  684. how_to_play=0;
  685. iRectangle(603,50,180,65);
  686. //iText(500,500,"how");
  687. }
  688. if(new_game==1)
  689. {
  690. timer=0;
  691. //iText(500,500,"new");
  692. level=1;
  693. new_game=0;
  694. cont=0;
  695. }
  696. if(high_score==1)
  697. {
  698. //level=-1;
  699. iShowBMP(0,0,"images\\highscore.bmp");
  700. if(back_from_high)
  701. {
  702. high_score=0;
  703. }
  704. iRectangle(603,50,180,65);
  705. }
  706.  
  707. }
  708.  
  709. man_wid=60,man_height=80;
  710. //level=1;
  711. if(level==1)
  712. {
  713. //iRectangle(man_x,man_y,man_wid,man_height);
  714.  
  715. timer+=.01;
  716.  
  717. score_count[0]+=0.01*score_multiplier;
  718.  
  719. if(timer>=10)
  720. score_multiplier=2;
  721. if(timer>=50)
  722. score_multiplier=5;
  723. // if(timer>=10)
  724. // health=110;
  725. // takes 36 seconds to reach 0 to 10
  726.  
  727. iShowBMP(0,0,"images\\background-game-3.bmp");
  728. int gem_cou;
  729. if(man_x>=1000-man_wid && man_x<=1000+40 && man_y>=700-man_height && man_y<=700+40) // make it like bomb touch
  730. gem_collected[0]=1; //show the gem in one corner in small size if taken
  731. if(!gem_collected[0])
  732. iShowBMP2(1000,700,"images\\pink-gem.bmp",0xFFFFFF); //this is gem 1
  733.  
  734. if(gem_collected[0])
  735. iText(80,700,"CONGRATULATIONS! You have collected a gem");
  736. iSetColor(255, 100, 10);
  737.  
  738. iRectangle(man_x,man_y,man_wid,man_height);
  739. //iRectangle(dead_man_x,dead_man_y,man_wid,man_height);
  740.  
  741. if(man_mov_left && sprint%2==0)
  742. iShowBMP2(man_x,man_y,"images\\left.bmp",0xFFFFFF);
  743. if(man_mov_left && sprint%2!=0)
  744. iShowBMP2(man_x,man_y,"images\\leftsprint.bmp",0xFFFFFF);
  745. if(man_mov_right && sprint%2==0)
  746. iShowBMP2(man_x,man_y,"images\\right.bmp",0xFFFFFF);
  747. if(man_mov_right && sprint%2!=0)
  748. iShowBMP2(man_x,man_y,"images\\rightsprint.bmp",0xFFFFFF);
  749. if(man_mov_down || man_mov_up)
  750. iShowBMP2(man_x,man_y,"images\\right.bmp",0xFFFFFF);
  751. changelasercolor();
  752. int i;
  753. for(i=0;i<horizontal_laser_count;i++)
  754. {
  755. if(laserMove[i]==0 && laser_x[i]!=movingLaserRange_x2[i])
  756. {
  757. laser_x[i]+=1;
  758. if(laser_x[i]==movingLaserRange_x2[i])
  759. {
  760. laserMove[i]=1;
  761. }
  762. }
  763. if(laserMove[i]==1 && laser_x[i]!=movingLaserRange_x1[i])
  764. {
  765. laser_x[i]-=1;
  766. if(laser_x[i]==movingLaserRange_x1[i])
  767. {
  768. laserMove[i]=0;
  769. }
  770. }
  771. horizontalLaser(laserLen,i);
  772. health_change(i);
  773. if(health>50)
  774. iSetColor(0,255,0);
  775. else if(health>20&&health<40)
  776. iSetColor(255,255,0);
  777. else
  778. iSetColor(255,0,0);
  779. iFilledRectangle(1200,700,health,4);
  780. }
  781.  
  782. for(i=0;i<vertical_laser_count;i++)
  783. {
  784. if(vertical_laserMove[i]==0 && vertical_laser_y[i]>=vertical_movingLaserRange_y1[i])
  785. {
  786. vertical_laser_y[i]-=1;
  787. if(vertical_laser_y[i]==vertical_movingLaserRange_y1[i])
  788. {
  789. vertical_laserMove[i]=1;
  790. }
  791. }
  792. if(vertical_laserMove[i]==1 && vertical_laser_y[i]<=vertical_movingLaserRange_y2[i])
  793. {
  794. vertical_laser_y[i]+=1;
  795. if(vertical_laser_y[i]==vertical_movingLaserRange_y2[i])
  796. {
  797. vertical_laserMove[i]=0;
  798. }
  799. }
  800. verticalLaser(100,i);
  801. vertical_health_change(i);
  802. if(health>50)
  803. iSetColor(0,255,0);
  804. else if(health>20&&health<=50)
  805. iSetColor(255,255,0);
  806. else
  807. iSetColor(255,0,0);
  808. iFilledRectangle(1200,700,health,4);
  809. }
  810.  
  811. if(!health_pack_chk)
  812. {
  813. hel_tm++;
  814. if(hel_pck_num==3)
  815. hel_pck_num=0;
  816. if(hel_tm%400==0){
  817. health_pack_chk=1;
  818. hel_tm=0;
  819. hel_pck_num++;
  820. hel_initial_x=health_x[hel_pck_num-1];
  821. hel_initial_y=health_y[hel_pck_num-1];
  822. }
  823. }
  824. if(health_pack_chk)
  825. healthPack();
  826. if(!bomb_chk)
  827. {
  828. bomb_tm++;
  829. if(bomb_cnt==4)
  830. bomb_cnt=0;
  831. if(bomb_tm%200==0)
  832. {
  833. bomb_chk=1;
  834. bomb_tm=0;
  835. bomb_cnt++;
  836. bomb_initial_x=bomb_x[bomb_cnt-1];
  837. bomb_initial_y=bomb_y[bomb_cnt-1];
  838. }
  839. }
  840. if(bomb_chk)
  841. bomb();
  842.  
  843. // iSetColor(0,255,0);
  844. // iFilledRectangle(1200,700,health,4);
  845. iSetColor(0,255,0);
  846. iRectangle(1200,700,100,4);
  847.  
  848. if(health==100)
  849. iText(1200,700-13,"Health = Full");
  850. else if(health<20 && health!=0)
  851. iText(1200,700-13,"Health Critical");
  852. else if(health==0)
  853. iText(1200,700-13,"Zero Health");
  854. else
  855. iText(1200,700-13,"Health");
  856. //health=0;
  857. if(!health)
  858. {
  859. game_over = 1;
  860. level_one_sound();
  861. game_over_sound();
  862. health = 0.1;
  863. }
  864.  
  865. }
  866. if(game_over)
  867. {
  868. // dead_man_y=man_y,dead_man_x=man_x;
  869. man_x=-1000, man_y=-1000;
  870. //if(game_over)
  871. // if(dead_man_y>=10)
  872. // dead_man_y--;
  873. // kam baki ase
  874. // iFilledRectangle(man_x,man_y,30,40),
  875.  
  876. iShowBMP2(470,game_over_y,"images\\game_over.bmp",0xFFFFFF);
  877. if(game_over_y<=280)
  878. game_over_y+=4;
  879. if(game_over_y>=280)
  880. {
  881. game_end++;
  882. if(game_end==100){
  883.  
  884.  
  885. man_x=30, man_y=150;
  886. health=100;
  887. sprint=0;
  888. cont=0;
  889. //level=1;
  890. high_score=1;
  891. game_over=0;
  892. game_over_sound();
  893. score_page_sound();
  894.  
  895.  
  896. man_x=10;
  897. man_y=150;
  898. dx=3, dy=3;
  899. sprint=0;
  900. lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  901.  
  902. int laserMove[]={1,1,1,1},laser_x[]={300,700,200,500},laser_y[]={190,270,400,500};
  903.  
  904. vertical_laserMove[0]=0;
  905. vertical_laserMove[1]=1;
  906.  
  907.  
  908. vertical_laser_x[0]=850;
  909. vertical_laser_x[1]=700;
  910.  
  911. vertical_laser_y[0]=600;
  912. vertical_laser_y[1]=400;
  913.  
  914. vertical_laser_count=2;
  915. health=100;
  916. // health_x[]={600,300,900},health_y[]={768,768,768};
  917.  
  918. health_x[0]=600;
  919. health_x[1]=300;
  920. health_x[2]=900;
  921.  
  922. health_y[0]=768;
  923. health_y[1]=768;
  924. health_y[2]=768;
  925.  
  926. hel_tm=0,health_pack_chk=0,hel_pck_num=0;
  927.  
  928. health_taken=0;//health_yes
  929.  
  930. bomb_x[0]=1336;
  931. bomb_x[2]=1000;
  932. bomb_x[2]=300;
  933. bomb_x[3]=0;
  934.  
  935. bomb_y[0]=768;
  936. bomb_y[1]=768;
  937. bomb_y[2]=768;
  938. bomb_y[3]=300;
  939.  
  940. bomb_tm=0,bomb_chk=0,bomb_cnt=0;
  941.  
  942. gem_collected[0]=0;
  943. gem_collected[1]=0;
  944. gem_collected[2]=0;
  945.  
  946. level=0; // level=2 indicating the score page
  947. game_over=0;
  948. new_game=0;
  949. cont=0;
  950. game_end=0;
  951.  
  952. }
  953.  
  954. }
  955. }
  956.  
  957. FILE * fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9, *fp10,*fp11;
  958. fp1=fopen("man_x_man_y.txt","w");
  959. fprintf(fp1,"%d %d",man_x,man_y);
  960. fclose(fp1);
  961.  
  962.  
  963. fp2=fopen("dx_dy.txt","w");
  964. fprintf(fp2,"%d %d",dx,dy);
  965. fclose(fp2);
  966.  
  967. fp3=fopen("horizontal_laser.txt","w");
  968. fprintf(fp3,"%d %d %d %d",laser_x[0],laser_x[1],laser_x[2],laser_x[3]);
  969. fclose(fp3);
  970.  
  971.  
  972. fp4=fopen("vertical_laser.txt","w");
  973. fprintf(fp4,"%d %d",vertical_laser_y[0],vertical_laser_y[1]);
  974. fclose(fp4);
  975.  
  976.  
  977. fp5=fopen("bomb1.txt","w");
  978. fprintf(fp5,"%d %d %d",bomb_cnt,bomb_chk,bomb_tm);
  979. fclose(fp5);
  980.  
  981. fp6=fopen("bomb2.txt","w");
  982. 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);
  983. fclose(fp6);
  984.  
  985.  
  986. fp7=fopen("health.txt","w");
  987. fprintf(fp7,"%f",health);
  988. fclose(fp7);
  989.  
  990.  
  991. fp8=fopen("health_pack1.txt","w");
  992. fprintf(fp8,"%d %d %d",hel_pck_num,health_pack_chk,hel_tm);
  993. fclose(fp8);
  994.  
  995.  
  996. fp9=fopen("health_pack_2.txt","w");
  997. fprintf(fp9,"%f %f %f %f",health_x[hel_pck_num-1],health_y[hel_pck_num-1],hel_initial_x,hel_initial_y);
  998. fclose(fp9);
  999.  
  1000. fp10=fopen("timer.txt","w");
  1001. fprintf(fp10,"%f",timer);
  1002. fclose(fp10);
  1003.  
  1004. fp11=fopen("score.txt","w");
  1005. fprintf(fp11,"%f",score_count);
  1006. fclose(fp11);
  1007.  
  1008. }
  1009.  
  1010. int main()
  1011. {
  1012. menu_sound();
  1013.  
  1014. // PlaySound((LPCSTR) "C:\\Users\\Public\\Music\\Sample Music\\Sleep Away.mp3", NULL, SND_FILENAME | SND_ASYNC);
  1015. //DWORD dwError = GetLastError();
  1016.  
  1017. //place your own initialization codes here.
  1018. // iSetTimer(5, ballChange);
  1019. //
  1020.  
  1021. iInitialize(1366, 768, "Superman Adventures ver 1.2");
  1022.  
  1023. return 0;
  1024. }
RAW Paste Data