home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / demo.c < prev    next >
C/C++ Source or Header  |  2010-01-20  |  11KB  |  532 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3. #include <graphics/gfxmacros.h>
  4. #include <stdio.h>
  5. #include <h/rot.h>
  6. #include <h/extern.h>
  7.  
  8.  
  9. initInput(x)
  10. LONG x;
  11. {
  12. LONG n;
  13.  
  14. n = control.input[x];
  15.  
  16. in.FI[n] = FALSE;
  17. in.FIUP[n] = TRUE;
  18. in.HY[n] = FALSE;
  19. in.TH[n] = FALSE;
  20.  
  21. in.PAUSE = FALSE;
  22. in.EXIT = FALSE;
  23. in.NEXT = FALSE;
  24. }
  25.  
  26. initLEVEL()
  27. {
  28. LONG x,y;
  29.  
  30. for (x=control.playernum;x<control.playernum+control.maxenemynum;x++)
  31.     {
  32.     ship[x].pilot = DESTROYED;
  33.     for (y=0;y<ship[x].fnum;y++) ship[x].shotI[y].flight = FALSE;
  34.     }
  35.  
  36. saucer.flag = FALSE;
  37. if (control.game == 1) control.asteroidnum = 8+control.level*8;
  38. else                   control.asteroidnum = 12+control.level*4;
  39. control.asize = 0;
  40.  
  41. ClearScreen();
  42. DrawGameScreen();
  43. initAsteroids();
  44.  
  45. for(x=0;x<control.ftrnum;x++)
  46.     f[x].flight = FALSE;
  47.  
  48. for (x=0;x<control.playernum;x++)
  49.     {
  50.     control.hyper[x] = 0;
  51.     if (control.player[x] == TRUE)
  52.         initPlayer(x);
  53.     initfirestructures(x);
  54.     }
  55.  
  56. for(x=0;x<control.maxenemynum+control.playernum;x++)
  57.     {
  58.     initfirestructures(x);
  59.     ship[x].ox = 200;
  60.     ship[x].oy = 200;
  61.     }
  62. for (x=0;x<saucer.fnum;x++) saucer.photI[x].flight = FALSE;
  63.  
  64. control.enemynum=0;
  65.  
  66. inittokenexplosions();
  67. initboxes();
  68.  
  69. for(x=0;x<control.battleshipnum;x++)
  70.     bs[x].flight=FALSE;
  71.  
  72. for(x=0;x<control.debrisnum;x++)
  73.     d[x].length=0;
  74.  
  75. for(x=0;x<control.minenum;x++)
  76.     m[x].flight = FALSE;
  77.  
  78. for(x=0;x<control.hypernum;x++)
  79.     h[x].flag = FALSE;
  80.  
  81. /*if (control.game != 1) initMines(Random(3.0));*/
  82.  
  83. for(x=0;x<2;x++) initInput(x);
  84. }
  85.  
  86.  
  87. DisplayLevel()
  88. {
  89. LONG x,y=0;
  90. BYTE string[20];
  91. BOOL getout = FALSE;
  92.  
  93. for (x=0;x<control.playernum;x++)
  94.         ship[x].pilot = DESTROYED;
  95.  
  96. timedelay(2000);  /* prime the pump */
  97.  
  98. while (getout == FALSE)
  99. {
  100. getjoystickinput();
  101.  
  102. bit^=1;
  103.  
  104. SetAPen(rp1[bit],2);
  105. SetWrMsk(rp1[bit],0xfe);
  106. SetFont(rp1[bit],basicfont);
  107. sprintf(string,"LEVEL %d",control.level);
  108. Move(rp1[bit],gi.wi/2-100,gi.he/2-20);
  109. Text(rp1[bit],string,strlen(string));
  110.  
  111. for (x=0;x<control.asteroidnum;x++)
  112.     if (a[x].flag != FALSE) UpdateAsteroid(x);
  113.  
  114. dodrawlist();
  115.  
  116. waitfortimer();
  117. timedelay(control.delay);
  118. WaitBlit();
  119. changeview(bit);
  120.  
  121. SetAPen(rp1[1-bit],0);
  122.  
  123. EraseAsteroids();
  124.  
  125. if (++y > 50)
  126.     {
  127.     if ((CheckAsteroidWindow(0) == TRUE) && (CheckAsteroidWindow(1) == TRUE))
  128.         getout = TRUE;
  129.  
  130.     if ((in.FI[0] == TRUE) || (in.FI[1] == TRUE)) getout = TRUE;
  131.     }
  132. else
  133.     {
  134.     if (in.EXIT == TRUE) getout = TRUE;
  135.     else in.FI[0] = in.FI[1] = FALSE;
  136.     }
  137. }
  138.  
  139. for (x=0;x<2;x++) SetFont(rp1[x],hiresfont);
  140.  
  141. for (x=0;x<control.playernum;x++)
  142.     if (control.player[x] == TRUE) ship[x].pilot = HUMAN;
  143.  
  144. for (y=0;y<2;y++) 
  145.     {
  146.     SetAPen(rp1[y],0);
  147.     SetWrMsk(rp1[y],0xfe);
  148.     RectFill(rp1[y],gi.wi/2-101,gi.he/2-20-gi.largefontheight-3,gi.wi/2+150,gi.he/2-19);
  149.     }
  150. }
  151.  
  152.  
  153. CheckAsteroidWindow(n)
  154. LONG n;
  155. {
  156. BOOL out;
  157. LONG x,p;
  158.  
  159. out = TRUE;
  160. for (x=0;x<control.asteroidnum;x++)
  161.     if (a[x].flag != FALSE)
  162.         for(p=0;p<control.playernum;p++)
  163.             {
  164.             if ((control.player[p] == TRUE) && (n == p))
  165.                 if ((abs(a[x].x - gi.wi/2) < 70+abs(a[x].vx*10)) && (abs(a[x].y - (gi.he/2-20)) < 50+abs(a[x].vy*10)))
  166.                     {
  167.                     out = FALSE;
  168.                     break;
  169.                     }
  170.             }
  171.  
  172. if (saucer.flag == TRUE)
  173.     if ((abs(saucer.x - 310) < 75) && (abs(saucer.y - 200) < 50)) 
  174.         out = FALSE;
  175.  
  176. return(out);
  177. }
  178.  
  179.  
  180. printendgame()
  181. {
  182. SetAPen(rp1[bit],2);
  183. SetWrMsk(rp1[bit],0xfe);
  184. SetFont(rp1[bit],basicfont);
  185.  
  186. Move(rp1[bit],gi.wi/2-100,gi.he/2-20);
  187. Text(rp1[bit],"GAME OVER",9);
  188.  
  189. SetFont(rp1[bit],hiresfont);
  190. }
  191.  
  192.  
  193. Information()
  194. {
  195. LONG x;
  196. LONG wi,he,wo;
  197. LONG sax,say,sapos;
  198. LONG sattx,satty,sattpos;
  199. LONG ax[3],ay[3],ap[3];
  200. LONG bx[4],by[4],bp[4];
  201. LONG off;
  202. LONG spos[10];
  203. LONG sxx[10],syy[10];
  204. LONG simage[10];
  205.  
  206. off = gi.wi/2-320;
  207.  
  208. for (x=0;x<2;x++)
  209.     {
  210.     SetAPen(rp1[x],2);
  211.     SetWrMsk(rp1[x],0xfe);
  212.     SetFont(rp1[x],basicfont);
  213.     Move(rp1[x],off+220,40);
  214.     Text(rp1[x],"ASTERIODS II",12);
  215.  
  216.     SetFont(rp1[x],sfont);
  217.     Move(rp1[x],off+350,260);
  218.     Text(rp1[x],"KEYBOARD COMMANDS",17);
  219.     Move(rp1[x],off+360,280);
  220.     Text(rp1[x],"Z,X  ROTATE",11);
  221.     Move(rp1[x],off+360,290);
  222.     Text(rp1[x],"<,>  THRUST",11);
  223.     Move(rp1[x],off+360,300);
  224.     Text(rp1[x],"<.>  FIRE",9);
  225.     Move(rp1[x],off+360,310);
  226.     Text(rp1[x],"</>  HYPERSPACE",15);
  227.     Move(rp1[x],off+360,320);
  228.     Text(rp1[x],"<SPACE>  PAUSE",14);
  229.  
  230.     Move(rp1[x],off+483,260);
  231.     Text(rp1[x],"JOYSTICK COMMANDS",17);
  232.     Move(rp1[x],off+480,280);
  233.     Text(rp1[x],"LEFT/RIGHT  ROTATE",18);
  234.     Move(rp1[x],off+480,290);
  235.     Text(rp1[x],"UP          THRUST",18);
  236.     Move(rp1[x],off+480,300);
  237.     Text(rp1[x],"BUTTON      FIRE",16);
  238.     Move(rp1[x],off+480,310);
  239.     Text(rp1[x],"BACK        HYPERSPACE",22);
  240.  
  241.     Move(rp1[x],off+400,340);
  242.     Text(rp1[x],"FOR GAME REGISTRATION,",22);
  243.     Move(rp1[x],off+400,350);
  244.     Text(rp1[x],"BUG REPORTS, OR",15);
  245.     Move(rp1[x],off+400,360);
  246.     Text(rp1[x],"SOURCE INFORMATION, SEND",24);
  247.     Move(rp1[x],off+400,370);
  248.     Text(rp1[x],"INTERNET MAIL TO:",17);
  249.     Move(rp1[x],off+400,380);
  250.     Text(rp1[x],"seifert@gn.ecn.purdue.edu",25);
  251.     Move(rp1[x],off+400,390);
  252.     Text(rp1[x],"OR CALL (317)743-5999",21);
  253.  
  254.  
  255.     Move(rp1[x],off+255,60);
  256.     Text(rp1[x],"DESIGNED AND CODED BY MIKE SEIFERT",34);
  257.  
  258.     Move(rp1[x],off+0,130);
  259.     Text(rp1[x],"PLAYER 1 CRUISER",16);
  260.  
  261.     Move(rp1[x],off+125,130);
  262.     Text(rp1[x],"PLAYER 2 CRUISER",16);
  263.  
  264.     Move(rp1[x],off+250,130);
  265.     Text(rp1[x],"ENEMY LIGHT CRUISER",19);
  266.     Move(rp1[x],off+266,140);
  267.     Text(rp1[x],"1000 POINTS",11);
  268.  
  269.     Move(rp1[x],off+375,130);
  270.     Text(rp1[x],"ENEMY HEAVY CRUISER",19);
  271.     Move(rp1[x],off+391,140);
  272.     Text(rp1[x],"3000 POINTS",11);
  273.  
  274.     Move(rp1[x],off+505,130);
  275.     Text(rp1[x],"ENEMY CARRIER",13);
  276.     Move(rp1[x],off+510,140);
  277.     Text(rp1[x],"5000 POINTS",11);
  278.  
  279.  
  280.  
  281.     Move(rp1[x],off+0,200);
  282.     Text(rp1[x],"ENEMY X CRUISER",15);
  283.     Move(rp1[x],off+8,210);
  284.     Text(rp1[x],"3500 POINTS",11);
  285.  
  286.     Move(rp1[x],off+125,200);
  287.     Text(rp1[x],"ENEMY MINELAYER",15);
  288.     Move(rp1[x],off+135,210);
  289.     Text(rp1[x],"500 POINTS",10);
  290.  
  291.     Move(rp1[x],off+250,200);
  292.     Text(rp1[x],"ENEMY DREADNOUGHT",17);
  293.     Move(rp1[x],off+262,210);
  294.     Text(rp1[x],"4000 POINTS",11);
  295.  
  296.     Move(rp1[x],off+375,200);
  297.     Text(rp1[x],"ENEMY M-CRUISER",15);
  298.     Move(rp1[x],off+383,210);
  299.     Text(rp1[x],"2000 POINTS",11);
  300.  
  301.     Move(rp1[x],off+500,200);
  302.     Text(rp1[x],"ENEMY FIGHTERS",14);
  303.     Move(rp1[x],off+510,210);
  304.     Text(rp1[x],"50 POINTS",9);
  305.  
  306.  
  307.     Move(rp1[x],off+250,275);
  308.     Text(rp1[x],"SCOUT SAUCER",12);
  309.     Move(rp1[x],off+254,285);
  310.     Text(rp1[x],"500 POINTS",10);
  311.  
  312.     Move(rp1[x],off+250,330);
  313.     Text(rp1[x],"ATTACK SAUCER",13);
  314.     Move(rp1[x],off+254,340);
  315.     Text(rp1[x],"1500 POINTS",11);
  316.  
  317.     Move(rp1[x],off+255,390);
  318.     Text(rp1[x],"MINEFIELD",9);
  319.  
  320.  
  321.  
  322.     Move(rp1[x],off+125,260);
  323.     Text(rp1[x],"LARGE ASTEROID",14);
  324.     Move(rp1[x],off+125,270);
  325.     Text(rp1[x],"50 POINTS",9);
  326.  
  327.     Move(rp1[x],off+125,300);
  328.     Text(rp1[x],"MEDIUM ASTEROID",15);
  329.     Move(rp1[x],off+125,310);
  330.     Text(rp1[x],"100 POINTS",10);
  331.  
  332.     Move(rp1[x],off+125,330);
  333.     Text(rp1[x],"SMALL ASTEROID",14);
  334.     Move(rp1[x],off+125,340);
  335.     Text(rp1[x],"150 POINTS",10);
  336.  
  337.     Move(rp1[x],off+125,369);
  338.     Text(rp1[x],"WEAPON FLOTSAM",14);
  339.  
  340.     Move(rp1[x],off+125,384);
  341.     Text(rp1[x],"LIFE FLOTSAM",12);
  342.  
  343.     Move(rp1[x],off+125,399);
  344.     Text(rp1[x],"SHIELD FLOTSAM",14);
  345.  
  346.     Move(rp1[x],off+125,414);
  347.     Text(rp1[x],"AUTOFIRE FLOTSAM",16);
  348.     }
  349.  
  350. ax[0] = off+75;
  351. ay[0] = 245;
  352. ap[0] = 0;
  353.  
  354. ax[1] = off+80;
  355. ay[1] = 290;
  356. ap[1] = 0;
  357.  
  358. ax[2] = off+85;
  359. ay[2] = 325;
  360. ap[2] = 0;
  361.  
  362. bx[0] = off+90;
  363. by[0] = 360;
  364. bp[0] = 0;
  365.  
  366. bx[1] = off+90;
  367. by[1] = 375;
  368. bp[1] = 1;
  369.  
  370. bx[2] = off+90;
  371. by[2] = 390;
  372. bp[2] = 2;
  373.  
  374. bx[3] = off+90;
  375. by[3] = 405;
  376. bp[3] = 3;
  377.  
  378.  
  379. for(x=0;x<5;x++)
  380.     {
  381.     spos[x] = 0;
  382.     sxx[x] = off+40+125*x;
  383.     syy[x] = 100;
  384.     }
  385.  
  386. for(x=0;x<4;x++)
  387.     {
  388.     spos[5+x] = 0;
  389.     sxx[5+x] = off+40+125*x;
  390.     syy[5+x] = 170;
  391.     }
  392.  
  393. simage[0] = il.player;
  394. simage[1] = il.player2;
  395. simage[2] = il.elight;
  396. simage[3] = il.eheavy;
  397. simage[4] = il.carrier;
  398. simage[5] = il.xcruiser;
  399. simage[6] = il.minelayer;
  400. simage[7] = il.dreadnought;
  401. simage[8] = il.magnetic;
  402.  
  403. sapos = 0;
  404. sax = off+265;
  405. say = 250;
  406.  
  407. sattpos = 2;
  408. sattx = off+265;
  409. satty = 305;
  410.  
  411.  
  412. for (x=0;x<8;x++)
  413.     {
  414.     f[x].x = off+525+Random(24.0)-12;
  415.     f[x].y = 170+Random(14.0)-7;
  416.     f[x].pos = Random(31.0);
  417.     }
  418.  
  419. for (x=0;x<4;x++)
  420.     {
  421.     m[x].x = off+265+Random(24.0)-12;
  422.     m[x].y = 365+Random(14.0)-7;
  423.     m[x].rot = Random(3.0);
  424.     }
  425.  
  426.  
  427. in.KEY = NULL;
  428.  
  429.  
  430. timedelay(2000);  /* prime the pump */
  431.  
  432. while (in.KEY == NULL)
  433. {
  434. bit^=1;
  435. SetAPen(rp1[bit],1);
  436. SetWrMsk(rp1[x],0xfd);
  437.  
  438. for (x=0;x<9;x++)
  439.     {
  440.     if (++spos[x] > 31) spos[x] = 0;
  441.     wi = id[simage[x]].wi;
  442.     he = id[simage[x]].he;
  443.     wo = 2*id[simage[x]].wo;
  444.     BltTemplate(id[simage[x]+spos[x]].data,0,wo,rp1[bit],sxx[x]-wi/2,syy[x]-he/2,wi,he);
  445.     }
  446.  
  447.  
  448. for (x=0;x<8;x++)
  449.     {
  450.     f[x].pos+=2;
  451.     if (f[x].pos > 31) f[x].pos -= 32;
  452.     wo =2*id[il.fighter+f[x].pos/2].wo;
  453.     wi =  id[il.fighter+f[x].pos/2].wi;
  454.     he =  id[il.fighter+f[x].pos/2].he;
  455.     BltTemplate(id[il.fighter+f[x].pos/2].data,0,wo,rp1[bit],f[x].x,f[x].y,wi,he);
  456.     }
  457.  
  458.  
  459. for (x=0;x<4;x++)
  460.     {
  461.     if (++m[x].rot > 3) m[x].rot = 0;
  462.     wo =2*id[il.mine+m[x].rot].wo;
  463.     wi =  id[il.mine+m[x].rot].wi;
  464.     he =  id[il.mine+m[x].rot].he;
  465.     BltTemplate(id[il.mine+m[x].rot].data,0,wo,rp1[bit],m[x].x,m[x].y,wi,he);
  466.     }
  467.  
  468. if (++sapos > 4) sapos = 0;
  469. wi = id[il.saucer+sapos].wi;
  470. he = id[il.saucer+sapos].he;
  471. wo = 2*id[il.saucer+sapos].wo;
  472. BltTemplate(id[il.saucer+sapos].data,0,wo,rp1[bit],sax,say,wi,he);
  473.  
  474. if (++sattpos > 4) sattpos = 0;
  475. wi = id[il.asaucer+sattpos].wi;
  476. he = id[il.asaucer+sattpos].he;
  477. wo = 2*id[il.asaucer+sattpos].wo;
  478. BltTemplate(id[il.asaucer+sattpos].data,0,wo,rp1[bit],sattx,satty,wi,he);
  479.  
  480. for (x=0;x<3;x++)
  481.     {
  482.     if (x == 0) if (++ap[x] > 63) ap[x] = 0;
  483.     if (x == 1) if (++ap[x] > 31) ap[x] = 0;
  484.     if (x == 2) if (++ap[x] > 15) ap[x] = 0;
  485.  
  486.     wi = id[il.asteroid[x]].wi;
  487.     he = id[il.asteroid[x]].he;
  488.     wo = 2*id[il.asteroid[x]].wo;
  489.     BltTemplate(id[il.asteroid[x]+ap[x]].data,0,wo,rp1[bit],ax[x],ay[x],wi,he);
  490.     }
  491.  
  492. if (++bp[0] > 15) bp[0] = 0;
  493. if (++bp[1] > 31) bp[1] = 0;
  494. if (++bp[2] > 15) bp[2] = 0;
  495. if (++bp[3] > 15) bp[3] = 0;
  496.  
  497. wi = id[il.box+bp[0]].wi;
  498. he = id[il.box+bp[0]].he;
  499. wo = 2*id[il.box+bp[0]].wo;
  500. BltTemplate(id[il.box+bp[0]].data,0,wo,rp1[bit],bx[0],by[0],wi,he);
  501.  
  502. wi = id[il.diamond+bp[1]].wi;
  503. he = id[il.diamond+bp[1]].he;
  504. wo = 2*id[il.diamond+bp[1]].wo;
  505. BltTemplate(id[il.diamond+bp[1]].data,0,wo,rp1[bit],bx[1],by[1],wi,he);
  506.  
  507. wi = id[il.triangle+bp[2]].wi;
  508. he = id[il.triangle+bp[2]].he;
  509. wo = 2*id[il.triangle+bp[2]].wo;
  510. BltTemplate(id[il.triangle+bp[2]].data,0,wo,rp1[bit],bx[2],by[2],wi,he);
  511.  
  512. wi = id[il.rectangle+bp[3]].wi;
  513. he = id[il.rectangle+bp[3]].he;
  514. wo = 2*id[il.rectangle+bp[3]].wo;
  515. BltTemplate(id[il.rectangle+bp[3]].data,0,wo,rp1[bit],bx[3],by[3],wi,he);
  516.  
  517.  
  518. waitfortimer();
  519. WaitBlit();
  520. changeview(bit);
  521. timedelay(control.delay);
  522.  
  523. SetWrMsk(rp1[1-bit],0xfd);
  524. SetRast(rp1[1-bit],0);
  525. }
  526.  
  527.  
  528. in.KEY=NULL;
  529. SetAPen(rp1[0],1);
  530. changeview(0);
  531. }
  532.