home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / xgalaga-2_0_tar.gz / xgalaga-2_0_tar / xgalaga-2.0 / prize.c < prev    next >
C/C++ Source or Header  |  1998-04-30  |  4KB  |  197 lines

  1. /* $Id: prize.c,v 1.2 1998/04/30 05:11:58 mrogre Exp $ */
  2. /* Copyright (c) 1998 Joe Rumsey (mrogre@mediaone.net) */
  3. #include "copyright.h"
  4. #include <config.h>
  5.  
  6. #include <stdlib.h>
  7. #include "Wlib.h"
  8. #include "images.h"
  9. #include "struct.h"
  10. #include "data.h"
  11. #include "defs.h"
  12. #include "proto.h"
  13. #include "sound.h"
  14.  
  15. #define PR_SING 0
  16. #define PR_DOUB 1
  17. #define PR_TRIP 2
  18. #define PR_SPEED 3
  19. #define PR_SHIELD 4
  20. #define PR_SMART 5
  21. #define PR_LEMON 6
  22. #define PR_EXTRABULLET 7
  23. #define NUMPRIZES 8
  24.  
  25. #define PRIZESPEED 3
  26.  
  27. W_Image *prizeImages[NUMPRIZES];
  28.     
  29. struct prize {
  30.     struct prize *next, *prev;
  31.     int x, y, type, dying;
  32. } *first_prize; /* 8-) */
  33.  
  34. void init_prizes()
  35. {
  36.     prizeImages[0] = getImage(I_PR_SING);
  37.     prizeImages[1] = getImage(I_PR_DOUB);
  38.     prizeImages[2] = getImage(I_PR_TRIP);
  39.     prizeImages[3] = getImage(I_PR_SPEED);
  40.     prizeImages[4] = getImage(I_PR_SHIELD);
  41.     prizeImages[5] = getImage(I_PR_BRAIN);
  42.     prizeImages[6] = getImage(I_PR_LEMON);
  43.     prizeImages[7] = getImage(I_PR_EXTRABULLET);
  44. }
  45.     
  46. void new_prize(int x, int y)
  47. {
  48.     struct prize *p;
  49.  
  50.     p = malloc(sizeof(struct prize));
  51.     p->next = first_prize;
  52.     p->prev = 0;
  53.     if(first_prize)
  54.     first_prize->prev = p;
  55.     first_prize = p;
  56.     p->x = x;
  57.     p->y = y;
  58.     p->type = random()%NUMPRIZES;
  59.     p->dying = 0;
  60. }
  61.  
  62. void undo_prizes()
  63. {
  64.     struct prize *p = first_prize, *nextp;
  65.  
  66.     while(p) {
  67.     nextp = p->next;
  68.  
  69.     W_CacheClearArea(baseWin, 
  70.              p->x-prizeImages[p->type]->width/2, p->y-prizeImages[p->type]->width/2,
  71.              prizeImages[p->type]->width+1, prizeImages[p->type]->height);
  72.     if(p->dying) {
  73.         if(p->next)
  74.         p->next->prev = p->prev;
  75.         if(p->prev)
  76.         p->prev->next = p->next;
  77.         if(p == first_prize)
  78.         first_prize = p->next;
  79.         free(p);
  80.     }
  81.     p = nextp;
  82.     }
  83. }
  84.  
  85. void do_prizes()
  86. {
  87.     struct prize *p = first_prize;
  88.     int i,k, ne;
  89. #ifdef SOUND
  90.     int oldPlaySounds;
  91. #endif
  92.  
  93.     while(p) {
  94.     if(!paused)
  95.         p->y+=PRIZESPEED;
  96.     W_DrawImage(baseWin, 
  97.             p->x-prizeImages[p->type]->width/2, p->y-prizeImages[p->type]->width/2,
  98.             0, prizeImages[p->type], W_Green);
  99.  
  100.     if(p->y > (WINHEIGHT-20) && (ABS(p->x - plx) < 15)) {
  101.         p->dying = 1;
  102. #ifdef SOUND
  103.         play_sound(SND_DDLOO);
  104. #endif
  105.         switch(p->type) {
  106.           case PR_SING:
  107.         if(weapon == SINGLESHOT)
  108.             maxtorps++;
  109.         else
  110.             weapon = SINGLESHOT;
  111.         break;
  112.           case PR_DOUB:
  113.         if(weapon == DOUBLESHOT)
  114.             maxtorps++;
  115.         else {
  116.             weapon = DOUBLESHOT;
  117.             if(maxtorps < 4)
  118.             maxtorps = 4;
  119.         }
  120.         break;
  121.           case PR_TRIP:
  122.         if(weapon == TRIPLESHOT)
  123.             maxtorps++;
  124.         else {
  125.             weapon = TRIPLESHOT;
  126.             if(maxtorps < 6)
  127.             maxtorps=6;
  128.         }
  129.         break;
  130.           case PR_SPEED:
  131.         if(movespeed < MAXSPEED)
  132.             movespeed++;
  133.         break;
  134.           case PR_SHIELD:
  135.         plshield = SHIELDTIME;
  136. #ifdef SOUND
  137.         play_sound(SND_SHIELD);
  138. #endif
  139.         break;
  140.           case PR_SMART:
  141. #ifdef SOUND
  142.         play_sound(SND_SMART);
  143.         oldPlaySounds = playSounds;
  144.         playSounds = 0;
  145. #endif
  146.         for(i=0;i<MAXALIENS;i++) {
  147.             if(aliens[i].alive && !aliens[i].dying) {
  148.             aliens[i].dying = 1;
  149.             if(i >= 10) {
  150.                 if(aliens[i].dir < 0)
  151.                 score += 50;
  152.                 else {
  153.                 score += (6-(i/10))*100;
  154.                 if(!(random()%(gotlemon ? 3 : PRIZECHANCE)))
  155.                     new_prize(aliens[i].x, aliens[i].y);
  156.                 }
  157.                 new_explosion(aliens[i].x, aliens[i].y, 0);
  158.             } else {
  159.                 if(aliens[i].dir < 0)
  160.                 score += 200;
  161.                 else {
  162.                 ne=0; /* count how many escorts */
  163.                 for(k = i+9;k < i+12; k++) {
  164.                     if(aliens[k].escorting == i)
  165.                     ne++;
  166.                 }                    
  167.                 score_flagship(aliens[i].x, aliens[i].y, ne);
  168.                 }
  169.                 new_explosion(aliens[i].x, aliens[i].y, 1);
  170.             }
  171.             }
  172.         }
  173. #ifdef SOUND
  174.         playSounds = oldPlaySounds;
  175. #endif
  176.         break;
  177.           case PR_LEMON:
  178.         gotlemon = 1;
  179.         maxtorps = MINTORPS;
  180.         weapon = 0;
  181.         movespeed = MINSPEED;
  182.         break;
  183.           case PR_EXTRABULLET:
  184.         if(maxtorps < MAXTORPS)
  185.             maxtorps++;
  186.         break;
  187.         }
  188.         if(maxtorps > MAXTORPS)
  189.         maxtorps = MAXTORPS;
  190.     } else if(p->y > WINHEIGHT) {
  191.         p->dying = 1;
  192.     }
  193.     p=p->next;
  194.     }
  195. }
  196.  
  197.