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