home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / asteroids.c < prev    next >
C/C++ Source or Header  |  2010-05-07  |  2KB  |  116 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3. #include <graphics/gfxmacros.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <h/rot.h>
  7. #include <h/extern.h>
  8.  
  9.  
  10. UpdateAsteroid(n)
  11. LONG n;
  12. {
  13. LONG x;
  14. LONG wi,he;
  15.  
  16. wi = id[il.asteroid[a[n].size]].wi;
  17. he = id[il.asteroid[a[n].size]].he;
  18.  
  19. a[n].ox = a[n].x;
  20. a[n].oy = a[n].y;
  21.  
  22. a[n].x += a[n].vx;
  23. a[n].y += a[n].vy;
  24.  
  25. if (a[n].flag == LAST) return;
  26.  
  27. for(x=0;x<control.playernum;x++)
  28.     if (ship[x].pilot != DESTROYED) CollisionAsteroidsShip(n,x,wi,he);
  29.  
  30. if (saucer.flag == TRUE) CollisionAsteroidsSaucer(n,wi,he);
  31.  
  32. if (a[n].x+wi/2 > gi.x2) a[n].x = gi.x1-wi/2;
  33. if (a[n].x+wi/2 < gi.x1) a[n].x = gi.x2-wi/2;
  34. if (a[n].y+he/2 > gi.y2) a[n].y = gi.y1-he/2;
  35. if (a[n].y+he/2 < gi.y1) a[n].y = gi.y2-he/2;
  36.  
  37. a[n].rot += a[n].dir;
  38. if (a[n].size == 2)
  39.     {
  40.     if (a[n].rot > 15) a[n].rot = 0;
  41.     if (a[n].rot < 0)  a[n].rot = 15;
  42.     }
  43. else
  44. if (a[n].size == 1)
  45.     {
  46.     if (a[n].rot > 31) a[n].rot = 0;
  47.     if (a[n].rot < 0)  a[n].rot = 31;
  48.     }
  49. else
  50. if (a[n].size == 0)
  51.     {
  52.     if (a[n].rot > 63) a[n].rot = 0;
  53.     if (a[n].rot < 0)  a[n].rot = 63;
  54.     }
  55.  
  56. todrawlist(il.asteroid[a[n].size]+a[n].rot,a[n].x,a[n].y,0xfd,1);
  57. }
  58.  
  59.  
  60. EraseAsteroids()
  61. {
  62. LONG x;
  63.  
  64. for (x=0;x<control.asteroidnum;x++)
  65.     if (a[x].flag != FALSE)
  66.         {
  67.         SetWrMsk(rp1[1-bit],0xfd);
  68.         RectFill(rp1[1-bit],a[x].ox,a[x].oy,a[x].ox+45,a[x].oy+45);
  69.         if (a[x].flag == LAST) a[x].flag = FALSE;
  70.         }
  71. }
  72.  
  73.  
  74. AsteroidExplosion(num,xx,yy)
  75. LONG num,xx,yy;
  76. {
  77. LONG num2=-1,x;
  78.  
  79. makesound(2,2);
  80. AllocateExplosion(xx,yy,5);
  81.  
  82. if (++a[num].size > 2)
  83.     {
  84.     a[num].flag = LAST;
  85.     }
  86. else
  87.     {
  88.     for(x=0;x<control.asteroidnum;x++)
  89.         if (a[x].flag == FALSE)
  90.             {
  91.             num2 = x;
  92.             break;
  93.             }
  94.  
  95.     a[num2].x = a[num].x;
  96.     a[num2].y = a[num].y;
  97.     a[num2].size = a[num].size;
  98.     a[num2].flag = TRUE;
  99.  
  100.     if (Random(100.0) > 50)     a[num2].dir = 1;
  101.     else                    a[num2].dir = -1;
  102.  
  103.     a[num].vx += Random((DOUBLE)(2*(control.difficulty+2)))-(control.difficulty+2);
  104.     a[num].vy += Random((DOUBLE)(2*(control.difficulty+2)))-(control.difficulty+2);
  105.  
  106.     while ((a[num].vx == 0) && (a[num].vy == 0))
  107.         {
  108.         a[num].vx += Random(8.0)-4;
  109.         a[num].vy += Random(8.0)-4;
  110.         }
  111.  
  112.     a[num2].vx = -a[num].vx;
  113.     a[num2].vy = -a[num].vy;
  114.     }
  115. }
  116.