home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / saucer.c < prev    next >
C/C++ Source or Header  |  2009-01-21  |  5KB  |  230 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. #define MWDEBUG 1
  10. #include "sc:extras/memlib/memwatch.h"
  11. */
  12.  
  13. InitSmartSaucerFire()
  14. {
  15. LONG x,num=-1;
  16. LONG random,aim;
  17. DOUBLE aimfp;
  18.  
  19. for(x=0;x<saucer.fnum;x++)
  20.     if (saucer.photI[x].flight == FALSE)
  21.         {
  22.         num = x;
  23.         break;
  24.         }
  25.  
  26. if (num != -1)
  27.     {
  28.     aimfp = control.playernum+control.enemynum;
  29.     aim = Random(aimfp);
  30.  
  31.     random = determineheading(ship[aim].x,ship[aim].y,saucer.x,saucer.y,0);
  32.     if (random < 0) random+=32;
  33.  
  34.     makesound(4,0);
  35.     saucer.photI[x].xp = saucer.x+id[saucer.image+saucer.rot].wi/2;
  36.     saucer.photI[x].yp = saucer.y+id[saucer.image+saucer.rot].he/2;
  37.     saucer.photI[x].vx = 12*VxINC[random];
  38.     saucer.photI[x].vy = 12*VyINC[random];
  39.     saucer.photI[x].rot = 0;
  40.     saucer.photI[x].flight = TRUE;
  41.     }
  42. }
  43.  
  44.  
  45. InitSaucerFire()
  46. {
  47. LONG x,num=-1;
  48. LONG random;
  49.  
  50. for(x=0;x<saucer.fnum;x++)
  51.     if (saucer.photI[x].flight == FALSE)
  52.         {
  53.         num = x;
  54.         break;
  55.         }
  56.  
  57. if (num != -1)
  58.     {
  59.     random = Random(31.0);
  60.     makesound(4,0);
  61.     saucer.photI[x].xp = saucer.x+id[saucer.image+saucer.rot].wi/2;
  62.     saucer.photI[x].yp = saucer.y+id[saucer.image+saucer.rot].he/2;
  63.     saucer.photI[x].vx = 12*VxINC[random];
  64.     saucer.photI[x].vy = 12*VyINC[random];
  65.     saucer.photI[x].rot = 0;
  66.     saucer.photI[x].flight = TRUE;
  67.     }
  68. }
  69.  
  70.  
  71.  
  72. DrawSaucerFire()
  73. {
  74. LONG x,y;
  75.  
  76. for(x=0;x<saucer.fnum;x++)
  77.     {
  78.     if (saucer.photI[x].flight != FALSE)
  79.         {
  80.         for(y=0;y<control.playernum+control.enemynum;y++)
  81.             {
  82.             if (ship[y].pilot != DESTROYED)
  83.             if ( (saucer.photI[x].xp + 2 > ship[y].x)    &&
  84.                 (saucer.photI[x].xp + 2 < ship[y].x+id[ship[y].image+ship[y].pos].wi) &&
  85.                 (saucer.photI[x].yp + 2 > ship[y].y)    &&
  86.                 (saucer.photI[x].yp + 2 < ship[y].y+id[ship[y].image+ship[y].pos].he))
  87.                     {
  88.                     if (ship[y].pilot == HUMAN) saucer.haltfire = TRUE;
  89.                     saucer.photI[x].flight = LAST;
  90.                     Firehit(y,300,8);
  91.                     break;
  92.                     }
  93.             }
  94.  
  95.         for(y=0;y<control.asteroidnum;y++)
  96.             {
  97.             if (a[y].flag == TRUE)
  98.                 {
  99.                 if ( (saucer.photI[x].xp + 2 > a[y].x)    &&
  100.                     (saucer.photI[x].xp + 2 < a[y].x+id[il.asteroid[a[y].size]].wi) &&
  101.                     (saucer.photI[x].yp + 2 > a[y].y)    &&
  102.                     (saucer.photI[x].yp + 2 < a[y].y+id[il.asteroid[a[y].size]].he))
  103.                         {
  104.                         saucer.photI[x].flight = LAST;
  105.                         AsteroidExplosion(y,saucer.photI[x].xp,saucer.photI[x].yp);
  106.                         break;
  107.                         }
  108.                 }
  109.             }
  110.  
  111.         saucer.photI[x].oxp = saucer.photI[x].xp;
  112.         saucer.photI[x].oyp = saucer.photI[x].yp;
  113.  
  114.         if ( (saucer.photI[x].xp > gi.x2+10) ||
  115.             (saucer.photI[x].xp < gi.x1-10) || 
  116.             (saucer.photI[x].yp > gi.y2+10) || 
  117.             (saucer.photI[x].yp < gi.y1-10))
  118.                 saucer.photI[x].flight = LAST;
  119.  
  120.  
  121.         if (saucer.photI[x].flight == TRUE)
  122.             {
  123.             if (++saucer.photI[x].rot > 15) saucer.photI[x].rot = 0;
  124.             saucer.photI[x].xp += saucer.photI[x].vx/100;
  125.             saucer.photI[x].yp += saucer.photI[x].vy/100;
  126.  
  127.             SetAPen(rp1[bit],1);
  128.             SetWrMsk(rp1[bit],0xfd);
  129.             BltTemplate(id[il.sauphot+saucer.photI[x].rot].data,0,2,rp1[bit],
  130.                               saucer.photI[x].xp,saucer.photI[x].yp,id[il.sauphot].he,id[il.sauphot].wi);
  131.             }
  132.          }
  133.     }
  134. }
  135.  
  136.  
  137.  
  138. EraseSaucerFire()
  139. {
  140. LONG x;
  141.  
  142. for(x=0;x<saucer.fnum;x++)
  143. {
  144. if (saucer.photI[x].flight != FALSE)
  145.     {
  146.     SetWrMsk(rp1[1-bit],0xfd);
  147.     RectFill(rp1[1-bit],saucer.photI[x].oxp,saucer.photI[x].oyp,
  148.             saucer.photI[x].oxp+id[il.sauphot].wi,saucer.photI[x].oyp+id[il.sauphot].he);
  149.  
  150.     if (saucer.photI[x].flight == LAST) saucer.photI[x].flight = FALSE;
  151.     }
  152. }
  153. }
  154.  
  155.  
  156. UpdateSaucer()
  157. {
  158. LONG x,wo,he,wi;
  159. LONG sapic;
  160.  
  161. if (saucer.flag != FALSE)
  162.     {
  163.     saucer.ox = saucer.x;
  164.     saucer.oy = saucer.y;
  165.     }
  166.  
  167. if (saucer.flag == TRUE)
  168.     {
  169.     sapic = saucer.image+saucer.rot;
  170.     wi = id[sapic].wi;
  171.     he = id[sapic].he;
  172.  
  173.     saucer.x += saucer.vx;
  174.     saucer.y += saucer.vy;
  175.  
  176.     for(x=0;x<control.playernum;x++)
  177.         if (ship[x].pilot != DESTROYED)
  178.             if ((saucer.x      < ship[x].x + wi -4) &&
  179.                 (saucer.x + wi > ship[x].x +4) &&
  180.                 (saucer.y      < ship[x].y + he -4) &&
  181.                 (saucer.y + he > ship[x].y +4))
  182.                     {
  183.                     DestroyShip(x);
  184.                         initInput(x);
  185.                     }
  186.  
  187.     if ((saucer.x+wi/2 > gi.x2) || (saucer.x+wi/2 < gi.x1)) saucer.flag = LAST;
  188.  
  189.     if (saucer.y+he/2 > gi.y2) saucer.y = gi.y1-he/2;
  190.     if (saucer.y+he/2 < gi.y1) saucer.y = gi.y2-he/2;
  191.  
  192.     if (saucer.delay%3 == 0)
  193.         if (++saucer.rot > 4) saucer.rot = 0;
  194.  
  195.  
  196.     if (saucer.flag == TRUE)
  197.         {
  198.         SetAPen(rp1[bit],1);
  199.         SetWrMsk(rp1[bit],0xfd);
  200.         wo = 2*id[sapic].wo;
  201.         BltTemplate(id[sapic].data,0,wo,rp1[bit],saucer.x,saucer.y,wi,he);
  202.         }
  203.     }
  204. }
  205.  
  206.  
  207. ChangeSaucerCourse()
  208. {
  209. LONG random;
  210.  
  211. random = Random(300.0);
  212. if (random > 200) saucer.vy =-3;
  213. else
  214. if (random > 100) saucer.vy = 3;
  215. else               saucer.vy = 0;
  216.  
  217. saucer.delay = Random(50.0-control.level);
  218. }
  219.  
  220.  
  221. EraseSaucer()
  222. {
  223. if (saucer.flag != FALSE)
  224.     {
  225.     SetWrMsk(rp1[1-bit],0xfd);
  226.     if (saucer.flag == LAST) saucer.flag = FALSE;
  227.     RectFill(rp1[1-bit],saucer.ox,saucer.oy,saucer.ox+id[saucer.image+saucer.rot].wi,saucer.oy+id[saucer.image+saucer.rot].he);
  228.     }
  229. }
  230.