home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / fighter.c < prev    next >
C/C++ Source or Header  |  2011-01-05  |  6KB  |  355 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.  
  10. AllocateHyper(xx,yy)
  11. LONG xx,yy;
  12. {
  13. LONG x,num,n;
  14.  
  15. for (n=0;n<8;n++)
  16.     {
  17.     num=-1;
  18.     for(x=0;x<control.hypernum;x++)
  19.         if (h[x].flag == FALSE)
  20.             {
  21.             num = x;
  22.             break;
  23.             }
  24.  
  25.     if (num != -1)
  26.         {
  27.         h[num].flag = TRUE;
  28.         h[num].x = xx+(200*VxINC[n*4])/100;
  29.         h[num].y = yy+(150*VyINC[n*4])/100;
  30.         h[num].destx = xx;
  31.         h[num].desty = yy;
  32.         h[num].vx = (20*VxINC[n*4])/100;
  33.         h[num].vy = (15*VyINC[n*4])/100;
  34.         h[num].rot = Random(31.0);
  35.         h[num].image = il.triangle;
  36.         }
  37.     }
  38. }
  39.  
  40. UpdateHyper()
  41. {
  42. LONG n;
  43. LONG wo,he,wi;
  44. LONG pic;
  45.  
  46. for(n=0;n<control.hypernum;n++)
  47. {
  48.  
  49. if (h[n].flag != FALSE)
  50.     {
  51.     h[n].ox = h[n].x;
  52.     h[n].oy = h[n].y;
  53.     }
  54.  
  55. if (h[n].flag == TRUE)
  56.     {
  57.     h[n].x -= h[n].vx;
  58.     h[n].y -= h[n].vy;
  59.  
  60.     if (abs(h[n].x-h[n].destx)+abs(h[n].y-h[n].desty) < 20)
  61.         {
  62.         h[n].flag = LAST;
  63.         }
  64.     else
  65.         {
  66.         SetAPen(rp1[bit],1);
  67.         SetWrMsk(rp1[bit],0xfd);
  68.         if (++h[n].rot > 15) h[n].rot = 0;
  69.         pic = h[n].image+h[n].rot;
  70.         wo = 2*id[pic].wo;
  71.         wi = id[pic].wi;
  72.         he = id[pic].he;
  73.  
  74.         if ((h[n].x > gi.x1) && (h[n].x < gi.x2) &&
  75.             (h[n].y > gi.y1) && (h[n].y < gi.y2))
  76.             BltTemplate(id[pic].data,0,wo,rp1[bit],h[n].x,h[n].y,wi,he);
  77.         }
  78.     }
  79. }
  80. }
  81.  
  82. EraseHyper()
  83. {
  84. LONG x,pic;
  85.  
  86. for (x=0;x<control.hypernum;x++)
  87.     {
  88.     if (h[x].flag != FALSE)
  89.         {
  90.         SetWrMsk(rp1[1-bit],0xfd);
  91.         if (h[x].flag == LAST) h[x].flag = FALSE;
  92.         pic = h[x].image+h[x].rot;
  93.         if ((h[x].ox > gi.x1) && (h[x].ox < gi.x2) &&
  94.             (h[x].oy > gi.y1) && (h[x].oy < gi.y2))
  95.             RectFill(rp1[1-bit],h[x].ox,h[x].oy,h[x].ox+id[pic].wi,h[x].oy+id[pic].he);
  96.         }
  97.     }
  98. }
  99.  
  100.  
  101.  
  102.  
  103. UpdateDebris()
  104. {
  105. LONG wo,he,wi;
  106. LONG pic,n;
  107.  
  108. for (n=0;n<control.debrisnum;n++)
  109. {
  110. if (d[n].length >= 0)
  111.     {
  112.     d[n].ox = d[n].x;
  113.     d[n].oy = d[n].y;
  114.     }
  115.  
  116. if (d[n].length > 2)
  117.     {
  118.     if (d[n].length %6 == 0)
  119.         if (--d[n].vmax < 3) d[n].vmax = 3;
  120.  
  121.     d[n].x += (d[n].vmax*VxINC[d[n].pos])/100;
  122.     d[n].y += (d[n].vmax*VyINC[d[n].pos])/100;
  123.  
  124.     if ((d[n].x > gi.x2) || (d[n].x < gi.x1) ||
  125.         (d[n].y > gi.y2) || (d[n].y < gi.y1))
  126.         {
  127.         d[n].length = 1;
  128.         }
  129.     else
  130.         {
  131.         SetAPen(rp1[bit],1);
  132.         SetWrMsk(rp1[bit],0xfd);
  133.         if (++d[n].rot > 31) d[n].rot = 0;
  134.         if (d[n].image ==  il.line) pic = d[n].image+d[n].rot/2;
  135.         else                       pic = d[n].image+d[n].rot;
  136.         wo = 2*id[pic].wo;
  137.         wi = id[pic].wi;
  138.         he = id[pic].he;
  139.         BltTemplate(id[pic].data,0,wo,rp1[bit],d[n].x,d[n].y,wi,he);
  140.         }
  141.     }
  142. }
  143. }
  144.  
  145.  
  146. EraseDebris()
  147. {
  148. LONG x,pic;
  149.  
  150. for (x=0;x<control.debrisnum;x++)
  151.     {
  152.     if (d[x].length != 0)
  153.         {
  154.         SetWrMsk(rp1[1-bit],0xfd);
  155.         d[x].length--;
  156.         if (d[x].image ==  il.line) pic = d[x].image+d[x].rot/2;
  157.         else                       pic = d[x].image+d[x].rot;
  158.         RectFill(rp1[1-bit],d[x].ox,d[x].oy,d[x].ox+id[pic].wi,d[x].oy+id[pic].he);
  159.         }
  160.     }
  161. }
  162.  
  163.  
  164.  
  165.  
  166. AllocateDebris(xx,yy,max)
  167. LONG xx,yy,max;
  168. {
  169. LONG x,num,n;
  170.  
  171. for (n=0;n<max;n++)
  172.     {
  173.     num=-1;
  174.     for(x=0;x<control.debrisnum;x++)
  175.         if (d[x].length == 0)
  176.             {
  177.             num = x;
  178.             break;
  179.             }
  180.  
  181.     if (num != -1)
  182.         {
  183.         d[num].x = xx+Random(10.0)-5;
  184.         d[num].y = yy+Random(8.0)-4;
  185.         d[num].pos = Random(31.0);
  186.         d[num].rot = Random(7.0);
  187.         d[num].length = 48;
  188.         if (Random(100.0) < 80)
  189.             {
  190.             d[num].image = il.line;
  191.             d[num].vmax = Random(9.0)+3;
  192.             }
  193.         else
  194.             {
  195.             d[num].image = il.debris;
  196.             d[num].vmax = Random(5.0)+3;
  197.             }
  198.         }
  199.     }
  200. }
  201.  
  202.  
  203.  
  204.  
  205. UpdateFighters()
  206. {
  207. LONG wo,he,wi;
  208. LONG xx,yy;
  209. LONG shpic;
  210. LONG pic;
  211. LONG n;
  212.  
  213.  
  214. for(n=0;n<control.ftrnum;n++)
  215. {
  216. if (f[n].flight != FALSE)
  217.     {
  218.     f[n].ox = f[n].x;
  219.     f[n].oy = f[n].y;
  220.     }
  221.  
  222. if (f[n].flight == TRUE)
  223.     {
  224.     if (ship[f[n].aim].pilot == DESTROYED)
  225.         {
  226.         if (control.playernum > 1) f[n].aim = abs(/*maxplayernum*/2-control.playernum);
  227.         }
  228.     else
  229.         {
  230.         shpic = ship[f[n].aim].image+ship[f[n].aim].pos;
  231.         xx = ship[f[n].aim].x + id[shpic].wi/2 + f[n].ax;
  232.         yy = ship[f[n].aim].y + id[shpic].he/2 + f[n].ay;
  233.         
  234.         f[n].pos += detcomplexheading(0,xx,yy,f[n].x,f[n].y,f[n].pos);
  235.         if (f[n].pos > 31) f[n].pos = 0;
  236.         else
  237.         if (f[n].pos < 0) f[n].pos = 31;
  238.  
  239.         if ((xx = f[n].x) && (yy == f[n].y))
  240.             {
  241.             f[n].ax = Random(60.0)-30;
  242.             f[n].ay = Random(48.0)-24;
  243.             }
  244.         }
  245.  
  246.     f[n].x += (f[n].vmax*VxINC[f[n].pos])/100; + Random(1.0);
  247.     f[n].y += (f[n].vmax*VyINC[f[n].pos])/100; + Random(1.0);
  248.  
  249.     SetAPen(rp1[bit],2);
  250.     SetWrMsk(rp1[bit],0xfe);
  251.     pic = il.fighter+f[n].pos/2;
  252.     wo = 2*id[pic].wo;
  253.     wi = id[pic].wi;
  254.     he = id[pic].he;
  255.  
  256.     if (f[n].x+wi+1 >= gi.x2) f[n].x = gi.x1+1;
  257.     if (f[n].x      <= gi.x1) f[n].x = gi.x2-wi-1;
  258.     if (f[n].y+he+1 >= gi.y2) f[n].y = gi.y1+1;
  259.     if (f[n].y      <= gi.y1) f[n].y = gi.y2-he-1;
  260.  
  261.     BltTemplate(id[pic].data,0,wo,rp1[bit],f[n].x,f[n].y,wi,he);
  262.     }
  263. }
  264. }
  265.  
  266.  
  267. EraseFighters()
  268. {
  269. LONG x;
  270.  
  271. control.fighter = FALSE;
  272. for (x=0;x<control.ftrnum;x++)
  273.     if (f[x].flight == TRUE)
  274.         {
  275.         control.fighter = TRUE;
  276.         break;
  277.         }
  278.  
  279. for (x=0;x<control.ftrnum;x++)
  280.     {
  281.     SetWrMsk(rp1[1-bit],0xfe);
  282.     if (f[x].flight != FALSE)
  283.         RectFill(rp1[1-bit],f[x].ox,f[x].oy,f[x].ox+id[il.fighter+f[x].pos/2].wi,f[x].oy+id[il.fighter+f[x].pos/2].he);
  284.  
  285.     if (f[x].flight == LAST) f[x].flight = FALSE;
  286.     }
  287. }
  288.  
  289.  
  290.  
  291.  
  292. DrawFighterFire()
  293. {
  294. LONG dx,dy;
  295. LONG n;
  296.  
  297. for(n=0;n<control.ftrnum;n++)
  298. {
  299. if (f[n].flight == TRUE) 
  300. {
  301. if ((f[n].fire == FALSE) && (ship[f[n].aim].pilot != DESTROYED))
  302.     {
  303.     dx = abs(f[n].x - ship[f[n].aim].x);
  304.     dy = abs(f[n].y - ship[f[n].aim].y);
  305.     if (((dx+dy) < 60) && (--f[n].delay <= 0))
  306.         {
  307.         Firehit(f[n].aim,1,2);
  308.         f[n].fdelay = 5;
  309.         f[n].delay = 30;
  310.         f[n].fire = TRUE;
  311.         }
  312.     }
  313. else
  314.     {
  315.     f[n].ox1 = f[n].x1;
  316.     f[n].oy1 = f[n].y1;
  317.     f[n].ox2 = f[n].x2;
  318.     f[n].oy2 = f[n].y2;
  319.     }
  320.  
  321. if (f[n].fire == TRUE)
  322.     {
  323.     f[n].x1 = f[n].x + id[il.fighter+f[n].pos/2].wi/2;
  324.     f[n].y1 = f[n].y + id[il.fighter+f[n].pos/2].he/2;
  325.     f[n].x2 = ship[f[n].aim].x + id[ship[f[n].aim].image+ship[f[n].aim].pos].wi/2;
  326.     f[n].y2 = ship[f[n].aim].y + id[ship[f[n].aim].image+ship[f[n].aim].pos].he/2;
  327.  
  328.     SetAPen(rp1[bit],1);
  329.     SetWrMsk(rp1[bit],0xfd);
  330.     Move(rp1[bit],f[n].x1,f[n].y1);
  331.     Draw(rp1[bit],f[n].x2,f[n].y2);
  332.     }
  333. }
  334. }
  335. }
  336.  
  337. EraseFighterFire()
  338. {
  339. LONG n;
  340.  
  341. for(n=0;n<control.ftrnum;n++)
  342. {
  343. if (f[n].fire != FALSE)
  344.     {
  345.     if (f[n].fire == LAST) f[n].fire = FALSE;
  346.     else
  347.     if (--f[n].fdelay == 0) f[n].fire = LAST;
  348.     
  349.     SetWrMsk(rp1[1-bit],0xfd);
  350.     Move(rp1[1-bit],f[n].ox1,f[n].oy1);
  351.     Draw(rp1[1-bit],f[n].ox2,f[n].oy2);
  352.     }
  353. }
  354. }
  355.