home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098sub.adf / asteroids2.LZX / asteroids2 / rotx / collision.c < prev    next >
C/C++ Source or Header  |  2010-01-06  |  8KB  |  408 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3. #include <stdio.h>
  4. #include <h/rot.h>
  5. #include <h/extern.h>
  6.  
  7.  
  8. CollisionFireSaucer(n,x,xx,yy)
  9. LONG n,x,xx,yy;
  10. {
  11. LONG wi,he;
  12.  
  13. if (saucer.flag == TRUE)
  14. {
  15. wi = id[saucer.image+saucer.rot].wi;
  16. he = id[saucer.image+saucer.rot].he;
  17.  
  18. if ( (xx > saucer.x)    &&
  19.     (xx < saucer.x+wi) &&
  20.     (yy > saucer.y)    &&
  21.     (yy < saucer.y+he))
  22.         {
  23.         makesound(3,3);
  24.         ship[n].shotI[x].flight = LAST;
  25.         saucer.flag = LAST;
  26.         if (ship[n].pilot == HUMAN)
  27.             {
  28.             if (saucer.type == 0) IncreaseScore(n,500);
  29.             else                  IncreaseScore(n,1500);
  30.             }
  31.         AllocateDebris(xx+wi/2,yy+wi/2,control.standarddebris);
  32.         AllocateExplosion(xx+wi/2,yy+he/2,7);
  33.         AllocateBoxes(xx,yy,1);
  34.         }
  35. }
  36. }
  37.  
  38.  
  39. CollisionFireAsteroids(n,x,xx,yy)
  40. LONG n,x,xx,yy;
  41. {
  42. LONG y;
  43. LONG wi,he;
  44.  
  45. for(y=0;y<control.asteroidnum;y++)
  46.     {
  47.     wi = id[il.asteroid[a[y].size]].wi;
  48.     he = id[il.asteroid[a[y].size]].he;
  49.  
  50.     if (a[y].flag == TRUE)
  51.         {
  52.         if (!((xx < a[y].x) || (xx > a[y].x+wi) ||
  53.              (yy < a[y].y) || (yy > a[y].y+he)))
  54.                 {
  55.                 ship[n].shotI[x].flight = LAST;
  56.                 if (ship[n].pilot == HUMAN) IncreaseScore(n,50*(a[y].size+1));
  57.                 AsteroidExplosion(y,a[y].x+wi/2,a[y].y+he/2);
  58.                 break;
  59.                 }
  60.         }
  61.     }
  62. }
  63.  
  64.  
  65.  
  66. CollisionFireFighters(n,x,xx,yy)
  67. LONG n,x,xx,yy;
  68. {
  69. LONG y;
  70.  
  71. for(y=0;y<control.ftrnum;y++)
  72.     {
  73.     if (f[y].flight == TRUE)
  74.         {
  75.         if ((xx > f[y].x) && (xx < f[y].x+id[il.fighter+f[y].pos/4].wi) &&
  76.             (yy > f[y].y) && (yy < f[y].y+id[il.fighter+f[y].pos/4].he))
  77.                 {
  78.                 ship[n].shotI[x].flight = LAST;
  79.                 if (ship[n].pilot == HUMAN) IncreaseScore(n,50);
  80.                 makesound(13,2);
  81.                 AllocateExplosion(xx,yy,5);
  82.                 f[y].flight = LAST;
  83.                 break;
  84.                 }
  85.         }
  86.     }
  87. }
  88.  
  89. CollisionPhotonFighters(n,x)
  90. LONG n,x;
  91. {
  92. LONG xx,yy,y;
  93.  
  94. xx = ship[n].photI[x].xp+2;
  95. yy = ship[n].photI[x].yp+2;
  96.  
  97. for(y=0;y<control.ftrnum;y++)
  98.     {
  99.     if (f[y].flight == TRUE)
  100.         {
  101.         if ((xx > f[y].x) && (xx < f[y].x+id[il.fighter+f[y].pos/4].wi) &&
  102.             (yy > f[y].y) && (yy < f[y].y+id[il.fighter+f[y].pos/4].he))
  103.                 {
  104.                 if (ship[n].pilot == HUMAN) IncreaseScore(n,50);
  105.                 makesound(13,2);
  106.                 AllocateExplosion(xx,yy,5);
  107.                 f[y].flight = LAST;
  108.                 break;
  109.                 }
  110.         }
  111.     }
  112. }
  113.  
  114.  
  115. CollisionBattleshipFireShips(n,x,xx,yy)
  116. LONG n,x,xx,yy;
  117. {
  118. LONG y,wi,he;
  119.  
  120. for(y=0;y<control.playernum;y++)
  121.     if (ship[y].pilot != DESTROYED)
  122.         {
  123.         wi = id[ship[y].image+ship[y].pos].wi;
  124.         he = id[ship[y].image+ship[y].pos].he;
  125.         if ( (xx > ship[y].x) && (xx < ship[y].x+wi) &&
  126.             (yy > ship[y].y) &&    (yy < ship[y].y+he))
  127.                 {
  128.                 bs[n].shotI[x].flight = LAST;
  129.                 Firehit(y,bs[n].fdam,7);
  130.                 break;
  131.                 }
  132.         }
  133. }
  134.  
  135.  
  136. CollisionFireShips(n,x,xx,yy)
  137. LONG n,x,xx,yy;
  138. {
  139. LONG y;
  140. LONG wi,he;
  141.  
  142. for(y=0;y<control.maxenemynum+control.playernum;y++)
  143.     {
  144.     if ((ship[y].pilot != DESTROYED) && (n != y))
  145.     if ((ship[y].pilot != ship[n].pilot) ||
  146.        ((control.playmode == 1) && (ship[y].pilot == HUMAN) && (ship[n].pilot == HUMAN)))
  147.         {
  148.         wi = id[ship[y].image+ship[y].pos].wi;
  149.         he = id[ship[y].image+ship[y].pos].he;
  150.         if ( (xx > ship[y].x) && (xx < ship[y].x+wi) &&
  151.             (yy > ship[y].y) &&    (yy < ship[y].y+he))
  152.                 {
  153.                 ship[n].shotI[x].flight = LAST;
  154.  
  155.                 if (ship[n].pilot == HUMAN)
  156.                     {
  157.                     IncreaseScore(n,ship[y].pointvalue);
  158.                     }
  159.                 Firehit(y,ship[n].fdam,7);
  160.                 break;
  161.                 }
  162.         }
  163.     }
  164. }
  165.  
  166.  
  167. CollisionPhotonShips(n,x)
  168. LONG n,x;
  169. {
  170. LONG y;
  171. LONG wi,he;
  172.  
  173. for(y=0;y<control.maxenemynum+control.playernum;y++)
  174.     {
  175.     if ((y == ship[n].aim) || (ship[n].pilot == HUMAN))
  176.     if ((ship[y].pilot != DESTROYED) && (n != y))
  177.     if ((ship[y].pilot != ship[n].pilot) ||
  178.        ((control.playmode == 1) && (ship[y].pilot == HUMAN) && (ship[n].pilot == HUMAN)))
  179.         {
  180.         wi = id[ship[n].photI[x].image].wi;
  181.         he = id[ship[n].photI[x].image].he;
  182.  
  183.         if ( (ship[n].photI[x].xp     < ship[y].x+id[ship[y].image].wi)  &&
  184.             (ship[n].photI[x].xp+wi  > ship[y].x)                     &&
  185.             (ship[n].photI[x].yp     < ship[y].y+id[ship[y].image].he)  &&
  186.             (ship[n].photI[x].yp+he  > ship[y].y))
  187.                 {
  188.                 ship[n].photI[x].flight = LAST;
  189.  
  190.                 if (ship[n].pilot == HUMAN)
  191.                     {
  192.                     IncreaseScore(n,ship[y].pointvalue);
  193.                     }
  194.                 Firehit(y,ship[n].pdam,7);
  195.                 break;
  196.                 }
  197.         }
  198.     }
  199. }
  200.  
  201.  
  202.  
  203. CollisionPhotonSaucer(n,x)
  204. LONG n,x;
  205. {
  206. LONG xx,yy;
  207. LONG wi,he;
  208.  
  209. if (saucer.flag == TRUE)
  210. {
  211. xx = ship[n].photI[x].xp;
  212. yy = ship[n].photI[x].yp;
  213. wi = id[ship[n].photI[x].image].wi;
  214. he = id[ship[n].photI[x].image].he;
  215.  
  216. if ( (xx     < saucer.x+id[saucer.image].wi)  &&
  217.     (xx+wi  > saucer.x)                      &&
  218.     (yy     < saucer.y+id[saucer.image].he)  &&
  219.     (yy+he  > saucer.y))
  220.         {
  221.         ship[n].photI[x].flight = LAST;
  222.         makesound(3,3);
  223.         if (ship[n].pilot == HUMAN)
  224.             {
  225.             if (saucer.type == 0) IncreaseScore(n,500);
  226.             else                  IncreaseScore(n,1500);
  227.             }
  228.         AllocateDebris(xx+wi/2,yy+wi/2,control.standarddebris);
  229.         AllocateExplosion(xx+wi/2,yy+he/2,7);
  230.         AllocateBoxes(xx+wi/2,yy+he/2,1);
  231.         saucer.flag = LAST;
  232.         }
  233. }
  234. }
  235.  
  236. CollisionAsteroidsShip(n,x,wi,he)
  237. LONG n,x,wi,he;
  238. {
  239. LONG offx,offy;
  240.  
  241. offx = wi/4;
  242. offy = wi/4;
  243.  
  244. if ((a[n].x+wi-offx < ship[x].x) ||
  245.     (a[n].x+offx    > ship[x].x+id[ship[x].image].wi) ||
  246.     (a[n].y+he-offy < ship[x].y) ||
  247.     (a[n].y+offy    > ship[x].y+id[ship[x].image].he))
  248.         return;
  249. else
  250.     {
  251.     DestroyShip(x);
  252.     initInput(x);
  253.     }
  254. }
  255.  
  256. CollisionPhotonAsteroids(n,x)
  257. LONG n,x;
  258. {
  259. LONG y;
  260. LONG wi,he;
  261. LONG wi2,he2;
  262. LONG xx,yy;
  263.  
  264. xx = ship[n].photI[x].xp;
  265. yy = ship[n].photI[x].yp;
  266.  
  267. for(y=0;y<control.asteroidnum;y++)
  268.     {
  269.     if (a[y].flag == TRUE)
  270.         {
  271.         wi = id[ship[n].photI[x].image].wi;
  272.         he = id[ship[n].photI[x].image].he;
  273.  
  274.         wi2 = id[il.asteroid[a[y].size]].wi;
  275.         he2 = id[il.asteroid[a[y].size]].he;
  276.  
  277.         if ( (xx     < a[y].x+2*wi2/3) &&
  278.             (xx+wi  > a[y].x+wi2/3)     &&
  279.             (yy     < a[y].y+2*he2/3) &&
  280.             (yy+he  > a[y].y+he2/3))
  281.                 {
  282.                 ship[n].photI[x].flight = LAST;
  283.                 if (ship[n].pilot == HUMAN) IncreaseScore(n,50*(a[y].size+1));
  284.                 AsteroidExplosion(y,a[y].x+id[il.asteroid[a[y].size]].wi/2,
  285.                                 a[y].y+id[il.asteroid[a[y].size]].he/2);
  286.                 break;
  287.                 }
  288.         }
  289.     }
  290. }
  291.  
  292.  
  293.  
  294.  
  295.  
  296. CollisionAsteroidsSaucer(n,wi,he)
  297. LONG n,wi,he;
  298. {
  299. if ((a[n].x < saucer.x + wi -2) &&
  300.     (a[n].x + id[il.asteroid[a[n].size]].wi > saucer.x +2) &&
  301.     (a[n].y < saucer.y + he -2) &&
  302.     (a[n].y + id[il.asteroid[a[n].size]].he > saucer.y +2))
  303.         {
  304.         makesound(3,3);
  305.         AllocateDebris(saucer.x+wi/2,saucer.y+he/2,control.standarddebris);
  306.         AllocateExplosion(saucer.x+wi/2,saucer.y+he/2,7);
  307.         saucer.flag = LAST;
  308.         }
  309. }
  310.  
  311.  
  312.  
  313. Firehit(n,dam,len)
  314. LONG n,dam,len;
  315. {
  316.  
  317. if (n < control.playernum) IncreaseShields(n,-dam);
  318. else ship[n].shield-=dam;
  319.  
  320. if (ship[n].shield < 0) DestroyShip(n);
  321. else    makesound(8,0);
  322.  
  323. ship[n].shieldstat=len;
  324. }
  325.  
  326.  
  327. DestroyShip(n)
  328. LONG n;
  329. {
  330. LONG xx,yy;
  331.  
  332. xx = ship[n].x+id[ship[n].image+ship[n].pos].wi/2;
  333. yy = ship[n].y+id[ship[n].image+ship[n].pos].he/2;
  334.  
  335. AllocateExplosion(xx,yy,7);
  336. AllocateDebris(xx,yy,control.standarddebris);
  337. if ((control.asize > 4) && (ship[n].pilot!=HUMAN))
  338.     {
  339.     if (ship[n].image == il.minelayer) AllocateBoxes(xx,yy,1);
  340.     else
  341.     if (ship[n].image == il.elight)     AllocateBoxes(xx,yy,2);
  342.     else                            AllocateBoxes(xx,yy,3);
  343.     }
  344.  
  345. makesound(3,3);
  346. ship[n].wait = 30;
  347. ship[n].pilot=DESTROYED;
  348.  
  349. if (n < control.playernum)
  350.     {
  351.     if (--control.fire[n] < control.weapon[n]) control.fire[n] = control.weapon[n];
  352.     if (++control.firedelay[n] > 4) control.firedelay[n] = 4;
  353.     }
  354. else 
  355.     {
  356.     control.enemynum--;
  357.     }
  358. }
  359.  
  360.  
  361. CollisionBoxShips(n)
  362. LONG n;
  363. {
  364. LONG y;
  365. LONG xx,yy;
  366. LONG wi,he;
  367.  
  368. xx = b[n].x+id[il.box+b[n].pos].wi/2;
  369. yy = b[n].y+id[il.box+b[n].pos].he/2;
  370.  
  371. for(y=0;y<control.playernum;y++)
  372.     {
  373.     wi = id[ship[y].image+ship[y].pos].wi;
  374.     he = id[ship[y].image+ship[y].pos].he;
  375.     
  376.     if ( (xx > ship[y].x) && (xx < ship[y].x+wi) &&
  377.         (yy > ship[y].y) &&    (yy < ship[y].y+he))
  378.             {
  379.             if (b[n].type == 2)
  380.                 {
  381.                 makesound(11,2);
  382.                 IncreaseShields(y,50);
  383.                 }
  384.             else
  385.             if (b[n].type == 1)
  386.                 {
  387.                 makesound(9,2);
  388.                 ++control.fire[y];
  389.                 }
  390.             else
  391.             if (b[n].type == 3)
  392.                 {
  393.                 makesound(9,2);
  394.                 if (--control.firedelay[y] < 0) control.firedelay[y] = 0;
  395.                 }
  396.             else
  397.             if (b[n].type == 0)
  398.                 {
  399.                 makesound(12,2);
  400.                 IncreaseLives(y,1);
  401.                 }
  402.  
  403.             b[n].length = 2;
  404.             break;
  405.             }
  406.     }
  407. }
  408.