home *** CD-ROM | disk | FTP | other *** search
/ ISV Strong Games / ISV_STRONG_GAMES.iso / shootemup / hive / !Hive / c / useful < prev    next >
Text File  |  2000-11-27  |  3KB  |  120 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "DeskLib:h.Error"
  5.  
  6. #include "Popcorn:h.Popcorn"
  7.  
  8. #include "h.game"
  9. #include "h.sound"
  10.  
  11. #define random(limit) (rand() % (limit))
  12.  
  13. signed char             sine_table[360];
  14. int                sine_value = 0;
  15.  
  16. int                     alien_proto[32], alien_score[32], score_next=0;
  17.  
  18. void print_message(char *msg, int x, int y, BOOL wiggle)
  19. {
  20.   char res_name[128];
  21.   int  c=0;
  22.   void **res;
  23.  
  24.   while (msg[c] >= 32)
  25.   {
  26.     sprintf(res_name, "<Hive$Dir>.Graphics.alphabet.%d", msg[c]);
  27.     res = Popcorn_FindResource(res_name);
  28.     if (res != NULL)
  29.       if (*res != NULL)
  30.         if (wiggle)
  31.         {
  32.           Popcorn_PlotSprite(*res, x+(c*14), sine_table[((sine_value+(c*20)) % 360)] + y);
  33.         }
  34.         else
  35.           Popcorn_PlotSprite(*res, x+(c*14), y);
  36.     c++;
  37.   }
  38. }
  39.  
  40. void make_lots_of_particles_everywhere(int x, int y, int number)
  41. {
  42.   struct game_object     *particle;
  43.  
  44.   for (; number!=0; number--)
  45.   {
  46.     particle = Popcorn_NewPrototype(fx_table, 'TRAP', x, y);
  47.  
  48.     if (particle == NULL)
  49.       break;
  50.  
  51.     particle->xv = random(16384)-8192; particle->yv = random(16384)-8192;
  52.     particle->timer.value = random(100)+100; particle->timer.decrement = 1;
  53.   }
  54. }
  55.  
  56. void make_explosion(int x, int y)
  57. {
  58.   struct game_object   *explosion;
  59.  
  60.   explosion = Popcorn_NewPrototype(fx_table, 'LPXE', x, y);
  61.  
  62.   if (explosion == NULL)
  63.     return;
  64.  
  65.   explosion->timer.value = 20;
  66.   explosion->timer.decrement = 1;
  67.   make_lots_of_particles_everywhere(x, y, 30);
  68. }
  69.  
  70. void load_scoring(void)
  71. {
  72.   FILE    *handle;
  73.  
  74.   handle = fopen("<Hive$Dir>.Data.Scoring", "rb");
  75.   if (handle == NULL)
  76.     Error_ReportFatal(0, "Cannot find scores file");
  77.  
  78.   while (!feof(handle))
  79.   {
  80.     fscanf(handle, "%s %d", (int) &alien_proto[score_next], &alien_score[score_next]);
  81.     score_next++;
  82.   }
  83.  
  84.   fclose(handle);
  85. }
  86.  
  87. void delete_alien(struct game_object *obj)
  88. {
  89.   int c=0;
  90.   union object_flags reason;
  91.   struct game_object *token;
  92.  
  93.   reason.word = 0;
  94.   reason.bits.collide = TRUE;
  95.  
  96.   while (alien_proto[c] != obj->object_id)
  97.     c++;
  98.   if (obj->user_data == NULL)
  99.     score = score + alien_score[c];
  100.   else
  101.     score = score + (alien_score[c] * 2); /* Got it out of formation */
  102.  
  103.   make_sound("<Hive$Dir>.Sounds.Explode");
  104.   make_explosion(obj->x+ (((obj->size.x>>1)-obj->plot_offset.x)<<12),
  105.                  obj->y+ (((obj->size.y>>1)-obj->plot_offset.y)<<12));
  106.   if (obj->handler != NULL)
  107.     (obj->handler)( (void*) obj, reason, obj);
  108.   aliens_left--;
  109.   if (random(4) == 0)
  110.   {
  111.     token = Popcorn_NewPrototype(token_table, 'NKOT', obj->x, obj->y);
  112.     if (token != NULL)
  113.     {
  114.       token->xv = random(32768)-16384;
  115.       token->yv = -(random(16384)+16384);
  116.     }
  117.   }
  118.   Popcorn_DeleteObject(obj);
  119. }
  120.