Anupznk

current

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