home *** CD-ROM | disk | FTP | other *** search
/ ISV Strong Games / ISV_STRONG_GAMES.iso / shootemup / hive / !Hive / c / alien_hnd next >
Text File  |  2000-11-27  |  6KB  |  215 lines

  1. #include <stdlib.h>
  2.  
  3. #include "DeskLib:h.Kbd"
  4.  
  5. #include "Popcorn:h.Popcorn"
  6.  
  7. #include "h.game"
  8. #include "h.sound"
  9.  
  10. #define random(limit) (rand() % (limit))
  11.  
  12. void dull_alien_handler(struct game_object *obj, union object_flags reason, void *data)
  13. {
  14.   int turn, xvel;
  15.  
  16.   if (reason.bits.attn_gameout)
  17.   {
  18.     xvel = obj->xv*-1;
  19.     obj->x = obj->x + xvel;
  20.     for (turn = 0; turn != alien_table->max_objects; turn++)
  21.     {
  22.       if (alien_table->object[turn].object_id != NULL)
  23.       {
  24.         if (!hit_bottom)
  25.           alien_table->object[turn].y = alien_table->object[turn].y + 4096;
  26.         alien_table->object[turn].xv = xvel;
  27.         if (alien_table->object[turn].y > (180<<12))
  28.           hit_bottom = TRUE;
  29.       }
  30.     }
  31.   }
  32.  
  33.   if (reason.bits.collide)
  34.   {
  35.     if (obj->xv > 0)
  36.       xvel = obj->xv + 512;
  37.     else
  38.       xvel = obj->xv - 512;
  39.     for (turn = 0; turn != alien_table->max_objects; turn++)
  40.       if (alien_table->object[turn].object_id != 0)
  41.         alien_table->object[turn].xv = xvel;
  42.   }
  43. }
  44.  
  45. void bomby_alien_handler(struct game_object *obj, union object_flags reason, void *data)
  46. {
  47.   struct game_object    *bomb;
  48.  
  49.   if (reason.bits.attn_gameout || reason.bits.collide)
  50.     dull_alien_handler(obj, reason, data);
  51.  
  52.   if (random(100) == 1)
  53.   {
  54.     bomb = Popcorn_NewPrototype(alien_missile_table, 'BMBB', obj->x, obj->y);
  55.     bomb->xv = random(8192)-4096;
  56.     bomb->yv = random(4096);
  57.   }
  58. }
  59.  
  60. void bigblue_alien_handler(struct game_object *obj, union object_flags reason, void *data)
  61. {
  62.   struct game_object      *bomb;
  63.  
  64.   if (reason.bits.attn_gameout || reason.bits.collide)
  65.     dull_alien_handler(obj, reason, data);
  66.  
  67.   if (random(100) == 1)
  68.   {
  69.     bomb = Popcorn_NewPrototype(alien_missile_table, 'ULBB', obj->x, obj->y+40960);
  70.     if (bomb == NULL)
  71.       return;
  72.   }
  73. }
  74.  
  75. void bigblue_handler(struct game_object *obj, union object_flags reason, void *data)
  76. {
  77.   struct game_object      *expl;
  78.  
  79.   expl = Popcorn_NewPrototype(alien_missile_table, 'LPXE', obj->x, obj->y);
  80.   Popcorn_DeleteObject(obj);
  81.   if (expl == NULL)
  82.     return;
  83.   expl->timer.value = 20;
  84.   expl->timer.decrement = 1;
  85.   expl->flags.bits.collide = TRUE;
  86. }
  87.  
  88. void swoopy_alien_handler(struct game_object *obj, union object_flags reason, void *data)
  89. {
  90.   struct game_object     *swoop;
  91.   int     ox, oy, speed;
  92.  
  93.   if (obj->user_data == NULL)
  94.   {
  95.     if (random(1000) == 1)
  96.     {
  97.       swoop = Popcorn_NewPrototype(alien_swoop_table, obj->object_id, obj->x, obj->y);
  98.       swoop->xv = random(16384)-8192; swoop->yv = random(8192)+8192;
  99.       swoop->user_data = obj;
  100.       swoop->timer.value = 300; swoop->timer.decrement = 1;
  101.       obj->flags.bits.attn_every = obj->flags.bits.std_plot = obj->flags.bits.collide = 0;
  102.       obj->handler = (object_handler) dull_alien_handler;
  103.     }
  104.     else
  105.     {
  106.       dull_alien_handler(obj, reason, data);
  107.     }
  108.   }
  109.   else
  110.   {
  111.     if (obj->timer.decrement == 1)
  112.     {
  113.       if (obj->timer.value == 0)
  114.         obj->timer.decrement = 0;
  115.       speed = 128;
  116.     }
  117.     else
  118.       speed = 12288;
  119.     if (obj->x > ((struct game_object*) obj->user_data)->x && obj->xv > -12288)
  120.       obj->xv = obj->xv - speed;
  121.     if (obj->x < ((struct game_object*) obj->user_data)->x && obj->xv < 12288)
  122.       obj->xv = obj->xv + speed;
  123.     if (obj->y > ((struct game_object*) obj->user_data)->y && obj->yv > -12288)
  124.       obj->yv = obj->yv - speed;
  125.     if (obj->y < ((struct game_object*) obj->user_data)->y && obj->yv < 12288)
  126.       obj->yv = obj->yv + speed;
  127.     ox = obj->x - ((struct game_object*) obj->user_data)->x + 32768;
  128.     oy = obj->y - ((struct game_object*) obj->user_data)->y + 32768;
  129.     if ( (ox > 0 && ox < 32768) && (oy > 0 && oy < 32768) )
  130.     {
  131.       ((struct game_object*) obj->user_data)->flags.bits.attn_every = ((struct game_object*) obj->user_data)->flags.bits.std_plot = ((struct game_object*) obj->user_data)->flags.bits.attn_gameout = ((struct game_object*) obj->user_data)->flags.bits.collide = 1;
  132.       ((struct game_object*) obj->user_data)->handler = (object_handler) swoopy_alien_handler;
  133.       Popcorn_DeleteObject(obj);
  134.     }
  135.     if (reason.bits.collide)
  136.     {
  137.       Popcorn_DeleteObject(((struct game_object*)obj->user_data));
  138.     }
  139.   }
  140. }
  141.  
  142. void divebomb_alien_handler(struct game_object *obj, union object_flags reason, void *data)
  143. {
  144.   struct game_object       *swoop;
  145.  
  146.   if (obj->user_data == NULL)
  147.   {
  148.     if (random(1000) == 1)
  149.     {
  150.       make_sound("<Hive$Dir>.Sounds.DiveBomb");
  151.       swoop = Popcorn_NewPrototype(alien_swoop_table, obj->object_id, obj->x, obj->y);
  152.       swoop->xv = (ship_x - obj->x) / 50;
  153.       swoop->yv = ((255<<12) - obj->y) / 50;
  154.       swoop->user_data = obj;
  155.  
  156.       obj->flags.bits.attn_every = obj->flags.bits.std_plot = obj->flags.bits.collide = 0;
  157.       obj->handler = (object_handler) dull_alien_handler;
  158.     }
  159.     else
  160.     {
  161.       dull_alien_handler(obj, reason, data);
  162.     }
  163.   }
  164.   else
  165.   {
  166.     if (reason.bits.collide)
  167.     {
  168.       Popcorn_DeleteObject(((struct game_object*)obj->user_data));
  169.     }
  170.  
  171.     if (reason.bits.attn_gameout)
  172.     {
  173.       if ( (obj->x>>12) < game_window.x0 || (obj->x>>12) > game_window.x1 )
  174.         obj->xv = -obj->xv;
  175.       if ( (obj->y>>12) > game_window.y1)
  176.         obj->yv = -obj->yv;
  177.     }
  178.  
  179.     if (reason.bits.attn_userout)
  180.     {
  181.       ((struct game_object*) obj->user_data)->flags.bits.attn_every = ((struct game_object*) obj->user_data)->flags.bits.std_plot = ((struct game_object*) obj->user_data)->flags.bits.attn_gameout = ((struct game_object*) obj->user_data)->flags.bits.collide = 1;
  182.       ((struct game_object*) obj->user_data)->handler = (object_handler) divebomb_alien_handler;
  183.       Popcorn_DeleteObject(obj);
  184.     }
  185.   }
  186. }
  187.  
  188. void laser_alien_handler(struct game_object *obj, union object_flags reason, void *data)
  189. {
  190.   struct game_object       *laser;
  191.   int                c, xv, yv;
  192.  
  193.   if (reason.bits.collide || reason.bits.attn_gameout)
  194.     dull_alien_handler(obj, reason, data);
  195.  
  196.   if (reason.bits.attn_every)
  197.   {
  198.     if (random(2000) == 0)
  199.     {
  200.       xv = (ship_x - obj->x) / 400;
  201.       yv = ((255<<12) - obj->y) / 400;
  202.       for (c=5; c!=11; c++)
  203.       {
  204.         make_sound("<Hive$Dir>.Sounds.Laser");
  205.         laser = Popcorn_NewPrototype(alien_missile_table, 'RSAL', obj->x, obj->y);
  206.         if (laser != NULL)
  207.         {
  208.           laser->xv = xv*c;
  209.           laser->yv = yv*c;
  210.         }
  211.       }
  212.     }
  213.   }
  214. }
  215.