Advertisement
Erfan7135

Untitled

Sep 12th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 63.50 KB | None | 0 0
  1. # include "iGraphics.h"
  2. # include "gl.h"
  3. # include <Windows.h>
  4. #include<math.h>
  5. #include<stdio.h>
  6.  
  7. typedef struct{
  8. char name[21];
  9. int score;
  10.  
  11. }Leaderboard;
  12.  
  13. Leaderboard HighScore[5];
  14. int leaderboardIndex = 0;
  15.  
  16. int man_x, man_y;
  17. int dx, dy;
  18. int sprint=0;
  19. int lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  20. //int laser_x[]={300,250},laser_y[]={200,150}
  21. int movingLaserRange_x1[]={40,500,100,50},movingLaserRange_x2[]={500,900,600,500},laserMove[]={1,1,1,1},laserLen=100;
  22. int laser_x[]={300,700,200,500},laser_y[]={700,270,400,500};
  23. int horizontal_laser_count=4;
  24. int vertical_movingLaserRange_y1[]={450,500},vertical_movingLaserRange_y2[]={650,700},vertical_laserMove[]={0,1};
  25. int vertical_laser_count=2; // NOW ACTING AS vertical_shooter()
  26. int vertical_laser_x[]={1600,700},vertical_laser_y[]={600,400};
  27. //=============================static vartical laser====================
  28. int static_ver_laser_count=2;
  29. int static_ver_laser_x[]={1500,1800} , static_ver_laser_y[]={600,100};
  30. int static_laserLen=150;
  31.  
  32. int vln=0;//vertical_laser_num
  33. int level=0;
  34. double health=100;
  35. double health_x[]={600,300,900},health_y[]={768,768,768},hel_initial_x,hel_initial_y;
  36. int health_taken=0,pack_len,pack_wid;//,health_yes
  37. int man_wid,man_height;
  38. int man_mov_right=1,man_mov_left=0,man_mov_up=0,man_mov_down=0;
  39. int mouse_clk=0;
  40. int stop_sound=0;
  41. int bg=1;
  42. 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},
  43. bomb_initial_x,bomb_initial_y,bomb_r=8;
  44. double d[5];//for bomb_chk
  45. int hel_tm,health_pack_chk,hel_pck_num;
  46. int bomb_tm,bomb_chk,bomb_cnt;
  47. double bmb_rnge_x,bmb_rnge_y;
  48. int back_from_howto=0,back_from_high=0;
  49. int cont=0,new_game=0,high_score=0,how_to_play=0,cont_chk=1;
  50. int gem_collected[]={0,0,0};
  51. int game_over=0, game_over_y=0,game_end;
  52. double max_score_count=0;
  53. int score_count[]={0,0,0,0,0},current_score=0;
  54. double timer=0;
  55. int score_multiplier=1;
  56. float camx=0, camy=0;
  57. int leftkbhit = 0, rightkbhit = 0, camxLSCount = 0, camxRSCount = 0;
  58. float enemyFX = 1500, enemyFY=600;
  59.  
  60. ////======================== MENU PAGE DECORATION ================================
  61. //int cont_rectangle_sweep=0,newgame_rectangle_sweep=0,high_score_rectangle_sweep=0,how_to_play_rectangle_sweep=0;
  62. //int rec_swap_len=0;
  63.  
  64. //ENEMY VARIABLES:
  65. int enemyNum = 4;
  66. float enemyX[4] = {500, 1100, 1800, 2200}, enemyY[4] = {50,100,150,300};
  67. float enemyHealth[4] = {100,100,100,100};
  68. float enemyWidth[4] = {80,80,80,80};
  69. float enemyHeight[4] = {80,80,80,80};
  70. int enemyHitIndex;
  71. int enemyDamageRate[4] = {2,2,2,2};
  72. int enemyFireIndex[4] ={0};
  73. float enemyFireX[4], enemyFireY[4];
  74. int enemyFireSuppress[4] = {0};
  75. int enemyFireLR[4] = {-1,-1,-1,-1};
  76.  
  77. //VERTICAL ENEMY MOVE VARIABLES BY SUMON:
  78. int enemyRange_y1[]= {200,200,200,200}, enemyRange_y2[]= {750,400,700,600}, enemyMove[]= {1,1,1,1};
  79. float enemydY[] = {1,1,1,2};
  80.  
  81. int kill_count=0;
  82.  
  83. //ENEMY IMAGE VARIABLES
  84. int enemyImageTrack[4]={-5,0,5,10};
  85. int enemyDamageStatus[4] = {0,0,0,0};
  86.  
  87. //SUPERMAN HIT BY FIRE VARIABLES
  88. int manHitToLeft, manHitToRight;
  89. int manLeftDisplacement, manRightDisplacement;
  90.  
  91. //CHARACTER IMAGE VARIABLES
  92. int manMove;
  93. int reset = 11;
  94. int manImageTrack = 0;
  95.  
  96.  
  97. //GAME OVER VARIABLES
  98. int getname = 0;
  99.  
  100.  
  101.  
  102. //******************************* ANUP NEW *************************
  103. int flag=0;
  104. char str[100];
  105. int name_input_len=0;
  106.  
  107.  
  108.  
  109. //******************************* ANUP NEW *************************
  110.  
  111. //LASER VARIABLES:
  112. float laserEnd;
  113. int laserSwitch = 0, laserTimer=0, laserStat = 0;
  114. float laserHealth = 100;
  115. int manLeft = 0, manRight = 1;
  116.  
  117. int world_len_right=2500;
  118.  
  119. int test[]={0,9,18,27,36,45,54,63,72,81},bul[10],bul_ctrl=90;
  120. double bul_x[10],bul_y[10];
  121. double bul_l=10,bul_h=4;
  122. int bul_k=0;
  123. //int dis[10];
  124.  
  125. int reset_curr_score=0;
  126.  
  127. void menu_sound()
  128. {
  129. if(level==0)
  130. PlaySound("music\\menu background.wav", NULL, SND_LOOP | SND_ASYNC);
  131. else
  132. PlaySound(NULL, NULL, SND_ASYNC);
  133.  
  134. }
  135. void pause_menu_sound()
  136. {
  137. if(level==0)
  138. PlaySound("music\\Pause menu.wav", NULL, SND_LOOP | SND_ASYNC);
  139. else
  140. PlaySound(NULL, NULL, SND_ASYNC);
  141.  
  142. }
  143. void score_page_sound()
  144. {
  145. if( high_score)
  146. PlaySound("music\\high score.wav", NULL, SND_ASYNC);
  147. else if(high_score==0)
  148. PlaySound(NULL, NULL, SND_ASYNC);
  149.  
  150. }
  151. void your_score_page_sound()
  152. {
  153. if(level==2)
  154. PlaySound("music\\score clap.wav", NULL, SND_ASYNC);
  155. else
  156. PlaySound(NULL, NULL, SND_ASYNC);
  157.  
  158. }
  159. void level_one_sound()
  160. {
  161. if(level==1 && game_over==0)
  162. PlaySound("music\\game background.wav", NULL, SND_LOOP | SND_ASYNC);
  163. else
  164. PlaySound(NULL, NULL,SND_ASYNC);
  165.  
  166. }
  167.  
  168.  
  169. void game_over_sound()
  170. {
  171. if(game_over)
  172. PlaySound("music\\Game_Over.wav", NULL, SND_ASYNC);
  173. else
  174. PlaySound(NULL, NULL, SND_ASYNC);
  175.  
  176.  
  177. }
  178.  
  179. /*
  180. ********************************** FOLLOWING AND STATIC ENEMY CODE *********************************************************
  181. */
  182.  
  183. void detectMotion()
  184. {
  185. reset++;
  186. }
  187.  
  188.  
  189.  
  190. void renderSuperMan()
  191. {
  192.  
  193. if(!game_over && manHitToLeft)
  194. {
  195. if(manImageTrack<=10 )
  196. iShowBMP2(man_x,man_y,"images\\lefthit1.bmp",0xFFFFFF);
  197. else
  198. iShowBMP2(man_x,man_y,"images\\lefthit2.bmp",0xFFFFFF);
  199.  
  200. if(manImageTrack>20)
  201. manImageTrack=0;
  202.  
  203. }
  204.  
  205. if(!game_over && manHitToRight)
  206. {
  207. if(manImageTrack<=10 )
  208. iShowBMP2(man_x,man_y,"images\\righthit1.bmp",0xFFFFFF);
  209. else
  210. iShowBMP2(man_x,man_y,"images\\righthit2.bmp",0xFFFFFF);
  211.  
  212. if(manImageTrack>20)
  213. manImageTrack=0;
  214. }
  215.  
  216. if(manMove && !game_over && !manHitToLeft && !manHitToRight)
  217. {
  218.  
  219. if(man_mov_left)
  220. {
  221. if(manImageTrack<=10)
  222. iShowBMP2(man_x,man_y,"images\\leftmove.bmp",0xFFFFFF);
  223. else
  224. iShowBMP2(man_x,man_y,"images\\leftmove2.bmp",0xFFFFFF);
  225.  
  226. if(manImageTrack>20)
  227. manImageTrack=0;
  228.  
  229. }
  230.  
  231. if(man_mov_right)
  232. {
  233. if(manImageTrack<=10)
  234. iShowBMP2(man_x-30,man_y,"images\\rightmove.bmp",0xFFFFFF);
  235. else
  236. iShowBMP2(man_x-30,man_y,"images\\rightmove2.bmp",0xFFFFFF);
  237.  
  238. if(manImageTrack>20)
  239. manImageTrack=0;
  240. }
  241.  
  242. if(man_mov_down && manLeft)
  243. {
  244. if(manImageTrack<=10)
  245. iShowBMP2(man_x,man_y,"images\\downleft.bmp",0xFFFFFF);
  246. else
  247. iShowBMP2(man_x,man_y,"images\\downleft2.bmp",0xFFFFFF);
  248.  
  249. if(manImageTrack>20)
  250. manImageTrack=0;
  251. }
  252.  
  253. if(man_mov_up && manLeft)
  254. {
  255. if(manImageTrack<=10)
  256. iShowBMP2(man_x,man_y,"images\\upleft.bmp",0xFFFFFF);
  257. else
  258. iShowBMP2(man_x,man_y,"images\\upleft2.bmp",0xFFFFFF);
  259.  
  260. if(manImageTrack>20)
  261. manImageTrack=0;
  262. }
  263.  
  264.  
  265. if(man_mov_down && manRight)
  266. {
  267. if(manImageTrack<=10)
  268. iShowBMP2(man_x,man_y,"images\\downright.bmp",0xFFFFFF);
  269. else
  270. iShowBMP2(man_x,man_y,"images\\downright2.bmp",0xFFFFFF);
  271.  
  272. if(manImageTrack>20)
  273. manImageTrack=0;
  274. }
  275.  
  276. if(man_mov_up && manRight)
  277. {
  278. if(manImageTrack<=10)
  279. iShowBMP2(man_x,man_y,"images\\upright.bmp",0xFFFFFF);
  280. else
  281. iShowBMP2(man_x,man_y,"images\\upright2.bmp",0xFFFFFF);
  282.  
  283. if(manImageTrack>20)
  284. manImageTrack=0;
  285. }
  286.  
  287. }
  288.  
  289. else if(!game_over)
  290. {
  291. if(manLeft && !manHitToLeft && !manHitToRight)
  292. iShowBMP2(man_x,man_y,"images\\left.bmp",0xFFFFFF);
  293. if(manRight && !manHitToLeft && !manHitToRight)
  294. iShowBMP2(man_x,man_y,"images\\right.bmp",0xFFFFFF);
  295. }
  296.  
  297.  
  298. }
  299.  
  300. void reduceManHealth()
  301. {
  302. for(int i=0; i<enemyNum; i++)
  303. {
  304. if(enemyFireX[i]-camx-man_x<50 && enemyFireX[i]-camx-man_x>0 && enemyFireY[i]-man_y<80 && enemyFireY[i]-man_y>0)
  305. {
  306. health-=1;
  307.  
  308. if(enemyFireLR[i]==0)
  309. {
  310. if(manHitToLeft!=1)
  311. manHitToLeft=1;
  312. }
  313.  
  314. if(enemyFireLR[i]==1)
  315. {
  316. if(manHitToRight!=1)
  317. manHitToRight=1;
  318. }
  319.  
  320. }
  321.  
  322. }
  323. }
  324.  
  325. void enemy()
  326. {
  327. iSetColor(0,0,255);
  328. for(int i = 0; i<enemyNum; i++)
  329. {
  330. if(enemyHealth[i]>0.1)
  331.  
  332. {
  333. if(man_x<enemyX[i]-camx)
  334. {
  335.  
  336. if(enemyDamageStatus[i]==0)
  337. {
  338. if(enemyImageTrack[i]<=10)
  339. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyleft1.bmp",0xFFFFFF);
  340. else if(enemyImageTrack[i]<=20)
  341. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyleft2.bmp",0xFFFFFF);
  342. else if(enemyImageTrack[i]<=30)
  343. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyleft3.bmp",0xFFFFFF);
  344. else
  345. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyleft2.bmp",0xFFFFFF);
  346.  
  347. if(enemyImageTrack[i]>40)
  348. enemyImageTrack[i]=0;
  349.  
  350. }
  351.  
  352. else if(enemyDamageStatus[i]==1)
  353. {
  354. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyhitleft.bmp",0xFFFFFF);
  355. }
  356.  
  357. }
  358.  
  359. else
  360. {
  361. if(!enemyDamageStatus[i])
  362. {
  363. if(enemyImageTrack[i]<=10)
  364. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyright1.bmp",0xFFFFFF);
  365. else if(enemyImageTrack[i]<=20)
  366. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyright2.bmp",0xFFFFFF);
  367. else if(enemyImageTrack[i]<=30)
  368. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyright3.bmp",0xFFFFFF);
  369. else
  370. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyright2.bmp",0xFFFFFF);
  371.  
  372. if(enemyImageTrack[i]>40)
  373. enemyImageTrack[i]=0;
  374. }
  375.  
  376. else
  377. {
  378. iShowBMP2(enemyX[i]-camx,enemyY[i]-camy,"images\\enemyhitright.bmp",0xFFFFFF);
  379. }
  380.  
  381. }
  382. }
  383. //iRectangle((enemyX[i]-camx), (enemyY[i]-camy), enemyWidth[i], enemyHeight[i]);
  384.  
  385.  
  386. }
  387.  
  388. }
  389.  
  390. void changeEnemyY()
  391. {
  392. for(int i=0; i<enemyNum; i++)
  393. {
  394. if(enemyMove[i]==0 && enemyY[i]>=enemyRange_y1[i])
  395. {
  396. enemyY[i]-=enemydY[i];
  397. if(enemyY[i]==enemyRange_y1[i])
  398. {
  399. enemyMove[i]=1;
  400. }
  401. }
  402.  
  403. if(enemyMove[i]==1 && enemyY[i]<=enemyRange_y2[i])
  404. {
  405. enemyY[i]+=enemydY[i];
  406. if(enemyY[i]==enemyRange_y2[i])
  407. {
  408. enemyMove[i]=0;
  409. }
  410. }
  411.  
  412. }
  413.  
  414. }
  415.  
  416. void enemyFire()
  417. {
  418. for(int i=0; i<enemyNum; i++)
  419. {
  420. if(enemyX[i]-camx<1366 && enemyX[i]-camx > 0 && enemyHealth[i]>0.01)
  421. {
  422. if(abs(enemyY[i]-man_y)<20 && !enemyFireSuppress[i])
  423. {
  424. enemyFireIndex[i]=1;
  425.  
  426. }
  427. }
  428. }
  429. }
  430.  
  431. void enemyFireControl()
  432. {
  433. for(int i=0; i<enemyNum; i++)
  434. {
  435. if(enemyFireIndex[i])
  436. {
  437. enemyFireSuppress[i] = 1;
  438.  
  439. if(man_x<enemyX[i]-camx)
  440. {
  441. enemyFireX[i]=enemyX[i];
  442. enemyFireY[i]=enemyY[i]+50;
  443. }
  444.  
  445. else
  446. {
  447. enemyFireX[i]=enemyX[i]+50;
  448. enemyFireY[i]=enemyY[i]+50;
  449. }
  450.  
  451. enemyFireIndex[i]=0;
  452. }
  453. }
  454. }
  455.  
  456. void enemyFireChange()
  457. {
  458. for(int i=0; i<enemyNum; i++)
  459. {
  460. if(man_x<enemyX[i]-camx)
  461. {
  462. if(enemyFireLR[i]==-1)
  463. enemyFireLR[i]=0; //something which will stay put until suppression is 0. ebong ami eta ke hatabo na until it has gone to the left
  464. //enemyFireX[i]-=5; //controls speed of fire
  465. }
  466.  
  467. else
  468. {
  469. if(enemyFireLR[i]==-1)
  470. enemyFireLR[i]=1;
  471. //enemyFireX[i]+=5; //controls speed of fire
  472.  
  473. }
  474.  
  475.  
  476. if(enemyFireX[i]-camx<-30 || enemyFireX[i]-camx>1396)
  477. {
  478. enemyFireSuppress[i]=0;
  479. enemyFireLR[i]=-1;
  480. }
  481.  
  482. }
  483.  
  484. }
  485.  
  486. void drawEnemyFire()
  487. {
  488. for(int i=0; i<enemyNum; i++)
  489. {
  490. if(enemyFireLR[i]==0)
  491. enemyFireX[i]-=10;
  492. else if(enemyFireLR[i]==1)
  493. enemyFireX[i]+=10;
  494. }
  495. }
  496.  
  497.  
  498.  
  499.  
  500.  
  501. float laserEndDetect(float laserX, float laserY) //FUNCTION TO DETECT THE ENDING POINT OF A LASER
  502. {
  503. float matchX[100]; //KEEPS RECORD OF ALL X'S WHICH MATCH THE REQUIREMENTS
  504. int c=0; //KEEPS TRACK OF THE NUMBER OF ELEMENTS IN ARRAY AKA THE NUMBER OF MATCHES+1 (REASON BELOW)
  505.  
  506. if(manRight)
  507. {
  508. for(int i=0; i<enemyNum; i++)
  509. {
  510.  
  511. if(laserY-(enemyY[i]-camy)>0 && laserY-(enemyY[i]-camy)<enemyHeight[i] && laserX<(enemyX[i]-camx) && enemyHealth[i]>0.01)
  512. {
  513. //POPULATING THE ARRAY
  514. matchX[c] = (enemyX[i]-camx);
  515.  
  516. c++; //CAUSES C TO ALWAYS BE LARGER BY 1
  517.  
  518.  
  519. }
  520. }
  521.  
  522. if(!c)//IF THERE ARE NO MATCHES
  523. {
  524. enemyHitIndex = -1;
  525. return 1366; //INFINITE LASER
  526. }
  527.  
  528.  
  529. else
  530. {
  531. //finding the minimum
  532.  
  533. float minX = matchX[0];
  534. for(int i = 0; i<c; i++)
  535. {
  536. if(matchX[i]<minX)
  537. minX = matchX[i];
  538.  
  539. }
  540.  
  541. for(int i=0; i<enemyNum; i++)
  542. {
  543. if(minX == (enemyX[i]-camx))
  544. enemyHitIndex = i;
  545. }
  546.  
  547. return minX;
  548. }
  549. }
  550.  
  551. if(manLeft)
  552. {
  553. for(int i=0; i<enemyNum; i++)
  554. {
  555.  
  556. if(laserY-(enemyY[i]-camy)>0 && laserY-(enemyY[i]-camy)<enemyHeight[i] && laserX>(enemyX[i]-camx) && enemyHealth[i]>0.01)
  557. {
  558. //POPULATING THE ARRAY
  559. matchX[c] = (enemyX[i]-camx);
  560. c++; //CAUSES C TO ALWAYS BE LARGER BY 1
  561.  
  562.  
  563. }
  564. }
  565.  
  566. if(!c)//IF THERE ARE NO MATCHES
  567. {
  568. enemyHitIndex = -1;
  569. return 0; //INFINITE LASER
  570. }
  571.  
  572.  
  573. else
  574. {
  575. //finding the minimum
  576.  
  577. float minX = matchX[0];
  578. for(int i = 0; i<c; i++)
  579. {
  580. if(matchX[i]<minX)
  581. minX = matchX[i];
  582.  
  583. }
  584.  
  585. for(int i=0; i<enemyNum; i++)
  586. {
  587. if(minX == (enemyX[i]-camx))
  588. enemyHitIndex = i;
  589. }
  590.  
  591. return minX+enemyWidth[enemyHitIndex];
  592. }
  593. }
  594. }
  595.  
  596. int reduceEnemyHealth() //FUNCTION TO REDUCE ENEMY HEALTH TO 0
  597. {
  598. for(int i=0; i<enemyNum; i++)
  599. enemyDamageStatus[i]=0;
  600.  
  601. if(laserSwitch == 1 && enemyHitIndex != -1)
  602. {
  603. if(enemyHealth[enemyHitIndex]>=0)
  604. {
  605. enemyDamageStatus[enemyHitIndex] = 1;
  606. enemyHealth[enemyHitIndex]-=enemyDamageRate[enemyHitIndex]; //ADJUST TO REDUCE DAMAGE RATE
  607.  
  608. }
  609. }
  610.  
  611. return 1;
  612. }
  613.  
  614. void laser()
  615. {
  616.  
  617. if(manRight && !game_over)
  618. {
  619. float laserX = man_x+70;
  620. float laserY = man_y+80;
  621.  
  622. iSetColor(255,0,0);
  623. iLine(laserX-15, laserY+2, laserEndDetect(laserX, laserY)+25, laserY+2);
  624. iSetColor(255,0,0);
  625. iLine(laserX-15, laserY+1, laserEndDetect(laserX, laserY)+25, laserY+1);
  626. iSetColor(255,255,0);
  627. iLine(laserX-15, laserY, laserEndDetect(laserX, laserY)+25, laserY);
  628. iSetColor(255,0,0);
  629. iLine(laserX-15, laserY-1, laserEndDetect(laserX, laserY)+25, laserY-1);
  630. iSetColor(255,0,0);
  631. iLine(laserX-15, laserY-2, laserEndDetect(laserX, laserY)+25, laserY-2);
  632.  
  633. }
  634.  
  635. if(manLeft && !game_over)
  636. {
  637. float laserX = man_x;
  638. float laserY = man_y+80;
  639.  
  640. iSetColor(255,0,0);
  641. iLine(laserX, laserY+2, laserEndDetect(laserX, laserY), laserY+2);
  642. iSetColor(255,0,0);
  643. iLine(laserX, laserY+1, laserEndDetect(laserX, laserY), laserY+1);
  644. iSetColor(255,255,0);
  645. iLine(laserX, laserY, laserEndDetect(laserX, laserY), laserY);
  646. iSetColor(255,0,0);
  647. iLine(laserX, laserY-1, laserEndDetect(laserX, laserY), laserY-1);
  648. iSetColor(255,0,0);
  649. iLine(laserX, laserY-2, laserEndDetect(laserX, laserY), laserY-2);
  650. }
  651.  
  652. }
  653.  
  654.  
  655.  
  656. void enemyF()
  657. {
  658. iSetColor(0,0,0);
  659. iRectangle(enemyFX-camx, enemyFY-camy, 10, 10);
  660. }
  661.  
  662. void changeEnemy()
  663. {
  664.  
  665. if((enemyFX-camx<man_x+200)&&(enemyFX-camx>man_x-100) && (enemyFY-camy<man_y+200) && (enemyFY-camy>man_y-100))
  666. return;
  667.  
  668.  
  669. if(enemyFX-camx-man_x>10 || man_x-enemyFX+camx>10)
  670. {
  671. if(enemyFX-camx>man_x)
  672. enemyFX-=10;
  673. else
  674. enemyFX+=10;
  675.  
  676. if(enemyFY-camy>man_y)
  677. {
  678. enemyFY-=10*((enemyFY-man_y)/abs(enemyFX-man_x));
  679. }
  680.  
  681. else if(enemyFY-camy<man_y)
  682. {
  683. enemyFY+=10*((man_y-(enemyFY-camy))/abs(enemyFX-camx-man_x));
  684. }
  685.  
  686. }
  687.  
  688.  
  689.  
  690. }
  691. void changelasercolor(){
  692.  
  693. if(changecolor==0 && lasercolorR!=255)
  694. {
  695. lasercolorR+=15; // to change color faster
  696. if(lasercolorR==255)
  697. {
  698. changecolor=1;
  699. }
  700. }
  701. if(changecolor==1 && lasercolorR!=0)
  702. {
  703. lasercolorR-=15; // to change color faster
  704. if(lasercolorR==0)
  705. {
  706. changecolor=0;
  707. }
  708. }
  709.  
  710. }
  711.  
  712.  
  713. /*
  714. function iMouseMove() is called when the user presses and drags the mouse.
  715. (mx, my) is the position where the mouse pointer is.
  716. */
  717. void iMouseMove(int mx, int my)
  718. {
  719. //place your codes here
  720. }
  721.  
  722. /*
  723. function iMouse() is called when the user presses/releases the mouse.
  724. (mx, my) is the position where the mouse pointer is.
  725. */
  726. void iMouse(int button, int state, int mx, int my)
  727. {
  728. if(button == GLUT_LEFT_BUTTON && state == GLUT_UP && level!=1)
  729. {
  730. if(mx>=185 && mx<=185+270 && my>=382 && my<=382+100)
  731. {
  732. cont=1;
  733. //cont_chk=1;
  734. new_game=0;
  735. how_to_play=0;
  736. high_score=0;
  737. back_from_howto=0;
  738. back_from_high=0;
  739. //iText(500,500,"Continue");
  740.  
  741. // FILE* fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9,*fp10,*fp11, *fp12;
  742. // fp1=fopen("man_x_man_y.txt","r");
  743. // fscanf(fp1,"%d %d",&man_x,&man_y);
  744. // fclose(fp1);
  745. //
  746. // fp2=fopen("dx_dy.txt","r");
  747. // fscanf(fp2,"%d %d",&dx,&dy);
  748. // fclose(fp2);
  749. //
  750. //
  751. // fp3=fopen("horizontal_laser.txt","r");
  752. // fscanf(fp3,"%d %d %d %d",&laser_x[0],&laser_x[1],&laser_x[2],&laser_x[3]);
  753. // fclose(fp3);
  754. //
  755. //
  756. // fp4=fopen("vertical_laser.txt","r");
  757. // fscanf(fp4,"%d %d",&vertical_laser_y[0],&vertical_laser_y[1]);
  758. // fclose(fp4);
  759. //
  760. //
  761. // fp5=fopen("bomb1.txt","r");
  762. // fscanf(fp5,"%d %d %d",&bomb_cnt,&bomb_chk,&bomb_tm);
  763. // fclose(fp5);
  764. //
  765. //
  766. // fp6=fopen("bomb2.txt","r");
  767. // 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);
  768. // fclose(fp6);
  769. //
  770. //
  771. // fp7=fopen("health.txt","r");
  772. // fscanf(fp7,"%f",&health);
  773. // fclose(fp7);
  774. //
  775. //
  776. // fp8=fopen("health_pack1.txt","r");
  777. // fscanf(fp8,"%d %d %d",&hel_pck_num,&health_pack_chk,&hel_tm);
  778. // fclose(fp8);
  779. //
  780. //
  781. // fp9=fopen("health_pack_2.txt","r");
  782. // fscanf(fp9,"%lf %lf %d %d",&health_x[hel_pck_num-1],&health_y[hel_pck_num-1],&hel_initial_x,&hel_initial_y);
  783. // fclose(fp9);
  784. //
  785. //
  786. // fp10=fopen("timer.txt","r");
  787. // fscanf(fp10,"%f",&timer);
  788. // fclose(fp10);
  789. //
  790. // fp11=fopen("score.txt","r");
  791. // fscanf(fp11,"%f",&score_count);
  792. // fclose(fp11);
  793. //
  794. // fp12=fopen("high score list.txt","r");
  795. // for(int i=0;i<5;i++)
  796. // {
  797. // fscanf(fp12,"%d ",&score_count[i]);
  798. // }
  799. // fclose(fp12);
  800. if(reset_curr_score )
  801. {
  802. current_score=0;
  803. score_multiplier=1;
  804. kill_count=0;
  805. }
  806. reset_curr_score=0;
  807. level=1;
  808. menu_sound();
  809. level_one_sound();
  810. }
  811.  
  812. if(mx>=185 && mx<=185+295 && my>=302 && my<=382 && level!=1)
  813. {
  814.  
  815. new_game=1;
  816. camx=0,camy=0;
  817. score_multiplier=1;
  818. score_count[0]=0;
  819. score_count[1]=0;
  820. score_count[2]=0;
  821. score_count[3]=0;
  822. score_count[4]=0;
  823. current_score=0;
  824. health=100;
  825. sprint=0;
  826. cont=0;
  827. level=1;
  828. man_mov_right=1;
  829. man_mov_down=0;
  830. man_mov_left=0;
  831. man_mov_up=0;
  832. man_x=80;
  833. man_y=150;
  834. dx=3, dy=3;
  835. sprint=0;
  836. lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  837.  
  838. laserMove[0]=1;
  839. laserMove[1]=1;
  840. laserMove[2]=1;
  841. laserMove[3]=1;
  842.  
  843. laser_x[0]=300;
  844. laser_x[1]=700;
  845. laser_x[2]=200;
  846. laser_x[3]=500;
  847.  
  848. // laser_y[0]=100;
  849. // laser_y[1]=270;
  850. // laser_y[2]=400;
  851. // laser_y[3]=500;
  852.  
  853. vertical_laserMove[0]=0;
  854. vertical_laserMove[1]=1;
  855.  
  856.  
  857. // vertical_laser_x[0]=1500;
  858. // vertical_laser_x[1]=700;
  859.  
  860. vertical_laser_y[0]=600;
  861. vertical_laser_y[1]=400;
  862.  
  863. vertical_laser_count=2;
  864. health=100;
  865. // health_x[]={600,300,900},health_y[]={768,768,768};
  866.  
  867. health_x[0]=600;
  868. health_x[1]=300;
  869. health_x[2]=900;
  870.  
  871. health_y[0]=768;
  872. health_y[1]=768;
  873. health_y[2]=768;
  874.  
  875. hel_tm=0,health_pack_chk=0,hel_pck_num=0;
  876.  
  877. health_taken=0;//health_yes
  878.  
  879. bomb_x[0]=1336;
  880. bomb_x[2]=1000;
  881. bomb_x[2]=300;
  882. bomb_x[3]=0;
  883.  
  884. bomb_y[0]=768;
  885. bomb_y[1]=768;
  886. bomb_y[2]=768;
  887. bomb_y[3]=300;
  888.  
  889. bomb_tm=0,bomb_chk=0,bomb_cnt=0;
  890.  
  891. bmb_rnge_x=0;
  892. bmb_rnge_y=0;
  893.  
  894. 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;
  895. int i;
  896. for(i=0;i<10;i++){
  897. bul[i]=0;
  898. }
  899. vln=0;
  900. bul_k=0;
  901.  
  902.  
  903. gem_collected[0]=0;
  904. gem_collected[1]=0;
  905. gem_collected[2]=0;
  906.  
  907. enemyY[0]=50;
  908. enemyY[1]=100;
  909. enemyY[2]=150;
  910. enemyY[3]=300;
  911.  
  912. enemyHealth[0]=100;
  913. enemyHealth[1]=100;
  914. enemyHealth[2]=100;
  915. enemyHealth[3]=100;
  916.  
  917. how_to_play=0;
  918. high_score=0;
  919. back_from_howto=0;
  920. back_from_high=0;
  921. level=1;
  922. menu_sound();
  923. level_one_sound();
  924. }
  925.  
  926. if(mx>=185 && mx<=185+315 && my>=222&& my<=222+80 && level!=1)
  927. {
  928. cont=0;
  929. new_game=0;
  930. how_to_play=0;
  931. high_score=1;
  932. // level=-1;
  933. menu_sound();
  934. score_page_sound();
  935.  
  936. back_from_howto=0;
  937. back_from_high=0;
  938. //level=1;
  939. }
  940.  
  941. if(mx>=185 && mx<=185+350 && my>=142 && my<=142+80 && level!=1)
  942.  
  943. {
  944. cont=0;
  945. new_game=0;
  946. how_to_play=1;
  947. high_score=0;
  948. back_from_howto=0;
  949. back_from_high=0;
  950. //level=1;
  951. }
  952. if( how_to_play && mx>=603 && mx<=603+180 && my>=50 && my<=50+65 && level!=1)
  953. {
  954. back_from_howto=1;
  955. back_from_high=0;
  956. }
  957. if( high_score && mx>=603 && mx<=603+180 && my>=50 && my<=50+65 && level!=1)
  958. {
  959. back_from_howto=0;
  960. back_from_high=1;
  961. high_score=0;
  962. score_page_sound();
  963. menu_sound();
  964.  
  965. }
  966. }
  967.  
  968. if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
  969. {
  970. // printf("x=%d y=%d\n",mx,my);
  971. if((mx>=417 && mx<=417+420 && my>=382 && my<=382+50) ) // && level==2
  972. {
  973. // flag==1;
  974. }
  975. }
  976. }
  977.  
  978. /*
  979. function iKeyboard() is called whenever the user hits a key in keyboard.
  980. key- holds the ASCII value of the key pressed.
  981. */
  982. void iKeyboard(unsigned char key)
  983. {
  984.  
  985. if(level==2 && getname)
  986. {
  987. if(key==8)
  988. {
  989. if(name_input_len)
  990. {
  991. str[name_input_len-1]='\0';
  992. name_input_len--;
  993. if(name_input_len<0)
  994. name_input_len=0;
  995. }
  996. else
  997. name_input_len=0;
  998. }
  999. else if((key>=48 && key<=57) || (key>=65 && key<=90) || (key>=97 && key<=122))
  1000. {
  1001. str[name_input_len]=key;
  1002. //name_input_len++;
  1003. str[++name_input_len]='\0';
  1004. }
  1005. }
  1006. if(name_input_len>20)
  1007. name_input_len=20;
  1008. if((key==27) && game_over!=1){
  1009. level=0;
  1010. game_over=0;
  1011. new_game=0;
  1012. cont=0;
  1013. level_one_sound();
  1014. pause_menu_sound();
  1015. }
  1016. if(key == 13 && level==2)
  1017. {
  1018. // ******************************************************
  1019. // EKHANE STRING TA FILE E NITE HOBE MUST
  1020.  
  1021.  
  1022. //name_input_len=1;
  1023. if(getname){
  1024. if(strlen(str)!=0)strcpy(HighScore[leaderboardIndex].name, str);
  1025. for(int i=name_input_len;i>=0;i--){
  1026. str[i]=0;
  1027. }
  1028.  
  1029. FILE* fp21 = fopen("high score.txt", "w");
  1030.  
  1031. for(int i=0; i<5; i++)
  1032. {
  1033. fprintf(fp21, "%s %d\n", HighScore[i].name, HighScore[i].score);
  1034. }
  1035.  
  1036. fclose(fp21);
  1037. current_score=0;
  1038. score_multiplier=1;
  1039.  
  1040. str[0]='\0';
  1041. name_input_len=0;
  1042. getname=0;
  1043. }
  1044.  
  1045. if(level==2)
  1046. reset_curr_score=1;
  1047.  
  1048. level=0;
  1049. your_score_page_sound();
  1050. menu_sound();
  1051. }
  1052.  
  1053. if((key == 'e' || key=='E') && !laserStat && level==1 && !manMove)
  1054. {
  1055. laserSwitch = 1;
  1056. }
  1057. if(key=='k')
  1058. health=0;
  1059.  
  1060. }
  1061.  
  1062. /*
  1063. function iSpecialKeyboard() is called whenver user hits special keys like-
  1064. function keys, home, end, pg up, pg down, arraows etc. you have to use
  1065. appropriate constants to detect them. A list is:
  1066. GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
  1067. GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11, GLUT_KEY_F12,
  1068. GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_DOWN, GLUT_KEY_PAGE UP,
  1069. GLUT_KEY_PAGE DOWN, GLUT_KEY_HOME, GLUT_KEY_END, GLUT_KEY_INSERT
  1070.  
  1071. */
  1072. void iSpecialKeyboard(unsigned char key)
  1073. {
  1074. if(key == GLUT_KEY_DOWN)
  1075. {
  1076. reset = 0;
  1077. dy=3;
  1078. if(sprint%2==1)
  1079. dy=8;
  1080.  
  1081. if(man_y>10)
  1082. man_y-=dy;
  1083.  
  1084.  
  1085. man_mov_down=1;
  1086. man_mov_left=0;
  1087. man_mov_right=0;
  1088. man_mov_up=0;
  1089.  
  1090. }
  1091. if(key == GLUT_KEY_UP)
  1092. {
  1093. reset = 0;
  1094. dy=3;
  1095. if(sprint%2==1)
  1096. dy=8;
  1097.  
  1098. if(man_y<700)
  1099. man_y+=dy;
  1100.  
  1101. // else if(camy<500)
  1102. // {
  1103. // camy+=dy;
  1104. // }
  1105.  
  1106. man_mov_down=0;
  1107. man_mov_left=0;
  1108. man_mov_right=0;
  1109. man_mov_up=1;
  1110. }
  1111. if(key == GLUT_KEY_RIGHT)
  1112. {
  1113. reset = 0;
  1114. dx=10;
  1115. if(sprint%2==1)
  1116. dx=8;
  1117.  
  1118. manLeft=0;
  1119. manRight=1;
  1120.  
  1121. if(man_x<1246)
  1122. {
  1123.  
  1124. //COORDINATION BETWEEN MAN AND CAMERA: FIRST 500 UNITS WITHOUT CHANGING THE CAMERA POSITION
  1125. if(man_x<=500)
  1126. {
  1127. man_x+=dx;
  1128. }
  1129. //MIDDLE MOVEMENT HAPPENS WHEN MAN X TIRES TO EXCEED 400 AND CAMERA IS BETWEEN 0 AND 1000
  1130. else if(man_x>500)
  1131. {
  1132. if(camx<=world_len_right)
  1133. camx+=dx;
  1134. }
  1135.  
  1136. //STOPPING THE CAMERA AFTER CAMERA X TRIES TO EXCEED 1000
  1137. if(camx>world_len_right)
  1138. {
  1139. man_x+=dx;
  1140. }
  1141.  
  1142.  
  1143. }
  1144.  
  1145.  
  1146. man_mov_down=0;
  1147. man_mov_left=0;
  1148. man_mov_right=1;
  1149. man_mov_up=0;
  1150.  
  1151. }
  1152. if(key == GLUT_KEY_LEFT)
  1153. {
  1154. reset = 0;
  1155. dx=15;
  1156. if(sprint%2==1)
  1157. dx=8;
  1158.  
  1159. manLeft=1;
  1160. manRight=0;
  1161.  
  1162. //BASE CONDITION: UNTIL THE MAN REACHES 10
  1163. if(man_x>10)
  1164. {
  1165.  
  1166. //ONCE CAMX TRIES TO GO TO A NEGATIVE VALUE, REDUCE man_x UP TILL BASE CONDITION AT THE TOP
  1167.  
  1168. if(camx<0)
  1169. {
  1170. man_x-=dx;
  1171. }
  1172.  
  1173.  
  1174. //IF CAMERA X IS GREATER THAN 1000 (5 added to make small buffer (ALWAYS LESS THAN dx))
  1175.  
  1176.  
  1177. //IF man_x TRIES TO GO BELOW 800, REDUCE CAMERA X UNTIL CAMERA X BECOMES EQUAL TO 0
  1178. if(man_x<=700)
  1179. {
  1180. if(camx>=0)
  1181. camx-=dx;
  1182. }
  1183.  
  1184. if(man_x>=700)
  1185. man_x-=dx;
  1186. }
  1187.  
  1188.  
  1189. man_mov_down=0;
  1190. man_mov_left=1;
  1191. man_mov_right=0;
  1192. man_mov_up=0;
  1193.  
  1194.  
  1195. }
  1196. if(key== GLUT_KEY_PAGE_DOWN)
  1197. {
  1198. sprint++;
  1199. }
  1200.  
  1201. // while(key == GLUT_KEY_PAGE_UP)
  1202. // {
  1203. // }
  1204.  
  1205. if(key == GLUT_KEY_END)
  1206. exit(0);
  1207. }
  1208.  
  1209. void enemyFire_health(int i)
  1210. {
  1211. if( man_x>=enemyFireX[i]-man_wid-camx && man_x<=enemyFireX[i]-man_x-camx+10 && man_y>=enemyFireY[i]-man_height-camy && man_y<=enemyFireY[i]+10-camy )
  1212. {
  1213. if(health>0)
  1214. health-=1;
  1215. else health=0;
  1216. }
  1217. }
  1218.  
  1219. void vertical_health_change(int i)
  1220. {
  1221. if((man_y>=vertical_laser_y[i]-camy-man_height && man_y<=vertical_laser_y[i]-camy+40) && (man_x>=vertical_laser_x[i]-camx-man_wid && man_x<=vertical_laser_x[i]-camx+40))
  1222. {
  1223. man_x-=2;
  1224. man_y-=2;
  1225. if(health>0)
  1226. health-=1;
  1227. else health=0;
  1228. }
  1229. }
  1230. void static_vertical_health_change(int len,int i)
  1231. {
  1232. if((man_y>=static_ver_laser_y[i]-camy-man_height && man_y<=static_ver_laser_y[i]-camy+len) && (man_x>=static_ver_laser_x[i]-camx-man_wid && man_x<=static_ver_laser_x[i]-camx+3))
  1233. {
  1234. man_x-=2;
  1235. man_y-=2;
  1236. if(health>0)
  1237. health-=1;
  1238. else health=0;
  1239. }
  1240. }
  1241.  
  1242. void horizontalLaser(int laserLen,int i)
  1243. {
  1244. iSetColor(lasercolorR,255,lasercolorB);
  1245. iFilledRectangle(laser_x[i]-camx,laser_y[i]-camy,laserLen,3);
  1246. iSetColor(0,255,0);
  1247. iFilledRectangle(laser_x[i]-camx-10,laser_y[i]-camy-3,10,10);
  1248.  
  1249. iSetColor(0,255,0);
  1250. iFilledRectangle(laser_x[i]-camx+100,laser_y[i]-camy-3,10,10);
  1251.  
  1252. }
  1253. //void verticalLaser(int laserLen,int i)
  1254. //{
  1255. // iSetColor(lasercolorR,255,lasercolorB);
  1256. // iFilledRectangle(vertical_laser_x[i]-camx,vertical_laser_y[i]-camy,3,laserLen);
  1257. // iSetColor(0,255,0);
  1258. // iFilledRectangle(vertical_laser_x[i]-camx-3,vertical_laser_y[i]-camy-10,10,10);
  1259. // iSetColor(0,255,0);
  1260. // iFilledRectangle(vertical_laser_x[i]-camx-3,vertical_laser_y[i]-camy+100,10,10);
  1261. //}
  1262.  
  1263. void static_verticalLaser(int laserLen,int i)
  1264. {
  1265. iSetColor(255,lasercolorR,lasercolorB);
  1266. iFilledRectangle(static_ver_laser_x[i]-camx,static_ver_laser_y[i]-camy,3,laserLen);
  1267. iSetColor(255,0,0);
  1268. iFilledRectangle(static_ver_laser_x[i]-camx-3,static_ver_laser_y[i]-camy-10,10,10);
  1269. iSetColor(255,0,0);
  1270. iFilledRectangle(static_ver_laser_x[i]-camx-3,static_ver_laser_y[i]-camy+laserLen,10,10);
  1271. }
  1272. //**************************
  1273. void vertical_shooter(int i)
  1274. {
  1275. iShowBMP2(vertical_laser_x[i]-camx,vertical_laser_y[i]-camy-5,"images\\fly.bmp",0xFFFFFF);
  1276. }
  1277. //******************************************
  1278. void healthPack()
  1279. {
  1280. if(health_pack_chk){
  1281. if(hel_pck_num<=3)
  1282. {
  1283. pack_len=26, pack_wid=22;
  1284. iSetColor(211,211,211);
  1285. iFilledRectangle(health_x[hel_pck_num-1]-camx,health_y[hel_pck_num-1]-camy,pack_len,pack_wid);
  1286. iSetColor(0,0,0);
  1287. iFilledRectangle(health_x[hel_pck_num-1]-camx+(pack_len/2)-2,health_y[hel_pck_num-1]+3-camy,4,pack_wid-6);
  1288. iFilledRectangle(health_x[hel_pck_num-1]+3-camx,health_y[hel_pck_num-1]+(pack_wid/2)-2-camy,pack_len-6,4);
  1289. if(health_y[hel_pck_num-1]>0)
  1290. health_y[hel_pck_num-1]-=.5;
  1291. }
  1292. 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))
  1293. {
  1294. //health_taken=1;
  1295. health_x[hel_pck_num-1]=-10; //making the healthpacks disappear
  1296. health_y[hel_pck_num-1]=-10;
  1297. if (health>=80)
  1298. health=100;
  1299. else
  1300. health+=20;
  1301. health_pack_chk=0;
  1302. }
  1303. if(health_y[hel_pck_num-1]<=50){
  1304. health_pack_chk=0;
  1305. health_x[hel_pck_num-1]=hel_initial_x;
  1306. health_y[hel_pck_num-1]=hel_initial_y;
  1307. }
  1308. }
  1309.  
  1310. }
  1311. void bomb()
  1312. {
  1313. if(bomb_chk){
  1314. iSetColor(255,0,0);
  1315. // iFilledCircle(bomb_x[bomb_cnt-1]-camx,bomb_y[bomb_cnt-1],bomb_r,100);
  1316. iShowBMP2(bomb_x[bomb_cnt-1]-camx,bomb_y[bomb_cnt-1],"images\\bomb.bmp",0xFFFFFF);
  1317. bomb_x[bomb_cnt-1]=bomb_x[bomb_cnt-1]+bomb_x_change[bomb_cnt-1];
  1318. bomb_y[bomb_cnt-1]+=bomb_y_change[bomb_cnt-1];
  1319. // 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]));
  1320. // 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]));
  1321. // 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]));
  1322. // 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]));
  1323. bmb_rnge_x=bomb_x[bomb_cnt-1]-bomb_r;
  1324. bmb_rnge_y=bomb_y[bomb_cnt-1]-bomb_r;
  1325. // if(d[0]<=bomb_r||d[1]<=bomb_r||d[2]<=bomb_r||d[3]<=bomb_r){
  1326. // if(health>2)
  1327. // health-=2;
  1328. // else
  1329. // health=0;
  1330. // }
  1331. if(((man_x+man_wid)>=bmb_rnge_x-camx&& man_x<=(bmb_rnge_x+2*bomb_r-camx)) && ((man_y+man_height)>=bmb_rnge_y && man_y<=(bmb_rnge_y+2*bomb_r))){
  1332. bomb_chk=0;
  1333. bomb_x[bomb_cnt-1]=bomb_initial_x;
  1334. bomb_y[bomb_cnt-1]=bomb_initial_y;
  1335. if(health>10)
  1336. health-=10;
  1337. else
  1338. health=0;
  1339. }
  1340.  
  1341. if(bomb_y[bomb_cnt-1]<=50||bomb_y[3]>=768){
  1342. bomb_chk=0;
  1343. bomb_x[bomb_cnt-1]=bomb_initial_x;
  1344. bomb_y[bomb_cnt-1]=bomb_initial_y;
  1345. }
  1346.  
  1347. }
  1348. }
  1349.  
  1350. void enemyplane(int m)
  1351. {
  1352. if(bul[m]==1){
  1353. iSetColor(0,0,0);
  1354. //dis[m]=dis[m]+3;
  1355. bul_x[m]=bul_x[m]-3;
  1356. iFilledRectangle(bul_x[m]-camx,bul_y[m],bul_l,bul_h);
  1357.  
  1358. if(bul_x[m]<-4){
  1359. bul[m]=0;
  1360. test[m]=1;
  1361.  
  1362. }
  1363. 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))
  1364. {
  1365.  
  1366. if(health>0.3)
  1367. health-=.3;
  1368. else health=0;
  1369.  
  1370. }
  1371. }
  1372. }
  1373.  
  1374. void score_show_live()
  1375. {
  1376. char curr_score[100], buf[100];
  1377. strcpy(curr_score,"CURRENT SCORE: ");
  1378. strcat(curr_score,itoa(current_score,buf,10));
  1379. iSetColor(255,0,0);
  1380. iText(10,750,curr_score);
  1381.  
  1382. char score_mul[100];
  1383. strcpy(score_mul,"SCORE MULTIPLIER: X");
  1384. strcat(score_mul,itoa(score_multiplier,buf,10));
  1385. iSetColor(255,0,0);
  1386. iText(10,730,score_mul);
  1387.  
  1388. char hi_score[100];
  1389. strcpy(hi_score,"HIGH SCORE: ");
  1390. strcat(hi_score,itoa(HighScore[0].score,buf,10));
  1391. iSetColor(255,0,0);
  1392. iText(10,710,hi_score);
  1393. }
  1394.  
  1395. void show_current_score_lead()
  1396. {
  1397. char curr_scr[100], buf[100];
  1398. strcpy(curr_scr,"YOUR SCORE: ");
  1399. strcat(curr_scr,itoa(current_score,buf,10));
  1400. iSetColor(255,255,255);
  1401. iText(420,520,"CONGRATULATIONS! You have made it to the leaderboard!");
  1402. iText(520,550,curr_scr,GLUT_BITMAP_TIMES_ROMAN_24);
  1403. }
  1404. void show_current_score_lost()
  1405. {
  1406. char curr_scr[100], buf[100];
  1407. strcpy(curr_scr,"YOUR SCORE: ");
  1408. strcat(curr_scr,itoa(current_score,buf,10));
  1409. iSetColor(255,255,255);
  1410. iText(520,400,curr_scr,GLUT_BITMAP_TIMES_ROMAN_24);
  1411. iText(420,350,"SORRY! You couldn't make it to the leaderboard :(");
  1412. iText(520,320,"Press ENTER to Continue");
  1413. }
  1414. void High_scores()
  1415. {
  1416. int i;
  1417. char ch[21];
  1418. int x=400;
  1419. int y=550;
  1420. for(i=0;i<5;i++)
  1421. {
  1422. sprintf(ch,"%s",HighScore[i].name);
  1423. iSetColor(255,255,255);
  1424. iText(x,y,ch,GLUT_BITMAP_TIMES_ROMAN_24);
  1425. sprintf(ch,"%d",HighScore[i].score);
  1426. iSetColor(255,255,255);
  1427. iText(x+300,y,ch,GLUT_BITMAP_TIMES_ROMAN_24);
  1428. y-=35;
  1429. }
  1430. }
  1431.  
  1432. void score()
  1433. { if(!game_over && level==1){
  1434. current_score+=1*score_multiplier;
  1435. }
  1436. }
  1437. void health_change(int i)
  1438. {
  1439. 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))
  1440. {
  1441. FILE *fp;
  1442. man_x-=2;
  1443. man_y+=2;
  1444. if(health>0)
  1445. health-=1;
  1446. else health=0;
  1447. }
  1448. }
  1449.  
  1450. //******************************* ANUP NEW *************************
  1451. void enemyTouch_health_change(int i)
  1452. {
  1453. if((man_x>=enemyX[i]-camx-man_wid && man_x<=enemyX[i]-camx+enemyHeight[i]) && (man_y>=enemyY[i]-camy-man_height && man_y<=enemyY[i]-camy+enemyWidth[i]) && enemyHealth[i]>.01)
  1454. {
  1455. FILE *fp;
  1456. if(man_mov_left)
  1457. man_x+=6;
  1458. if(man_mov_right)
  1459. man_x-=6;
  1460. if(man_mov_down)
  1461. man_y+=6;
  1462. if(man_mov_up)
  1463. man_y-=6;
  1464. if(health>0)
  1465. health-=1;
  1466. else health=0;
  1467. }
  1468. }
  1469.  
  1470.  
  1471. void laser_move(int i)
  1472. {
  1473. if(laserMove[i]==0 && laser_x[i]!=movingLaserRange_x2[i])
  1474. {
  1475. laser_x[i]+=1;
  1476. if(laser_x[i]==movingLaserRange_x2[i])
  1477. {
  1478. laserMove[i]=1;
  1479. }
  1480. }
  1481. if(laserMove[i]==1 && laser_x[i]!=movingLaserRange_x1[i])
  1482. {
  1483. laser_x[i]-=1;
  1484. if(laser_x[i]==movingLaserRange_x1[i])
  1485. {
  1486. laserMove[i]=0;
  1487. }
  1488. }
  1489. horizontalLaser(laserLen,i);
  1490. health_change(i);
  1491.  
  1492. if(health>50)
  1493. iSetColor(0,255,0);
  1494. else if(health>20&&health<40)
  1495. iSetColor(255,255,0);
  1496. else
  1497. iSetColor(255,0,0);
  1498. }
  1499.  
  1500. //******************************* ANUP NEW *************************
  1501. //void gem_collection(int man_x, int man_y)
  1502. //{
  1503. // int gem_cou;
  1504. // if(man_x>=1000 && man_x<=1000+40 && man_y>=700 && man_y<=700+40)
  1505. // gem_collected[gem_cou]=1;
  1506. // //if(gem_collected[])
  1507. //}
  1508.  
  1509.  
  1510.  
  1511. void iDraw()
  1512. {
  1513. iClear();
  1514. if(reset<10)
  1515. {
  1516. manMove=1;
  1517. }
  1518. else
  1519. manMove=0;
  1520.  
  1521. if(level==0)
  1522. {
  1523. // if(bg>=1&&bg<15)
  1524. // iShowBMP(0,0,"images\\1.bmp");
  1525. // if(bg>=15&&bg<30)
  1526. // iShowBMP(0,0,"images\\2.bmp");
  1527. // if(bg>=30&&bg<55)
  1528. // iShowBMP(0,0,"images\\3.bmp");
  1529. // if(bg>=45&&bg<60)
  1530. // iShowBMP(0,0,"images\\4.bmp");
  1531.  
  1532. bg++;
  1533. if(bg==60)
  1534. bg=1;
  1535. iShowBMP(0,0,"images\\1.bmp");
  1536.  
  1537. // iRectangle(185,382,270,100);
  1538. // iRectangle(185,382-80,295,80);
  1539. // iRectangle(185,382-160,315,80);
  1540. // iRectangle(185,382-240,350,80);
  1541.  
  1542.  
  1543. //if(cont==1)
  1544. //{
  1545. FILE* fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9,*fp10,*fp11, *fp12;
  1546.  
  1547. fp1=fopen("man_x_man_y.txt","r");
  1548. fscanf(fp1,"%d %d",&man_x,&man_y);
  1549. fclose(fp1);
  1550.  
  1551. fp2=fopen("dx_dy.txt","r");
  1552. fscanf(fp2,"%d %d",&dx,&dy);
  1553. fclose(fp2);
  1554.  
  1555.  
  1556. fp3=fopen("horizontal_laser.txt","r");
  1557. fscanf(fp3,"%d %d %d %d",&laser_x[0],&laser_x[1],&laser_x[2],&laser_x[3]);
  1558. fclose(fp3);
  1559.  
  1560.  
  1561. fp4=fopen("vertical_laser.txt","r");
  1562. fscanf(fp4,"%d %d",&vertical_laser_y[0],&vertical_laser_y[1]);
  1563. fclose(fp4);
  1564.  
  1565.  
  1566. fp5=fopen("bomb1.txt","r");
  1567. fscanf(fp5,"%d %d %d",&bomb_cnt,&bomb_chk,&bomb_tm);
  1568. fclose(fp5);
  1569.  
  1570.  
  1571. fp6=fopen("bomb2.txt","r");
  1572. fscanf(fp6,"%lf %lf %lf %lf %lf %lf %lf %lf",&bomb_x[bomb_cnt-1],&bomb_y[bomb_cnt-1],&bomb_x_change[bomb_cnt-1],&bomb_y_change[bomb_cnt-1],&bomb_initial_x,&bomb_initial_y,&bmb_rnge_x,&bmb_rnge_y);
  1573. fclose(fp6);
  1574.  
  1575. fp7=fopen("health.txt","r");
  1576. fscanf(fp7,"%f",&health);
  1577. fclose(fp7);
  1578.  
  1579.  
  1580. fp8=fopen("health_pack1.txt","r");
  1581. fscanf(fp8,"%d %d %d",&hel_pck_num,&health_pack_chk,&hel_tm);
  1582. fclose(fp8);
  1583.  
  1584.  
  1585. fp9=fopen("health_pack_2.txt","r");
  1586. fscanf(fp9,"%lf %lf %d %d",&health_x[hel_pck_num-1],&health_y[hel_pck_num-1],&hel_initial_x,&hel_initial_y);
  1587. fclose(fp9);
  1588.  
  1589. fp10=fopen("timer.txt","r");
  1590. fscanf(fp10,"%f",&timer);
  1591. fclose(fp10);
  1592.  
  1593. fp11=fopen("score.txt","r");
  1594. fscanf(fp11,"%d %d",&current_score,&score_multiplier);
  1595. fclose(fp11);
  1596.  
  1597. fp12=fopen("high score list.txt","r");
  1598. for(int i=0;i<5;i++)
  1599. {
  1600. fscanf(fp12,"%d ",&score_count[i]);
  1601. }
  1602. fclose(fp12);
  1603.  
  1604. FILE *fp13;
  1605. fp13=fopen("bul.txt","r");
  1606. int m;
  1607. for(m=0;m<1;m++){
  1608. fscanf(fp13,"%d %d %lf %lf %d %d",&bul[m],&test[m],&bul_x[m],&bul_y[m],&bul_k,&vln);
  1609. }
  1610. fclose(fp13);
  1611.  
  1612. FILE *fp14;
  1613. fp14=fopen("camera.txt","r");
  1614. fscanf(fp14,"%f %f",&camx,&camy);
  1615. fclose(fp14);
  1616.  
  1617. //iText(500,500,"Continue");
  1618. cont=0;
  1619.  
  1620.  
  1621. //}
  1622. if(how_to_play==1)
  1623. {
  1624. iShowBMP(0,0,"images\\howto.bmp");
  1625. if(back_from_howto)
  1626. how_to_play=0;
  1627. // iRectangle(603,50,180,65);
  1628. //iText(500,500,"how");
  1629. }
  1630. if(new_game==1)
  1631. {
  1632. timer=0;
  1633. new_game=1;
  1634. score_multiplier=1;
  1635. score_count[0]=0;
  1636. score_count[1]=0;
  1637. score_count[2]=0;
  1638. score_count[3]=0;
  1639. score_count[4]=0;
  1640. current_score=0;
  1641. health=100;
  1642. sprint=0;
  1643. cont=0;
  1644. level=1;
  1645. man_mov_right=1;
  1646. man_mov_down=0;
  1647. man_mov_left=0;
  1648. man_mov_up=0;
  1649. man_x=80;
  1650. man_y=150;
  1651. dx=3, dy=3;
  1652. sprint=0;
  1653. lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  1654.  
  1655. laserMove[0]=1;
  1656. laserMove[1]=1;
  1657. laserMove[2]=1;
  1658. laserMove[3]=1;
  1659.  
  1660. laser_x[0]=300;
  1661. laser_x[1]=700;
  1662. laser_x[2]=200;
  1663. laser_x[3]=500;
  1664.  
  1665. // laser_y[0]=100;
  1666. // laser_y[1]=270;
  1667. // laser_y[2]=400;
  1668. // laser_y[3]=500;
  1669.  
  1670. vertical_laserMove[0]=0;
  1671. vertical_laserMove[1]=1;
  1672.  
  1673.  
  1674. // vertical_laser_x[0]=850;
  1675. // vertical_laser_x[1]=700;
  1676.  
  1677. vertical_laser_y[0]=600;
  1678. vertical_laser_y[1]=400;
  1679.  
  1680. vertical_laser_count=2;
  1681. health=100;
  1682. // health_x[]={600,300,900},health_y[]={768,768,768};
  1683.  
  1684. health_x[0]=600;
  1685. health_x[1]=300;
  1686. health_x[2]=900;
  1687.  
  1688. health_y[0]=768;
  1689. health_y[1]=768;
  1690. health_y[2]=768;
  1691.  
  1692. hel_tm=0,health_pack_chk=0,hel_pck_num=0;
  1693.  
  1694. health_taken=0;//health_yes
  1695.  
  1696. bomb_x[0]=1336;
  1697. bomb_x[2]=1000;
  1698. bomb_x[2]=300;
  1699. bomb_x[3]=0;
  1700.  
  1701. bomb_y[0]=768;
  1702. bomb_y[1]=768;
  1703. bomb_y[2]=768;
  1704. bomb_y[3]=300;
  1705.  
  1706. bomb_tm=0,bomb_chk=0,bomb_cnt=0;
  1707.  
  1708. bmb_rnge_x=0;
  1709. bmb_rnge_y=0;
  1710.  
  1711. 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;
  1712. int i;
  1713. for(i=0;i<10;i++){
  1714. bul[i]=0;
  1715. }
  1716. vln=0;
  1717. bul_k=0;
  1718.  
  1719. camx=0;
  1720. camy=0;
  1721.  
  1722. enemyY[0]=50;
  1723. enemyY[1]=100;
  1724. enemyY[2]=150;
  1725. enemyY[3]=300;
  1726.  
  1727. enemyHealth[0]=100;
  1728. enemyHealth[1]=100;
  1729. enemyHealth[2]=100;
  1730. enemyHealth[3]=100;
  1731.  
  1732. gem_collected[0]=0;
  1733. gem_collected[1]=0;
  1734. gem_collected[2]=0;
  1735. //iText(500,500,"new");
  1736. level=1;
  1737. new_game=0;
  1738. cont=0;
  1739. }
  1740. if(high_score==1)
  1741. {
  1742. //level=-1;
  1743. iShowBMP(0,0,"images\\highscore.bmp");
  1744. //for(int i=0;i<5;i++)
  1745. High_scores();
  1746. if(back_from_high)
  1747. {
  1748. high_score=0;
  1749. }
  1750. // iRectangle(603,50,180,65);
  1751. }
  1752.  
  1753. // if(cont_rectangle_sweep)
  1754. // {
  1755. // iSetColor(0,0,0);
  1756. // iRectangle(185,375,280,75);
  1757. // }
  1758.  
  1759. }
  1760.  
  1761. man_wid=60,man_height=95;
  1762. //level=1;
  1763. if(level==1)
  1764. {
  1765. int i;
  1766. //iRectangle(man_x,man_y,man_wid,man_height);
  1767. for(i=0; i<4; i++)
  1768. enemyImageTrack[i]++;
  1769. manImageTrack++;
  1770.  
  1771. timer+=.01;
  1772.  
  1773. if(timer>=10)
  1774. score_multiplier=2;
  1775.  
  1776. if(timer>=50)
  1777. score_multiplier=5;
  1778. for(i=0;i<enemyNum;i++)
  1779. {
  1780. if(enemyHealth[i]<0.01)
  1781. {
  1782. // ************************************************
  1783. // BUG ASE
  1784. if(enemyHealth[i]==-1)
  1785. continue;
  1786. kill_count++;
  1787. score_multiplier++;
  1788. enemyHealth[i]=-1;
  1789. }
  1790. }
  1791.  
  1792. // if(timer>=10)
  1793. // health=110;
  1794. // takes 36 seconds to reach 0 to 10
  1795.  
  1796. iShowBMP(0,0,"images\\background-game-3.bmp");
  1797. //ENEMIES:
  1798. enemy();
  1799. reduceEnemyHealth();
  1800. changeEnemyY();
  1801. enemyFire();
  1802. enemyFireControl();
  1803. enemyFireChange();
  1804. drawEnemyFire();
  1805. reduceManHealth();
  1806.  
  1807. //DRAWING ENEMY FIRE
  1808. iSetColor(255,0,0);
  1809. for(int i=0; i<enemyNum; i++){
  1810. if(enemyFireY[i]-man_y<80 && enemyFireY[i]-man_y>0)
  1811. {
  1812. if(enemyFireLR[i]==0 && enemyFireX[i]-camx-man_x>50)
  1813. {
  1814. iShowBMP2(enemyFireX[i]-camx, enemyFireY[i], "images\\fireleft.bmp", 0xFFFFFF);
  1815.  
  1816. }
  1817.  
  1818.  
  1819.  
  1820. if(enemyFireLR[i]==1 && man_x-enemyFireX[i]+camx>0)
  1821. {
  1822. iShowBMP2(enemyFireX[i]-camx, enemyFireY[i], "images\\fireright.bmp", 0xFFFFFF);
  1823. }
  1824.  
  1825. }
  1826.  
  1827. else
  1828. {
  1829. if(enemyFireLR[i]==0)
  1830. iShowBMP2(enemyFireX[i]-camx, enemyFireY[i], "images\\fireleft.bmp", 0xFFFFFF);
  1831. else if(enemyFireLR[i]==1)
  1832. iShowBMP2(enemyFireX[i]-camx, enemyFireY[i], "images\\fireright.bmp", 0xFFFFFF);
  1833.  
  1834. }
  1835.  
  1836. }
  1837.  
  1838. if(manHitToLeft)
  1839. {
  1840. if(manLeftDisplacement<20)
  1841. {
  1842. if(man_x>10)
  1843. man_x-=2;
  1844. manLeftDisplacement++;
  1845. }
  1846. else
  1847. {
  1848. manLeftDisplacement=0;
  1849. manHitToLeft=0;
  1850. }
  1851.  
  1852. }
  1853.  
  1854. if(manHitToRight)
  1855. {
  1856. if(manRightDisplacement<20)
  1857. {
  1858. if(man_x<1340)
  1859. man_x+=2;
  1860. manRightDisplacement++;
  1861. }
  1862. else
  1863. {
  1864. manRightDisplacement=0;
  1865. manHitToRight=0;
  1866. }
  1867.  
  1868. }
  1869.  
  1870. int gem_cou;
  1871. if(man_x>=1000-man_wid && man_x<=1000+40 && man_y>=700-man_height && man_y<=700+40) // make it like bomb touch
  1872. gem_collected[0]=1; //show the gem in one corner in small size if taken
  1873. if(!gem_collected[0])
  1874. iShowBMP2(1000,700,"images\\pink-gem.bmp",0xFFFFFF); //this is gem 1
  1875.  
  1876. // if(gem_collected[0])
  1877. // iText(80,700,"CONGRATULATIONS! You have collected a gem");
  1878. //// GEM TEXT
  1879. iSetColor(255, 100, 10);
  1880.  
  1881. // iRectangle(man_x,man_y,man_wid,man_height);
  1882. //iRectangle(dead_man_x,dead_man_y,man_wid,man_height);
  1883.  
  1884. renderSuperMan();
  1885.  
  1886. changelasercolor();
  1887.  
  1888. //******************************* ANUP NEW *************************
  1889.  
  1890. for(i=0;i<horizontal_laser_count;i++)
  1891. {
  1892. laser_move(i);
  1893. }
  1894.  
  1895.  
  1896. for(i=0;i<enemyNum;i++)
  1897. {
  1898. enemyTouch_health_change(i);
  1899. }
  1900.  
  1901. //******************************* ANUP NEW *************************
  1902.  
  1903. for(i=0;i<vertical_laser_count;i++)
  1904. {
  1905. if(vertical_laserMove[i]==0 && vertical_laser_y[i]>=vertical_movingLaserRange_y1[i])
  1906. {
  1907. vertical_laser_y[i]-=1;
  1908. if(vertical_laser_y[i]==vertical_movingLaserRange_y1[i])
  1909. {
  1910. vertical_laserMove[i]=1;
  1911. }
  1912. }
  1913. if(vertical_laserMove[i]==1 && vertical_laser_y[i]<=vertical_movingLaserRange_y2[i])
  1914. {
  1915. vertical_laser_y[i]+=1;
  1916. if(vertical_laser_y[i]==vertical_movingLaserRange_y2[i])
  1917. {
  1918. vertical_laserMove[i]=0;
  1919. }
  1920. }
  1921. // verticalLaser(100,i);
  1922. vertical_shooter(i);
  1923. vertical_health_change(i);
  1924.  
  1925. }
  1926. for(i=0;i<static_ver_laser_count;i++)
  1927. {
  1928. static_verticalLaser(static_laserLen,i);
  1929. static_vertical_health_change(static_laserLen,i);
  1930. }
  1931.  
  1932. if(!health_pack_chk)
  1933. {
  1934. hel_tm++;
  1935. if(hel_pck_num==3)
  1936. hel_pck_num=0;
  1937. if(hel_tm%400==0){
  1938. health_pack_chk=1;
  1939. hel_tm=0;
  1940. hel_pck_num++;
  1941. hel_initial_x=health_x[hel_pck_num-1];
  1942. hel_initial_y=health_y[hel_pck_num-1];
  1943. health_x[hel_pck_num-1]=health_x[hel_pck_num-1]+camx;
  1944. }
  1945. }
  1946. if(health_pack_chk)
  1947. healthPack();
  1948. if(!bomb_chk)
  1949. {
  1950. bomb_tm++;
  1951. if(bomb_cnt==4)
  1952. bomb_cnt=0;
  1953. if(bomb_tm%200==0)
  1954. {
  1955. bomb_chk=1;
  1956. bomb_tm=0;
  1957. bomb_cnt++;
  1958. bomb_initial_x=bomb_x[bomb_cnt-1];
  1959. bomb_initial_y=bomb_y[bomb_cnt-1];
  1960. }
  1961. }
  1962. if(bomb_chk)
  1963. bomb();
  1964.  
  1965. // iSetColor(0,255,0);
  1966. // iFilledRectangle(1200,700,health,4);
  1967. iSetColor(0,255,0);
  1968.  
  1969.  
  1970. if(health==100)
  1971. iText(1200,700-13,"Health = Full");
  1972. else if(health<20 && health!=0)
  1973. iText(1200,700-13,"Health Critical");
  1974. else if(health==0)
  1975. iText(1200,700-13,"Zero Health");
  1976. else
  1977. iText(1200,700-13,"Health");
  1978. //health=0;
  1979. if(!health)
  1980. {
  1981. game_over = 1;
  1982. level_one_sound();
  1983. game_over_sound();
  1984. health = 0.1;
  1985. }
  1986.  
  1987. // enemyF();
  1988.  
  1989. //LASER BAR
  1990. iSetColor(255,0,0);
  1991. iText(1200,660, "Laser Power");
  1992. iRectangle(1200,670,100,6);
  1993. iFilledRectangle(1200,670,laserHealth,6);
  1994.  
  1995.  
  1996. //LASER INITIATE CODE
  1997. if(!laserStat) //INDICATES ONE COMPLETE CYCLE OF LASER
  1998. {
  1999. if(laserSwitch) //INDICATES ON/OFF OF LASER
  2000. {
  2001. laser();
  2002. laserTimer++;
  2003. if(laserHealth>0)
  2004. laserHealth-=1; //PRODUCT OF LASERHEALTH AND LASERTIMER IS ALWAYS EQUAL TO 100 - THE SIZE OF THE LASER BAR
  2005.  
  2006. if(laserTimer>100) //INCREASE THIS NUMBER TO INCREASE DURATION OF LASER
  2007. {
  2008. laserStat=1;
  2009. laserTimer=0;
  2010. laserSwitch=0;
  2011. }
  2012.  
  2013. }
  2014.  
  2015. }
  2016. if(health>50)
  2017. iSetColor(0,255,0);
  2018. else if(health>20&&health<=50)
  2019. iSetColor(255,255,0);
  2020. else
  2021. iSetColor(255,0,0);
  2022. iRectangle(1200,700,100,8);
  2023. iFilledRectangle(1200,700,health,8);
  2024.  
  2025. //REFILLING THE LASER
  2026.  
  2027. if(laserStat)
  2028. {
  2029. laserHealth+=2; //CONTROLLING REFILLING OF LASER/REFILL THE LASER
  2030.  
  2031. if(laserHealth>=100)
  2032. laserStat=0;
  2033. }
  2034. score_show_live();
  2035.  
  2036. int m;
  2037. FILE *fp13;
  2038. fp13=fopen("bul.txt","w");
  2039.  
  2040. for(m=0;m<10;m++){
  2041. if(bul[m]==0){
  2042. test[m]++;
  2043. if(bul_k==10){
  2044. bul_k=0;
  2045. vln++;
  2046. if(vln>2){
  2047. vln=1;
  2048. }
  2049. }
  2050. }
  2051. if(test[m]%bul_ctrl==0){
  2052.  
  2053. if(vertical_laser_x[vln-1]-camx>0&&vertical_laser_x[vln-1]-camx<1366){
  2054. bul_x[m]=vertical_laser_x[vln-1];
  2055. //dis[m]=0;
  2056. bul_y[m]=vertical_laser_y[vln-1];
  2057. bul_k++;
  2058. }
  2059. else {
  2060. vln++;
  2061. if(vln>2){
  2062. vln=1;
  2063. }
  2064. }
  2065. bul[m]=1;
  2066. test[m]=1;
  2067. }
  2068. enemyplane(m);
  2069. fprintf(fp13,"%d %d %lf %lf %d %d\n",bul[m],test[m],bul_x[m],bul_y[m],bul_k,vln);
  2070. }
  2071. fclose(fp13);
  2072. }
  2073. if(game_over)
  2074. {
  2075. if(man_y>=50)
  2076. {
  2077. man_y-=5;
  2078. if(manImageTrack<=10)
  2079. iShowBMP2(man_x,man_y,"images\\deadleft1.bmp",0xFFFFFF);
  2080. else
  2081. iShowBMP2(man_x,man_y,"images\\deadleft2.bmp",0xFFFFFF);
  2082.  
  2083. if(manImageTrack>20)
  2084. manImageTrack=0;
  2085.  
  2086. }
  2087.  
  2088.  
  2089. iShowBMP2(470,game_over_y,"images\\game_over.bmp",0xFFFFFF);
  2090. if(game_over_y<=280)
  2091. game_over_y+=4;
  2092. if(game_over_y>=280)
  2093. {
  2094. game_end++;
  2095. if(game_end==50){
  2096.  
  2097. game_over_y=0;
  2098.  
  2099. health=100;
  2100. sprint=0;
  2101. cont=0;
  2102.  
  2103. Leaderboard temp, save;
  2104. save.score = current_score;
  2105. strcpy(save.name, "PLAYER");
  2106. for(int i=0; i<5; i++)
  2107. {
  2108. if(HighScore[i].score<=save.score)
  2109. {
  2110. if(getname == 0)leaderboardIndex=i;
  2111. getname = 1;
  2112. temp = HighScore[i];
  2113. HighScore[i] = save;
  2114. save = temp;
  2115. }
  2116. // for(int j=0;j<5;j++){
  2117. // printf("%s\t%d\n",HighScore[j].name,HighScore[j].score);
  2118. // }
  2119. // else
  2120. // getname == 0;
  2121. }
  2122.  
  2123. game_over=0;
  2124. level=2;
  2125. game_over_sound();
  2126. your_score_page_sound();
  2127.  
  2128.  
  2129. man_x=80;
  2130. man_y=150;
  2131. dx=3, dy=3;
  2132. sprint=0;
  2133. lasercolorR = 0,lasercolorG = 0,lasercolorB = 0, changecolor = 0;
  2134.  
  2135.  
  2136. laserMove[0]=1;
  2137. laserMove[1]=1;
  2138. laserMove[2]=1;
  2139. laserMove[3]=1;
  2140.  
  2141. laser_x[0]=300;
  2142. laser_x[1]=700;
  2143. laser_x[2]=200;
  2144. laser_x[3]=500;
  2145.  
  2146. // laser_y[0]=100;
  2147. // laser_y[1]=270;
  2148. // laser_y[2]=400;
  2149. // laser_y[3]=500;
  2150.  
  2151.  
  2152. vertical_laserMove[0]=0;
  2153. vertical_laserMove[1]=1;
  2154.  
  2155.  
  2156. // vertical_laser_x[0]=1500;
  2157. // vertical_laser_x[1]=700;
  2158.  
  2159. vertical_laser_y[0]=600;
  2160. vertical_laser_y[1]=400;
  2161.  
  2162. vertical_laser_count=2;
  2163. health=100;
  2164. // health_x[]={600,300,900},health_y[]={768,768,768};
  2165.  
  2166. health_x[0]=600;
  2167. health_x[1]=300;
  2168. health_x[2]=900;
  2169.  
  2170. health_y[0]=768;
  2171. health_y[1]=768;
  2172. health_y[2]=768;
  2173.  
  2174. hel_tm=0,health_pack_chk=0,hel_pck_num=0;
  2175.  
  2176. health_taken=0;//health_yes
  2177.  
  2178. bomb_x[0]=1336;
  2179. bomb_x[2]=1000;
  2180. bomb_x[2]=300;
  2181. bomb_x[3]=0;
  2182.  
  2183. bomb_y[0]=768;
  2184. bomb_y[1]=768;
  2185. bomb_y[2]=768;
  2186. bomb_y[3]=300;
  2187.  
  2188. bomb_tm=0,bomb_chk=0,bomb_cnt=0;
  2189.  
  2190. bmb_rnge_x=0;
  2191. bmb_rnge_y=0;
  2192.  
  2193. 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;
  2194. int i;
  2195. for(i=0;i<10;i++){
  2196. bul[i]=0;
  2197. }
  2198. bul_k=0;
  2199. vln=0;
  2200.  
  2201. gem_collected[0]=0;
  2202. gem_collected[1]=0;
  2203. gem_collected[2]=0;
  2204.  
  2205.  
  2206. // current_score=0;
  2207. // score_multiplier=1;
  2208. camx=0;
  2209. camy=0;
  2210.  
  2211. level=2; // level=2 indicating the your score page
  2212.  
  2213. new_game=0;
  2214. cont=0;
  2215. game_end=0;
  2216. //PLEASE CHANGE THIS IF YOU INTEND TO CHANGE THE INITIAL POSITIONS
  2217. // enemyX[0] = 200;
  2218. // enemyX[1] = 400;
  2219. // enemyX[2] = 600;
  2220. // enemyX[3] = 1000;
  2221.  
  2222.  
  2223. enemyY[0]=50;
  2224. enemyY[1]=100;
  2225. enemyY[2]=150;
  2226. enemyY[3]=300;
  2227.  
  2228. enemyHealth[0]=100;
  2229. enemyHealth[1]=100;
  2230. enemyHealth[2]=100;
  2231. enemyHealth[3]=100;
  2232.  
  2233.  
  2234.  
  2235. }
  2236.  
  2237. }
  2238. }
  2239. // level=2;
  2240. if(level==2)
  2241. {
  2242. // BMP & CURRENT SCORE SHOW KORA LAGBE
  2243.  
  2244. if(getname)
  2245. {
  2246. show_current_score_lead();
  2247. iSetColor(255,255,255);
  2248. iFilledRectangle(417,386,420,50);
  2249. iSetColor(192,192,192);
  2250. iFilledRectangle(417+5,386+5,420-10,50-10);
  2251.  
  2252. iSetColor(255,255,255);
  2253. iText(420,450,"Enter Your Name: (Not more than 20 Letters)");
  2254.  
  2255. iSetColor(0,0,0);
  2256. iSetColor(255,255,255);
  2257. iText(417+20,386+18,str,GLUT_BITMAP_TIMES_ROMAN_24);
  2258. iSetColor(255,255,255);
  2259. iText(420,400-35,"HIT ENTER TO CONTINUE");
  2260. }
  2261. else
  2262. show_current_score_lost();
  2263.  
  2264.  
  2265. }
  2266.  
  2267. FILE * fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9, *fp10,*fp11, *fp12;
  2268. fp1=fopen("man_x_man_y.txt","w");
  2269. fprintf(fp1,"%d %d",man_x,man_y);
  2270. fclose(fp1);
  2271.  
  2272.  
  2273. fp2=fopen("dx_dy.txt","w");
  2274. fprintf(fp2,"%d %d",dx,dy);
  2275. fclose(fp2);
  2276.  
  2277. fp3=fopen("horizontal_laser.txt","w");
  2278. fprintf(fp3,"%d %d %d %d",laser_x[0],laser_x[1],laser_x[2],laser_x[3]);
  2279. fclose(fp3);
  2280.  
  2281.  
  2282. fp4=fopen("vertical_laser.txt","w");
  2283. fprintf(fp4,"%d %d",vertical_laser_y[0],vertical_laser_y[1]);
  2284. fclose(fp4);
  2285.  
  2286.  
  2287. fp5=fopen("bomb1.txt","w");
  2288. fprintf(fp5,"%d %d %d",bomb_cnt,bomb_chk,bomb_tm);
  2289. fclose(fp5);
  2290.  
  2291. fp6=fopen("bomb2.txt","w");
  2292. fprintf(fp6,"%f %f %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,bmb_rnge_x,bmb_rnge_y);
  2293. fclose(fp6);
  2294.  
  2295. fp7=fopen("health.txt","w");
  2296. fprintf(fp7,"%f",health);
  2297. fclose(fp7);
  2298.  
  2299.  
  2300. fp8=fopen("health_pack1.txt","w");
  2301. fprintf(fp8,"%d %d %d",hel_pck_num,health_pack_chk,hel_tm);
  2302. fclose(fp8);
  2303.  
  2304.  
  2305. fp9=fopen("health_pack_2.txt","w");
  2306. fprintf(fp9,"%f %f %f %f",health_x[hel_pck_num-1],health_y[hel_pck_num-1],hel_initial_x,hel_initial_y);
  2307. fclose(fp9);
  2308.  
  2309. fp10=fopen("timer.txt","w");
  2310. fprintf(fp10,"%f",timer);
  2311. fclose(fp10);
  2312.  
  2313. fp11=fopen("score.txt","w");
  2314. fprintf(fp11,"%d %d",current_score,score_multiplier);
  2315. fclose(fp11);
  2316.  
  2317. fp12=fopen("high score list.txt","w");
  2318. for(int i=0;i<5;i++)
  2319. {
  2320. fprintf(fp12,"%d ",score_count[i]);
  2321. }
  2322. fclose(fp12);
  2323.  
  2324.  
  2325. FILE *fp13;
  2326. fp13=fopen("bul.txt","w");
  2327. int m;
  2328. for(m=0;m<10;m++){
  2329. fprintf(fp13,"%d %d %lf %lf %d %d",bul[m],test[m],bul_x[m],bul_y[m],bul_k,vln);
  2330. }
  2331. fclose(fp13);
  2332.  
  2333. // FILE *fp14;
  2334. // fp14=fopen("high score list.txt","w");
  2335. // for(int i=0;i<enemyNum;i++)
  2336. // {
  2337. // fprintf(fp14,"%d ",score_count[i]);
  2338. // }
  2339. // fclose(fp14);
  2340.  
  2341.  
  2342. // int i,j;
  2343. // for(i=0;i<5;i++)
  2344. // {
  2345. // if(current_score>score_count[i])
  2346. // {
  2347. // for(j=4;j>i;j--)
  2348. // {
  2349. // score_count[j]=score_count[j-1];
  2350. // }
  2351. // score_count[i]=current_score;
  2352. // break;
  2353. // }
  2354. // }
  2355.  
  2356. FILE *fp14;
  2357. fp14=fopen("camera.txt","w");
  2358. fprintf(fp14,"%f %f",camx,camy);
  2359. fclose(fp14);
  2360. // for(i=0;i<5;i++){
  2361. // printf("%d ",score_count[i]);
  2362. // }
  2363.  
  2364. }
  2365. int main()
  2366. {
  2367.  
  2368.  
  2369. FILE *fp20 = fopen("high score.txt", "r");
  2370.  
  2371. for(int i=0; i<5; i++)
  2372. {
  2373. fscanf(fp20, "%s %d\n", HighScore[i].name, &HighScore[i].score);
  2374.  
  2375. }
  2376.  
  2377. fclose(fp20);
  2378.  
  2379. menu_sound();
  2380. iSetTimer(50, changeEnemy);
  2381. iSetTimer(50, detectMotion);
  2382. iSetTimer(100,score);
  2383. // PlaySound((LPCSTR) "C:\\Users\\Public\\Music\\Sample Music\\Sleep Away.mp3", NULL, SND_FILENAME | SND_ASYNC);
  2384. //DWORD dwError = GetLastError();
  2385.  
  2386. //place your own initialization codes here.
  2387. // iSetTimer(5, ballChange);
  2388. //
  2389.  
  2390. iInitialize(1366, 768, "Superman Adventures ver 1.5");
  2391.  
  2392. return 0;
  2393. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement