home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / cruiser.c < prev    next >
C/C++ Source or Header  |  2010-01-19  |  5KB  |  252 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. UpdateMCruiser(n)
  11. LONG n;
  12. {
  13. LONG direction;
  14. LONG relpos;
  15. LONG dx,dy;
  16.  
  17. ship[n].ox = ship[n].x;
  18. ship[n].oy = ship[n].y;
  19.  
  20. if (ship[n].pilot == COMPUTER)
  21. {
  22. ship[n].x += (ship[n].vmax*VxINC[ship[n].pos])/100;
  23. ship[n].y += (ship[n].vmax*VyINC[ship[n].pos])/100;
  24.  
  25. if (ship[n].x > gi.x2)     ship[n].x = gi.x1;
  26. if (ship[n].x < gi.x1)     ship[n].x = gi.x2;
  27. if (ship[n].y > gi.y2-10) ship[n].y = gi.y1;
  28. if (ship[n].y < gi.y1)     ship[n].y = gi.y2-10;
  29.  
  30. if (ship[ship[n].aim].pilot == DESTROYED)
  31.     {
  32.     if (++ship[n].aim >= control.playernum) ship[n].aim = 0;
  33.     }
  34. else
  35.     {
  36.     direction = detcomplexheading(n,ship[ship[n].aim].x,ship[ship[n].aim].y,ship[n].x,ship[n].y,ship[n].pos);
  37.  
  38.     dx = abs(ship[n].x - ship[ship[n].aim].x);
  39.     dy = abs(ship[n].y - ship[ship[n].aim].y);
  40.     if (dx+dy < 100)
  41.         {
  42.         relpos = ship[n].pos + direction;
  43.         ship[ship[n].aim].vx+=VxINC[relpos]; 
  44.         ship[ship[n].aim].vy+=VyINC[relpos];
  45.         }
  46.     else
  47.     if (dx+dy < 50)
  48.         {
  49.         relpos = ship[n].pos + direction;
  50.         ship[ship[n].aim].vx+=2*VxINC[relpos]; 
  51.         ship[ship[n].aim].vy+=2*VyINC[relpos];
  52.         }
  53.  
  54.     if (++ship[n].turn > ship[n].man)
  55.         {
  56.         ship[n].pos+=sign(direction);
  57.         if (ship[n].pos > 31)  ship[n].pos= 0;
  58.         if (ship[n].pos <  0)  ship[n].pos=31;
  59.         ship[n].turn = 0;
  60.         }
  61.     }
  62.  
  63.  
  64. todrawlist(ship[n].image+ship[n].pos,ship[n].x,ship[n].y,0xfe,2);
  65. }
  66. }
  67.  
  68.  
  69.  
  70.  
  71. UpdateXCruiser(n)
  72. LONG n;
  73. {
  74. LONG direction;
  75.  
  76. ship[n].ox = ship[n].x;
  77. ship[n].oy = ship[n].y;
  78.  
  79. if (ship[n].pilot == COMPUTER)
  80. {
  81. ship[n].x += (ship[n].vmax*VxINC[ship[n].pos])/100;
  82. ship[n].y += (ship[n].vmax*VyINC[ship[n].pos])/100;
  83.  
  84. if (ship[n].x > gi.x2)     ship[n].x = gi.x1;
  85. if (ship[n].x < gi.x1)     ship[n].x = gi.x2;
  86. if (ship[n].y > gi.y2-10) ship[n].y = gi.y1;
  87. if (ship[n].y < gi.y1)     ship[n].y = gi.y2-10;
  88.  
  89. if (ship[ship[n].aim].pilot == DESTROYED)
  90.     {
  91.     if (++ship[n].aim >= control.playernum) ship[n].aim = 0;
  92.     }
  93. else
  94.     {
  95.     direction = detcomplexheading(n,ship[ship[n].aim].x,ship[ship[n].aim].y,ship[n].x,ship[n].y,ship[n].pos);
  96.     if (direction == 0)
  97.         {
  98.         if (++ship[n].fdelay > ship[n].frate)
  99.             {
  100.             InitDoubleFire(n);
  101.             ship[n].fdelay = 0;
  102.             }
  103.         }
  104.     else
  105.     if (++ship[n].turn > ship[n].man)
  106.         {
  107.         ship[n].pos+=sign(direction);
  108.         if (ship[n].pos > 31)  ship[n].pos= 0;
  109.         if (ship[n].pos <  0)  ship[n].pos=31;
  110.         ship[n].turn = 0;
  111.         }
  112.  
  113.     if ((abs(direction)<6) && (++ship[n].pdelay > ship[n].prate))
  114.         {
  115.         InitPlasmaShotgun(n);
  116.         ship[n].pdelay = 0;
  117.         }
  118.     }
  119.  
  120. todrawlist(ship[n].image+ship[n].pos,ship[n].x,ship[n].y,0xfe,2);
  121. }
  122. }
  123.  
  124.  
  125. InitPlasmaShotgun(n)
  126. LONG n;
  127. {
  128. LONG x,pos;
  129.  
  130. for(x=0;x<3;x++)
  131.     {
  132.     pos = ship[n].pos+Random(2.0)-1;
  133.     if (pos > 31) pos = pos-31;
  134.     else
  135.     if (pos < 0)  pos = pos+32;
  136.  
  137.     ship[n].photI[x].xp = ship[n].x+id[ship[n].image].wi/2;
  138.     ship[n].photI[x].yp = ship[n].y+id[ship[n].image].he/2;
  139.     ship[n].photI[x].vx = ship[n].pvmax+Random(6.0)-3;
  140.     ship[n].photI[x].vy = ship[n].pvmax+Random(6.0)-3;
  141.     ship[n].photI[x].pos = pos;
  142.     ship[n].photI[x].range = ship[n].prange;
  143.     ship[n].photI[x].image = ship[n].pimage;
  144.     ship[n].photI[x].type = DIRECT;
  145.     ship[n].photI[x].wrap = TRUE;
  146.     ship[n].photI[x].flight = TRUE;
  147.     }
  148. }
  149.  
  150.  
  151.  
  152. UpdateCruiser(n)
  153. LONG n;
  154. {
  155. LONG direction;
  156.  
  157. ship[n].ox = ship[n].x;
  158. ship[n].oy = ship[n].y;
  159.  
  160. if (ship[n].pilot == COMPUTER)
  161.     {
  162.     moveenemy(n);
  163.  
  164.     if (ship[ship[n].aim].pilot == DESTROYED)
  165.         {
  166.         if (++ship[n].aim >= control.playernum) ship[n].aim = 0;
  167.         }
  168.     else
  169.     if (++ship[n].turn > ship[n].man)
  170.         {
  171.         direction = detcomplexheading(n,ship[ship[n].aim].x,ship[ship[n].aim].y,ship[n].x,ship[n].y,ship[n].pos);
  172.  
  173.         if (ship[n].ftype > 0) Init360Fire(n,ship[n].pos+direction);
  174.  
  175.         if (direction == 0)
  176.             {
  177.             if (ship[n].ftype == 0)
  178.                 if (++ship[n].fdelay > ship[n].frate) InitFire(n);
  179.             }
  180.         else
  181.             {
  182.  
  183.             if ( abs(direction) < 6)
  184.                 if (ship[n].ftype != 2) InitPlasmaBall(n);
  185.                 else                    InitSidePlasmaBall(n);
  186.  
  187.             direction = sign(direction);
  188.             ship[n].pos+=direction;
  189.  
  190.             if (ship[n].pos > 31)  ship[n].pos= 0;
  191.             if (ship[n].pos <  0)  ship[n].pos=31;
  192.             }
  193.  
  194.         ship[n].turn = 0;
  195.         }
  196.     enemythrust(n);
  197.  
  198.  
  199.     todrawlist(ship[n].image+ship[n].pos,ship[n].x,ship[n].y,0xfe,2);
  200.     }
  201. }
  202.  
  203. enemythrust(n)
  204. LONG n;
  205. {
  206. LONG dist,dx,dy;
  207.  
  208. dx = abs(ship[ship[n].aim].x-ship[n].x);
  209. dy = abs(ship[ship[n].aim].y-ship[n].y);
  210.  
  211. dist = dx+dy;
  212.  
  213. if (dist > 350)
  214.     {
  215.     ship[n].vx+=2*VxINC[ship[n].pos];
  216.     ship[n].vy+=2*VyINC[ship[n].pos];
  217.     }
  218. else
  219. if (dist > 50)
  220.     {
  221.     ship[n].vx+=VxINC[ship[n].pos];
  222.     ship[n].vy+=VyINC[ship[n].pos];
  223.     }
  224.  
  225. if (ship[n].vx> ship[n].vmax*100) ship[n].vx= ship[n].vmax*100;
  226. if (ship[n].vx<-ship[n].vmax*100) ship[n].vx=-ship[n].vmax*100;
  227. if (ship[n].vy > ship[n].vmax*100) ship[n].vy = ship[n].vmax*100;
  228. if (ship[n].vy <-ship[n].vmax*100) ship[n].vy =-ship[n].vmax*100;
  229. }
  230.  
  231.  
  232.  
  233.  
  234. moveenemy(n)
  235. LONG n;
  236. {
  237. LONG wi,he;
  238.  
  239. ship[n].x += ship[n].vx/100;
  240. ship[n].y += ship[n].vy/100;
  241.  
  242. wi = id[ship[n].image].wi+1;
  243. he = id[ship[n].image].he+1;
  244.  
  245. if (ship[n].x+wi >= gi.x2) ship[n].x = gi.x1+1;
  246. else
  247. if (ship[n].x    <= gi.x1) ship[n].x = gi.x2-wi;
  248. if (ship[n].y+he >= gi.y2) ship[n].y = gi.y1+1;
  249. else
  250. if (ship[n].y    <= gi.y1) ship[n].y = gi.y2-he;
  251. }
  252.