home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / mine.c < prev    next >
C/C++ Source or Header  |  2011-01-08  |  3KB  |  155 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. AllocateMine(xx,yy)
  11. LONG xx,yy;
  12. {
  13. LONG x,num=-1;
  14.  
  15. for(x=0;x<control.minenum;x++)
  16.     if (m[x].flight == FALSE)
  17.         {
  18.         num = x;
  19.         break;
  20.         }
  21.  
  22. if (num != -1)
  23.     {
  24.     m[num].x = xx;
  25.     m[num].y = yy;
  26.     m[num].rot = Random(15.0);
  27.     m[num].flight = TRUE;
  28.     }
  29. }
  30.  
  31.  
  32. UpdateMines()
  33. {
  34. LONG wo,he,wi;
  35. LONG x,dx,dy;
  36. LONG n;
  37.  
  38.  
  39. for (n=0;n<control.minenum;n++)
  40. {
  41. if (m[n].flight == TRUE)
  42.     {
  43.     for (x=0;x<control.playernum;x++)
  44.         if (ship[x].pilot != DESTROYED)
  45.             {
  46.             dx = abs(m[n].x - ship[x].x);
  47.             dy = abs(m[n].y - ship[x].y);
  48.  
  49.             if (dx+dy < 40)
  50.                 {
  51.                 Firehit(x,50,10);
  52.                 AllocateExplosion(m[n].x,m[n].y,6);
  53.                 m[n].flight = LAST;
  54.                 }
  55.             }
  56.  
  57.     if (m[n].flight == TRUE)
  58.         {
  59.         SetAPen(rp1[bit],2);
  60.         SetWrMsk(rp1[bit],0xfe);
  61.         if (++m[n].rot > 3) m[n].rot = 0;
  62.         wo = 2*id[il.mine+m[n].rot].wo;
  63.         wi = id[il.mine+m[n].rot].wi;
  64.         he = id[il.mine+m[n].rot].he;
  65.         BltTemplate(id[il.mine+m[n].rot].data,0,wo,rp1[bit],m[n].x,m[n].y,wi,he);
  66.         }
  67.     }
  68. }
  69. }
  70.  
  71.  
  72. EraseMines()
  73. {
  74. LONG x;
  75.  
  76. for (x=0;x<control.minenum;x++)
  77.     {
  78.     SetWrMsk(rp1[1-bit],0xfe);
  79.     if (m[x].flight != FALSE)
  80.         RectFill(rp1[1-bit],m[x].x,m[x].y,m[x].x+id[il.mine+m[x].rot].wi,m[x].y+id[il.mine+m[x].rot].he);
  81.  
  82.     if (m[x].flight == LAST) m[x].flight = FALSE;
  83.     }
  84. }
  85.  
  86.  
  87. UpdateMineLayer(n)
  88. LONG n;
  89. {
  90. LONG direction;
  91. LONG wi,he,wo;
  92. LONG modpos,pic;
  93. LONG dx,dy;
  94.  
  95. ship[n].ox = ship[n].x;
  96. ship[n].oy = ship[n].y;
  97.  
  98. if (ship[n].pilot == COMPUTER)
  99. {
  100.  
  101. moveenemy(n);
  102.  
  103. ship[n].vx = ship[n].vmax*VxINC[ship[n].pos];
  104. ship[n].vy = ship[n].vmax*VyINC[ship[n].pos];
  105.  
  106. if (ship[ship[n].aim].pilot == DESTROYED)
  107.     {
  108.     if (control.playernum > 1) ship[n].aim = abs(1+control.maxplayernum-control.playernum);
  109.     }
  110. else
  111. if (++ship[n].turn > ship[n].man)
  112.     {
  113.     modpos = ship[n].pos+16;
  114.     if (modpos > 31) modpos-=31;
  115.  
  116.     direction = detcomplexheading(n,ship[ship[n].aim].x,ship[ship[n].aim].y,ship[n].x,ship[n].y,modpos);
  117.  
  118.     if (--ship[n].pdelay <= 0)
  119.         {
  120.         if (--ship[n].pnum < 0)
  121.             {
  122.             ship[n].shield = 0;
  123.             ship[n].pilot=DESTROYED;
  124.             control.enemynum--;
  125.             }
  126.         else
  127.             {
  128.             ship[n].pdelay = 20;
  129.             AllocateMine(ship[n].x+id[ship[n].image].wi/2,ship[n].y+id[ship[n].image].he/2);
  130.             }
  131.         }
  132.  
  133.     dx = abs(ship[ship[n].aim].x-ship[n].x);
  134.     dy = abs(ship[ship[n].aim].y-ship[n].y);
  135.     if ((direction != 0) && (dx+dy < 200))
  136.         {
  137.         direction = sign(direction);
  138.         ship[n].pos+=direction;
  139.         if (ship[n].pos > 31)  ship[n].pos= 0;
  140.         if (ship[n].pos <  0)  ship[n].pos=31;
  141.         }
  142.  
  143.     ship[n].turn = 0;
  144.     }
  145.  
  146. SetAPen(rp1[bit],2);
  147. SetWrMsk(rp1[bit],0xfe);
  148. pic = ship[n].image+ship[n].pos;
  149. wi = id[pic].wi;
  150. he = id[pic].he;
  151. wo = 2*id[pic].wo;
  152. BltTemplate(id[pic].data,0,wo,rp1[bit],ship[n].x,ship[n].y,wi,he);
  153. }
  154. }
  155.