home *** CD-ROM | disk | FTP | other *** search
/ Teach Yourself Game Programming in 21 Days / TYGAMES_R.ISO / source / day_16 / seashark.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-05  |  54.4 KB  |  2,378 lines

  1.  
  2. // I N C L U D E S ///////////////////////////////////////////////////////////
  3.  
  4. #include <io.h>
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. #include <bios.h>
  10. #include <fcntl.h>
  11. #include <memory.h>
  12. #include <malloc.h>
  13. #include <math.h>
  14. #include <string.h>
  15.  
  16. #include "graph3.h"  // include our graphics stuff
  17. #include "graph4.h"
  18. #include "graph6.h"
  19. #include "graph9.h"  // sound library
  20.  
  21. // P R O T O T Y P E S ///////////////////////////////////////////////////////
  22.  
  23. void Start_Missile(sprite_ptr who,
  24.                    int x,
  25.                    int y,
  26.                    int xv,
  27.                    int yv,
  28.                    int tag);
  29.  
  30. void Erase_Missiles(void);
  31.  
  32. void Behind_Missiles(void);
  33.  
  34. void Draw_Missiles(void);
  35.  
  36. void Move_Missiles(void);
  37.  
  38. void Init_Missiles(void);
  39.  
  40. void Start_Bubble(int x,
  41.                   int y);
  42.  
  43. void Erase_Bubbles(void);
  44.  
  45. void Behind_Bubbles(void);
  46.  
  47. void Draw_Bubbles(void);
  48.  
  49. void Move_Bubbles(void);
  50.  
  51. void Init_Bubbles(void);
  52.  
  53.  
  54. void Erase_Subs(void);
  55.  
  56. void Behind_Subs(void);
  57.  
  58. void Draw_Subs(void);
  59.  
  60. void Move_Subs(void);
  61.  
  62. void Init_Subs(void);
  63.  
  64. void Start_Sub();
  65.  
  66. void Start_Explosion(int x,int y,int speed);
  67.  
  68. void Behind_Explosions(void);
  69.  
  70. void Erase_Explosions(void);
  71.  
  72. void Draw_Explosions(void);
  73.  
  74. void Animate_Explosions(void);
  75.  
  76. void Draw_Score(void);
  77.  
  78. void Rotate_Lights(void);
  79.  
  80. unsigned char Get_Pixel_DB(int x,int y);
  81.  
  82. int Initialize_Sound_System(void);
  83.  
  84. void Close_Sound_System(void);
  85.  
  86. void Play_Sound(int sound);
  87.  
  88. void Start_Wave(void);
  89.  
  90. void Erase_End_Wave(void);
  91.  
  92. void Draw_End_Wave(void);
  93.  
  94. void Load_Subs(void);
  95.  
  96. void Load_Player(void);
  97.  
  98. void Load_Explosions(void);
  99.  
  100. void Do_Intro(void);
  101.  
  102. // D E F I N E S /////////////////////////////////////////////////////////////
  103.  
  104. // constants for player and enemy
  105.  
  106. #define ENEMY_MISSILE        0 // this is a missile fired by enemy
  107. #define PLAYER_MISSILE       1 // this is a missile fired by player
  108.  
  109. #define MISS_ALIVE           1 // state of a live missile
  110. #define MISS_DEAD            0 // state of a dead missile
  111. #define NUM_MISSILES         3 // number of missiles that can be fired
  112.  
  113. // defines for bubbles
  114.  
  115. #define BUBBLE_CREATED       1  // flags that a bubble has just been created
  116. #define BUBBLE_FLOATING      2  // the state of a floating bubble
  117. #define BUBBLE_DEAD          0  // the bubble is dead (not active)
  118. #define NUM_BUBBLES          50 // maximum bumber of bubbles in system
  119.  
  120. #define BUBBLE_COLOR_BASE    16 // this is used as the base color to make
  121.                                 // bubbles (off white)
  122.  
  123. // general explosions
  124.  
  125. #define NUM_EXPLOSIONS       10  // number of explosions that can run at once
  126.  
  127. #define EXPLOSION_DEAD       0   // state of a dead explosion
  128. #define EXPLOSION_ALIVE      1   // state of a live explosion
  129.  
  130. // cannon positions
  131.  
  132. #define NUM_CANNON_POSITIONS 3   // total possible positions missile cannon has
  133.  
  134. #define CANNON_WEST          0   // cannon is pointing west
  135. #define CANNON_NORTH         1   // cannon is pointing north
  136. #define CANNON_EAST          2   // cannon is pointing east
  137.  
  138. // defines for enemies
  139.  
  140. #define NUM_SUBS             12  // maximum number of subs in game
  141.  
  142. #define SUB_DEAD             0   // a dead sub
  143. #define SUB_ALIVE            1   // a live sub
  144. #define SUB_RIGHT            0   // sub is moving right
  145. #define SUB_LEFT             1   // sub is moving left
  146.  
  147. #define SUB_SMALL            0   // type for small sub
  148. #define SUB_LARGE            1   // type for large sub
  149. #define SUB_BOAT             2   // type for speed boat
  150.  
  151. #define WATER_COLOR          156 // the color register of the background water
  152.  
  153. // sound system defines
  154.  
  155. #define NUM_SOUNDS           5   // number of sounds in system
  156.  
  157. #define SOUND_MISSILE        0   // the players missile
  158. #define SOUND_EXPL           1   // the explosion
  159. #define SOUND_WAVE           2   // end of wave message
  160. #define SOUND_SONAR          3   // the soanr pulse of large sub
  161. #define SOUND_END            4   // game over man!
  162.  
  163. #define SOUND_DEFAULT_PORT   0x220  // default sound port for sound blaster
  164. #define SOUND_DEFAULT_INT    5      // default interrupt
  165.  
  166.  
  167. // M A C R O S //////////////////////////////////////////////////////////////
  168.  
  169. #define SET_SPRITE_SIZE(w,h) {sprite_width=w; sprite_height=h;}
  170.  
  171. // S T R U C T U R E S ///////////////////////////////////////////////////////
  172.  
  173. // typedef for a explosion particle and simple bullet
  174.  
  175. typedef struct particle_typ
  176.         {
  177.         int x;                   // x position
  178.         int y;                   // y position
  179.         int xv;                  // x velocity
  180.         int yv;                  // y velocity
  181.         int xa;                  // x acceleration
  182.         int ya;                  // y acceleration
  183.         unsigned char color;     // the color of the particle
  184.         unsigned char back;      // the color behind the particle
  185.         int state;               // the state of the particle
  186.         int tag;                 // if the particle is a missile then who
  187.                                  // does it belong to?
  188.         int counter_1;           // used for counting
  189.         int threshold_1;         // the counters threshold
  190.  
  191.         int counter_2;
  192.         int threshold_2;
  193.  
  194.         } particle, *particle_ptr;
  195.  
  196. // typedef for a projectile
  197.  
  198. typedef struct projectile_typ
  199.         {
  200.         int x;                   // x position
  201.         int y;                   // y position
  202.         int xv;                  // x velocity
  203.         int yv;                  // y velocity
  204.         int state;               // the state of the particle
  205.         int tag;                 // if the particle is a missile then who
  206.                                  // does it belong to?
  207.         int counter;             // use for counting
  208.         int threshold;           // the counters threshold
  209.  
  210.         int counter_2;
  211.         int threshold_2;
  212.  
  213.         sprite object;           // the missile sprite
  214.  
  215.         } projectile, *projectile_ptr;
  216.  
  217. // typedef for water vehicle
  218.  
  219. typedef struct boat_typ
  220.         {
  221.  
  222.         int state;        // state of boat
  223.         int direction;    // direction of motion
  224.         int type;         // type of water vehicle
  225.  
  226.         int xv;           // x velocity
  227.         int yv;           // y velocity
  228.  
  229.         int x,y;          // position of vehicle
  230.  
  231.         sprite object;    // the sprite for the boat
  232.  
  233.         } boat, *boat_ptr;
  234.  
  235. // G L O B A L S  ////////////////////////////////////////////////////////////
  236.  
  237. projectile missiles[NUM_MISSILES];   // the array of missiles in the world
  238.  
  239. int active_missiles = 0;             // tracks number of active missiles
  240.  
  241. int cannon_pos_x[NUM_CANNON_POSITIONS] = { 2,9,12 };
  242.  
  243. int cannon_pos_y[NUM_CANNON_POSITIONS] = { 0,-4,0 };
  244.  
  245. int cannon_vel_x[NUM_CANNON_POSITIONS] = { -3,0,3 };
  246.  
  247. int cannon_vel_y[NUM_CANNON_POSITIONS] = { -4,-6,-4};
  248.  
  249. particle bubbles[NUM_BUBBLES];       // the bubbbles in the world
  250.  
  251. sprite explosions[NUM_EXPLOSIONS];   // the array of explosions
  252.  
  253. pcx_picture imagery_pcx,      // the game imagery
  254.             background_pcx,   // the backdrop
  255.             intro_pcx;        // the introduction screen
  256.  
  257. // the sprites used in the game
  258.  
  259. sprite player;                // the player
  260.  
  261. sprite icons;                 // used to hold the ship icons during the score
  262.                               // phase
  263.  
  264. boat subs[NUM_SUBS];          // the enemy subs and boats
  265.  
  266. // some of the global game state variables
  267.  
  268. long players_score   = 0;       // the score of the player
  269.  
  270. int wave_number     = 0;       // the current game wave
  271.  
  272. int got_away_this_wave = 0;    // the number of ships that got away this wave
  273.  
  274. int total_got_away  = 0;       // the total number of ships that got away
  275.  
  276. int hits_this_wave  = 0;       // number of ships player hit this wave
  277.  
  278. int ships_large_hit = 0;       // number of large ships hit
  279.  
  280. int ships_small_hit = 0;       // number of small ships hit
  281.  
  282. int ships_boat_hit  = 0;       // number of boats ships hit
  283.  
  284. int ships_this_wave = 0;       // the number of ships that will come out this wave
  285.  
  286. int ships_so_far    = 0;       // number of ships that have come out so far
  287.  
  288. int wave_end        = 0;       // flags if it's the end of the wave
  289.  
  290. int wave_clock      = 0;       // used to count number of frames to display
  291.                                // wave stats to player
  292.  
  293. int game_over       = 0;       // flags if the game is over
  294.  
  295. int game_over_clock = 0;       // used to count how many frames to play the
  296.                                // game over sequence
  297.  
  298. RGB_color color_red     = {255,0,0};    // generic colors used on cannon display
  299. RGB_color color_green   = {0,255,0};
  300.  
  301. // the sound system variables
  302.  
  303. char far *sound_fx[NUM_SOUNDS];           // pointers to the voc files
  304. unsigned char sound_lengths[NUM_SOUNDS];  // lengths of the voc files
  305.  
  306. int sound_available = 1;                  // flags if sound is available
  307.  
  308. int sound_port = SOUND_DEFAULT_PORT;      // default sound port
  309. int sound_int  = SOUND_DEFAULT_INT;       // default sound interrupt
  310.  
  311. // F U N C T I O N S //////////////////////////////////////////////////////////
  312.  
  313. int Initialize_Sound_System(void)
  314. {
  315.  
  316. // this function loads in the ct-voice.drv driver and the configuration file
  317. // and sets up the sound driver appropriately
  318.  
  319. FILE *fp;
  320.  
  321. // test if driver is on disk
  322.  
  323. if ( (fp=fopen("ct-voice.drv","rb") )==NULL)
  324.    {
  325.    return(0);
  326.    } // end if not file
  327.  
  328. fclose(fp);
  329.  
  330. // load up sound configuration file
  331.  
  332. if ( (fp=fopen("seashark.cfg","r"))==NULL)
  333.    {
  334.    printf("\nSound configuration file not found...");
  335.    printf("\nUsing default values of port 220h and interrupt 5.");
  336.  
  337.    } // end if open sound configuration file
  338. else
  339.    {
  340.  
  341.    fscanf(fp,"%d %d",&sound_port, &sound_int);
  342.    printf("\nSetting sound system to port %d decimal with interrupt %d.",
  343.                                                     sound_port, sound_int);
  344.  
  345.    } // end else
  346.  
  347. // start up the whole sound system and load everything
  348.  
  349. Voc_Load_Driver();
  350.  
  351. Voc_Set_Port(sound_port);
  352. Voc_Set_IRQ(sound_int);
  353. Voc_Init_Driver();
  354. Voc_Get_Version();
  355. Voc_Set_Status_Addr((char far *)&ct_voice_status);
  356.  
  357. // load in sounds
  358.  
  359. sound_fx[SOUND_MISSILE ] = Voc_Load_Sound("smissile.voc",&sound_lengths[SOUND_MISSILE ]);
  360. sound_fx[SOUND_EXPL    ] = Voc_Load_Sound("sexpl.voc",   &sound_lengths[SOUND_EXPL    ]);
  361. sound_fx[SOUND_WAVE    ] = Voc_Load_Sound("swave.voc",   &sound_lengths[SOUND_WAVE    ]);
  362. sound_fx[SOUND_SONAR   ] = Voc_Load_Sound("ssonar.voc",  &sound_lengths[SOUND_SONAR   ]);
  363. sound_fx[SOUND_END     ] = Voc_Load_Sound("sover.voc",   &sound_lengths[SOUND_END]);
  364.  
  365. // turn on speaker
  366.  
  367. Voc_Set_Speaker(1);
  368.  
  369. // success
  370.  
  371. return(1);
  372.  
  373. } // end Initialize_Sound_System
  374.  
  375. /////////////////////////////////////////////////////////////////////////////
  376.  
  377. void Close_Sound_System(void)
  378. {
  379. // make sure there is sound
  380.  
  381. if (sound_available)
  382.    {
  383.    // turn off speaker
  384.  
  385.    Voc_Set_Speaker(0);
  386.  
  387.    // unload sounds
  388.  
  389.    Voc_Unload_Sound(sound_fx[SOUND_MISSILE ]);
  390.    Voc_Unload_Sound(sound_fx[SOUND_EXPL    ]);
  391.    Voc_Unload_Sound(sound_fx[SOUND_WAVE    ]);
  392.    Voc_Unload_Sound(sound_fx[SOUND_SONAR   ]);
  393.    Voc_Unload_Sound(sound_fx[SOUND_END     ]);
  394.  
  395.    Voc_Terminate_Driver();
  396.  
  397.    } // end if sound
  398.  
  399. } // end Close_Sound_System
  400.  
  401. /////////////////////////////////////////////////////////////////////////////
  402.  
  403. void Play_Sound(int sound)
  404. {
  405. // this function plays a sound by turning off one if there is a sound playing
  406. // and then playing the sent sound
  407.  
  408. // make sure there is a sound system first
  409.  
  410. if (sound_available)
  411.    {
  412.  
  413.    // stop the current sound (if there is one)
  414.  
  415.    Voc_Stop_Sound();
  416.  
  417.    // play sent sound
  418.  
  419.    Voc_Play_Sound(sound_fx[sound] , sound_lengths[sound]);
  420.  
  421.    } // end if sound available
  422.  
  423. } // end Play_Sound
  424.  
  425. ///////////////////////////////////////////////////////////////////////////////
  426.  
  427. unsigned char Get_Pixel_DB(int x,int y)
  428. {
  429.  
  430. // gets the color value of pixel at (x,y) from the double buffer
  431.  
  432. return double_buffer[((y<<8) + (y<<6)) + x];
  433.  
  434. } // end Get_Pixel_DB
  435.  
  436. ///////////////////////////////////////////////////////////////////////////////
  437.  
  438. void Erase_Missiles(void)
  439. {
  440.  
  441. // this function indexes through all the missiles and if they are active
  442. // erases them by replacing the background color that was under them
  443.  
  444. int index;
  445.  
  446. // set sprite size for engine
  447.  
  448. SET_SPRITE_SIZE(8,8);
  449.  
  450. for (index=0; index<NUM_MISSILES; index++)
  451.     {
  452.  
  453.     // is this missile active
  454.  
  455.     if (missiles[index].state == MISS_ALIVE)
  456.        {
  457.  
  458.        // extract proper parameters
  459.  
  460.        missiles[index].object.x = missiles[index].x;
  461.        missiles[index].object.y = missiles[index].y;
  462.  
  463.        // erase the sprite
  464.  
  465.        Erase_Sprite_DB((sprite_ptr)&missiles[index].object);
  466.  
  467.        } // end if alive
  468.  
  469.     } // end for index
  470.  
  471. } // end Erase_Missiles
  472.  
  473. /////////////////////////////////////////////////////////////////////////////
  474.  
  475. void Behind_Missiles(void)
  476. {
  477.  
  478. // this function indexes through all the missiles and if they are active
  479. // scans the background color that is behind them so it can be replaced later
  480.  
  481. int index;
  482.  
  483. // set sprite size for engine
  484.  
  485. SET_SPRITE_SIZE(8,8);
  486.  
  487. for (index=0; index<NUM_MISSILES; index++)
  488.     {
  489.  
  490.     // is this missile active
  491.  
  492.     if (missiles[index].state == MISS_ALIVE)
  493.        {
  494.  
  495.        // extract proper parameters
  496.  
  497.        missiles[index].object.x = missiles[index].x;
  498.        missiles[index].object.y = missiles[index].y;
  499.  
  500.        // scan begind the sprite
  501.  
  502.        Behind_Sprite_DB((sprite_ptr)&missiles[index].object);
  503.  
  504.        } // end if alive
  505.  
  506.     } // end for index
  507.  
  508. } // end Behind_Missiles
  509.  
  510. /////////////////////////////////////////////////////////////////////////////
  511.  
  512. void Draw_Missiles(void)
  513. {
  514.  
  515. // this function indexes through all the missiles and if they are active
  516. // draws the missile as a bright white pixel on the screen
  517.  
  518. int index;
  519.  
  520. // set sprite size for engine
  521.  
  522. SET_SPRITE_SIZE(8,8);
  523.  
  524. for (index=0; index<NUM_MISSILES; index++)
  525.     {
  526.  
  527.     // is this missile active
  528.  
  529.     if (missiles[index].state == MISS_ALIVE)
  530.        {
  531.  
  532.        // extract proper parameters
  533.  
  534.        missiles[index].object.x = missiles[index].x;
  535.        missiles[index].object.y = missiles[index].y;
  536.  
  537.        // draw the sprite
  538.  
  539.        Draw_Sprite_DB((sprite_ptr)&missiles[index].object);
  540.  
  541.        } // end if alive
  542.  
  543.     } // end for index
  544.  
  545. } // end Draw_Missiles
  546.  
  547. /////////////////////////////////////////////////////////////////////////////
  548.  
  549. void Move_Missiles(void)
  550. {
  551.  
  552. // this function moves the missiles and does all the collision detection
  553.  
  554. int index,              // used for loops
  555.     index_2,
  556.     index_3,
  557.     miss_x,             // position of missile
  558.     miss_y,
  559.     miss_x_center,      // center of missile
  560.     miss_y_center,
  561.     sub_x,              // position of test sub
  562.     sub_y,
  563.     num_explosions,     // temporary var that holds number of explosions
  564.     sub_hit=0;          // flags if a sub was hit
  565.  
  566.  
  567. // test if all missiles are active so that ready light on cannon can be
  568. // illuminated properly
  569.  
  570. if (active_missiles==NUM_MISSILES)
  571.    {
  572.    // turn ready light red
  573.  
  574.    Set_Palette_Register(254,(RGB_color_ptr)&color_red);
  575.  
  576.    } // no more missles can be fired
  577. else
  578.    {
  579.    // turn ready light green
  580.  
  581.    Set_Palette_Register(254,(RGB_color_ptr)&color_green);
  582.  
  583.    } // end else there is a missile ready
  584.  
  585. // loop thru all missiles and perform a lot of tests
  586.  
  587. for (index=0; index<NUM_MISSILES; index++)
  588.     {
  589.  
  590.     // is missile active
  591.  
  592.     if (missiles[index].state == MISS_ALIVE)
  593.        {
  594.  
  595.        // move the missile
  596.  
  597.        miss_x = (missiles[index].x += missiles[index].xv);
  598.        miss_y = (missiles[index].y += missiles[index].yv);
  599.  
  600.        // test if missile hit an object
  601.  
  602.        // compute center of missile for ease of computations
  603.  
  604.        miss_x_center = miss_x+4;
  605.        miss_y_center = miss_y+4;
  606.  
  607.        // reset sub hit flag
  608.  
  609.        sub_hit = 0;
  610.  
  611.        // for each active sub test missile to see if it has hit it
  612.  
  613.        for (index_2=0; index_2<NUM_SUBS; index_2++)
  614.            {
  615.  
  616.            // is this sub alive
  617.  
  618.            if (subs[index_2].state==SUB_ALIVE)
  619.               {
  620.  
  621.               // extract upper left hand corner of sub
  622.  
  623.               sub_x = subs[index_2].x;
  624.               sub_y = subs[index_2].y;
  625.  
  626.               // do standard bounding box test for collision
  627.  
  628.               if ( (miss_x_center >= sub_x) &&
  629.                    (miss_x_center <= sub_x+subs[index_2].object.width) &&
  630.                    (miss_y_center >= sub_y) &&
  631.                    (miss_y_center <= sub_y+subs[index_2].object.height) )
  632.                  {
  633.  
  634.                  // terminate sub and missile
  635.  
  636.                  subs[index_2].state   = SUB_DEAD;
  637.  
  638.                  hits_this_wave++;
  639.  
  640.                  missiles[index].state = MISS_DEAD;
  641.  
  642.                  // decrement number of active missiles
  643.  
  644.                  active_missiles--;
  645.  
  646.                  // start a couple explosions in the area
  647.  
  648.                  num_explosions = 1 + rand()%2;
  649.  
  650.                  for (index_3=0; index_3<num_explosions; index_3++)
  651.                      {
  652.  
  653.                      Start_Explosion(miss_x+4-30 + rand()%24,miss_y+4-20,1+rand()%2);
  654.  
  655.                      } // end for start explosions
  656.  
  657.                  // set hit flag
  658.  
  659.                  sub_hit = 1;
  660.  
  661.                  // increment number of hits this wave
  662.  
  663.                  hits_this_wave++;
  664.  
  665.                  // update players score based on type of sub
  666.  
  667.                  switch(subs[index_2].type)
  668.                        {
  669.  
  670.                        case SUB_SMALL: // hard to hit!
  671.                             {
  672.  
  673.                             players_score += 250;
  674.  
  675.                             ships_small_hit++;
  676.  
  677.                             } break;
  678.  
  679.                        case SUB_LARGE: // easy to hit
  680.                             {
  681.  
  682.                             players_score += 50;
  683.  
  684.                             ships_large_hit++;
  685.  
  686.                             } break;
  687.  
  688.                        case SUB_BOAT: // hard to hit
  689.                             {
  690.  
  691.                             players_score += 300;
  692.  
  693.                             ships_boat_hit++;
  694.  
  695.                             } break;
  696.  
  697.                        default:break;
  698.  
  699.                        } // end switch
  700.  
  701.                  // missile has hit something so break out of loop
  702.  
  703.                  break;
  704.  
  705.                  } // end if hit
  706.  
  707.               } // end if alive
  708.  
  709.            } // end for sub test
  710.  
  711.        // don't do any further processing of this missile if there has been a
  712.        // sub hit
  713.  
  714.        if (!sub_hit)
  715.           {
  716.  
  717.           // test if it's hit the edge of the screen or a wall
  718.  
  719.           if ( (miss_x >= SCREEN_WIDTH) || (miss_x <= 0) ||
  720.                (miss_y > (SCREEN_HEIGHT-16)) || ( miss_y <= 16) )
  721.                {
  722.  
  723.                // kill missile and start a surface explosion
  724.  
  725.                missiles[index].state = MISS_DEAD;
  726.  
  727.                // decrement number of active missiles
  728.  
  729.                active_missiles--;
  730.  
  731.                Start_Explosion(miss_x+4-16,miss_y+4-16,1);
  732.  
  733.                // process next missile
  734.  
  735.                continue;
  736.  
  737.                } // end if off edge of screen
  738.  
  739.           // start a bubble ?
  740.  
  741.           if (miss_y > 64 )
  742.              {
  743.  
  744.              Start_Bubble(miss_x+4, miss_y+4);
  745.  
  746.              } // end if time to start bubble
  747.  
  748.           } // end if sub not hit
  749.  
  750.        } // end if missile alive
  751.  
  752.     } // end for index
  753.  
  754. } // end Move_Missiles
  755.  
  756. /////////////////////////////////////////////////////////////////////////////
  757.  
  758. void Start_Missile(sprite_ptr who,
  759.                    int x,
  760.                    int y,
  761.                    int xv,
  762.                    int yv,
  763.                    int tag)
  764. {
  765.  
  766. // this function scans through the missile array and tries to find one that
  767. // isn't being used.  this function could be more efficient.
  768.  
  769. int index;
  770.  
  771. // scan for a useable missle
  772.  
  773. for (index=0; index<NUM_MISSILES; index++)
  774.     {
  775.     // is this missile free?
  776.  
  777.     if (missiles[index].state == MISS_DEAD)
  778.        {
  779.  
  780.        // set up fields
  781.  
  782.        missiles[index].state = MISS_ALIVE;
  783.        missiles[index].x     = x;
  784.        missiles[index].y     = y;
  785.        missiles[index].xv    = xv;
  786.        missiles[index].yv    = yv;
  787.        missiles[index].tag   = tag;
  788.  
  789.        // make sure proper animation cell is selected
  790.  
  791.        missiles[index].object.curr_frame = player.curr_frame;
  792.  
  793.        // extract proper parameters
  794.  
  795.        missiles[index].object.x = x;
  796.        missiles[index].object.y = y;
  797.  
  798.        // set sprite size for engine
  799.  
  800.        SET_SPRITE_SIZE(8,8);
  801.  
  802.        Behind_Sprite_DB((sprite_ptr)&missiles[index].object);
  803.  
  804.        // increment number of active missiles
  805.  
  806.        active_missiles++;
  807.  
  808.        // play sound
  809.  
  810.        Play_Sound(SOUND_MISSILE);
  811.  
  812.        break; // exit loop
  813.  
  814.        } // end if found a good one
  815.  
  816.     } // end for index
  817.  
  818. } // end Start_Missile
  819.  
  820. /////////////////////////////////////////////////////////////////////////////
  821.  
  822. void Init_Missiles(void)
  823. {
  824. // this function just makes sure all the "state" fields of the missiles are
  825. // dead so that we don't get any strays on start up.  Remember never assume
  826. // that variables are zeroed on instantiation!
  827.  
  828. int index;
  829.  
  830. for (index=0; index<NUM_MISSILES; index++)
  831.     missiles[index].state = MISS_DEAD;
  832.  
  833. } // Init_Missiles
  834.  
  835.  
  836. ///////////////////////////////////////////////////////////////////////////////
  837.  
  838. void Erase_Bubbles(void)
  839. {
  840. // this function erases all the bubbles
  841.  
  842. int index;
  843.  
  844. // process each bubble
  845.  
  846. for (index=0; index<NUM_BUBBLES; index++)
  847.     {
  848.  
  849.     // is this bubble active
  850.  
  851.     if (bubbles[index].state != BUBBLE_DEAD)
  852.        {
  853.  
  854.        Plot_Pixel_Fast_DB(bubbles[index].x,bubbles[index].y,bubbles[index].back);
  855.  
  856.        } // end if alive
  857.  
  858.     } // end for index
  859.  
  860. } // end Erase_Bubbles
  861.  
  862. /////////////////////////////////////////////////////////////////////////////
  863.  
  864. void Behind_Bubbles(void)
  865. {
  866. // this function scans the background under all the bubbles
  867.  
  868. int index;
  869.  
  870. // process each bubble
  871.  
  872. for (index=0; index<NUM_BUBBLES; index++)
  873.     {
  874.  
  875.     // is this bubble active
  876.  
  877.     if (bubbles[index].state != BUBBLE_DEAD)
  878.        {
  879.  
  880.        bubbles[index].back = Get_Pixel_DB(bubbles[index].x, bubbles[index].y);
  881.  
  882.        } // end if alive
  883.  
  884.     } // end for index
  885.  
  886. } // end Behind_Bubbles
  887.  
  888. /////////////////////////////////////////////////////////////////////////////
  889.  
  890. void Draw_Bubbles(void)
  891. {
  892. // this function draws all the bubbles
  893.  
  894. int index;
  895.  
  896. // process each bubble
  897.  
  898. for (index=0; index<NUM_BUBBLES; index++)
  899.     {
  900.  
  901.     // is this bubble active
  902.  
  903.     if (bubbles[index].state != BUBBLE_DEAD)
  904.        {
  905.        Plot_Pixel_Fast_DB(bubbles[index].x,bubbles[index].y,bubbles[index].color);
  906.  
  907.        } // end if alive
  908.  
  909.     } // end for index
  910.  
  911. } // end Draw_Bubbles
  912.  
  913. /////////////////////////////////////////////////////////////////////////////
  914.  
  915. void Move_Bubbles(void)
  916. {
  917.  
  918. // this function moves the bubbles
  919.  
  920. int index,     // used for loops
  921.     bubb_x,   // position of missile
  922.     bubb_y;
  923.  
  924. // loop thru all bubbles
  925.  
  926. for (index=0; index<NUM_BUBBLES; index++)
  927.     {
  928.  
  929.     // is bubble active
  930.  
  931.     if (bubbles[index].state != BUBBLE_DEAD)
  932.        {
  933.  
  934.        // move the bubble if time to using y velocity
  935.  
  936.        bubb_x = bubbles[index].x;
  937.  
  938.        if (bubbles[index].counter_1 > bubbles[index].threshold_2)
  939.            bubb_y = (bubbles[index].y += bubbles[index].yv);
  940.        else
  941.            bubb_y = bubbles[index].y;
  942.  
  943.        // test if it's hit the edge of the screen or a wall
  944.  
  945.        if ( (bubb_x >= SCREEN_WIDTH) || (bubb_x <= 0) ||
  946.             (bubb_y > (SCREEN_HEIGHT-16)) || ( bubb_y <=0) )
  947.             {
  948.             bubbles[index].state = BUBBLE_DEAD;
  949.             continue;
  950.  
  951.             } // end if off edge of screen
  952.  
  953.        // is it time to pop bubble
  954.  
  955.        if (++bubbles[index].counter_1 > bubbles[index].threshold_1)
  956.           {
  957.           // kill bubble and process next
  958.  
  959.           bubbles[index].state = BUBBLE_DEAD;
  960.           continue;
  961.  
  962.           } // end if timed out
  963.  
  964.        } // end if bubble alive
  965.  
  966.     } // end for index
  967.  
  968. } // end Move_Bubbles
  969.  
  970. /////////////////////////////////////////////////////////////////////////////
  971.  
  972. void Start_Bubble(int x, int y)
  973. {
  974.  
  975. // this function scans through the bubble array and tries to find one that
  976. // isn't being used.  this function could be more efficient.
  977.  
  978. int index;
  979.  
  980. // scan for a useable bubble
  981.  
  982. for (index=0; index<NUM_BUBBLES; index++)
  983.     {
  984.     // is this bubble free?
  985.  
  986.     if (bubbles[index].state == BUBBLE_DEAD)
  987.        {
  988.  
  989.        // set up fields
  990.  
  991.        bubbles[index].state = BUBBLE_CREATED;
  992.        bubbles[index].x     = -2 + x + rand()%4;
  993.        bubbles[index].y     = -2 + y + rand()%4;
  994.        bubbles[index].xv    = 0;
  995.        bubbles[index].yv    = -(rand()%3);
  996.  
  997.        // select a random lifetime before bursting
  998.  
  999.        bubbles[index].counter_1   = 0;
  1000.        bubbles[index].threshold_1 = 25 + rand()%10;
  1001.  
  1002.        bubbles[index].threshold_2 = 10 + rand()%5;
  1003.  
  1004.        // select a random shade of white
  1005.  
  1006.        bubbles[index].color = BUBBLE_COLOR_BASE+rand()%8;
  1007.  
  1008.        // scan the background
  1009.  
  1010.        bubbles[index].back  = Get_Pixel_DB(bubbles[index].x,bubbles[index].y);
  1011.  
  1012.        break; // exit loop
  1013.  
  1014.        } // end if found a good one
  1015.  
  1016.     } // end for index
  1017.  
  1018. } // end Start_Bubble
  1019.  
  1020. /////////////////////////////////////////////////////////////////////////////
  1021.  
  1022. void Init_Bubbles(void)
  1023. {
  1024. // this function sets the state of all bubbles to dead
  1025.  
  1026. int index;
  1027.  
  1028. for (index=0; index<NUM_BUBBLES; index++)
  1029.     bubbles[index].state = BUBBLE_DEAD;
  1030.  
  1031. } // Init_Bubbles
  1032.  
  1033. ////////////////////////////////////////////////////////////////////////////
  1034.  
  1035. void Start_Explosion(int x,int y,int speed)
  1036. {
  1037. // this function stars a generic explosion
  1038.  
  1039. int index;
  1040.  
  1041. SET_SPRITE_SIZE(32,32);
  1042.  
  1043. // scan for a useable explosion
  1044.  
  1045. for (index=0; index<NUM_EXPLOSIONS; index++)
  1046.     {
  1047.  
  1048.     if (explosions[index].state == EXPLOSION_DEAD)
  1049.        {
  1050.  
  1051.        // set up fields
  1052.  
  1053.        explosions[index].state      = EXPLOSION_ALIVE;
  1054.        explosions[index].x          = x;
  1055.        explosions[index].y          = y;
  1056.        explosions[index].curr_frame = 0;
  1057.        explosions[index].anim_speed = speed;
  1058.        explosions[index].anim_clock = 0;
  1059.  
  1060.        // scan background to be safe
  1061.  
  1062.        Behind_Sprite_DB((sprite_ptr)&explosions[index]);
  1063.  
  1064.        // play sound
  1065.  
  1066.        Play_Sound(SOUND_EXPL);
  1067.  
  1068.        break; // exit loop
  1069.  
  1070.        } // end if found a good one
  1071.  
  1072.     } // end for index
  1073.  
  1074. } // end Start_Explosion
  1075.  
  1076. /////////////////////////////////////////////////////////////////////////////
  1077.  
  1078. void Behind_Explosions(void)
  1079. {
  1080.  
  1081. // this function scans under the explosions
  1082.  
  1083. int index;
  1084.  
  1085. SET_SPRITE_SIZE(32,32);
  1086.  
  1087. // scan for a running explosions
  1088.  
  1089. for (index=0; index<NUM_EXPLOSIONS; index++)
  1090.     {
  1091.  
  1092.     if (explosions[index].state == EXPLOSION_ALIVE)
  1093.        {
  1094.        Behind_Sprite_DB((sprite_ptr)&explosions[index]);
  1095.  
  1096.        } // end if found a good one
  1097.  
  1098.     } // end for index
  1099.  
  1100. } // end Behind_Explosions
  1101.  
  1102. /////////////////////////////////////////////////////////////////////////////
  1103.  
  1104. void Erase_Explosions(void)
  1105. {
  1106. // this function erases all the current explosions
  1107.  
  1108. int index;
  1109.  
  1110. SET_SPRITE_SIZE(32,32);
  1111.  
  1112. // scan for a useable explosion
  1113.  
  1114. for (index=0; index<NUM_EXPLOSIONS; index++)
  1115.     {
  1116.  
  1117.     if (explosions[index].state == EXPLOSION_ALIVE)
  1118.        {
  1119.        Erase_Sprite_DB((sprite_ptr)&explosions[index]);
  1120.  
  1121.        } // end if found a good one
  1122.  
  1123.     } // end for index
  1124.  
  1125. } // end Erase_Explosions
  1126.  
  1127. /////////////////////////////////////////////////////////////////////////////
  1128.  
  1129. void Draw_Explosions(void)
  1130. {
  1131. // this function draws the explosion
  1132.  
  1133. int index;
  1134.  
  1135. SET_SPRITE_SIZE(32,32);
  1136.  
  1137. // scan for a useable explosion
  1138.  
  1139. for (index=0; index<NUM_EXPLOSIONS; index++)
  1140.     {
  1141.  
  1142.     // make sure this explosion is alive
  1143.  
  1144.     if (explosions[index].state == EXPLOSION_ALIVE)
  1145.        {
  1146.  
  1147.        Draw_Sprite_DB((sprite_ptr)&explosions[index]);
  1148.  
  1149.        } // end if found a good one
  1150.  
  1151.     } // end for index
  1152.  
  1153. } // end Draw_Explosions
  1154.  
  1155. /////////////////////////////////////////////////////////////////////////////
  1156.  
  1157. void Animate_Explosions(void)
  1158. {
  1159. // this function steps the explosion thru the frames of animation
  1160. int index;
  1161.  
  1162. // scan for a useable explosion
  1163.  
  1164. for (index=0; index<NUM_EXPLOSIONS; index++)
  1165.     {
  1166.     // test if explosion is alive
  1167.     if (explosions[index].state == EXPLOSION_ALIVE)
  1168.        {
  1169.        // test if it's time to change frames
  1170.  
  1171.        if (++explosions[index].anim_clock == explosions[index].anim_speed)
  1172.           {
  1173.           // is the explosion over?
  1174.  
  1175.           if (++explosions[index].curr_frame == 4)
  1176.              explosions[index].state = EXPLOSION_DEAD;
  1177.  
  1178.           // reset animation clock for future
  1179.  
  1180.           explosions[index].anim_clock = 0;
  1181.  
  1182.           } // end if time ti change frames
  1183.  
  1184.        } // end if found a good one
  1185.  
  1186.     } // end for index
  1187.  
  1188. } // end Animate_Explosions
  1189.  
  1190. //////////////////////////////////////////////////////////////////////////////
  1191.  
  1192. void Init_Explosions(void)
  1193. {
  1194. // reset all explosions
  1195.  
  1196. int index;
  1197.  
  1198. for (index=0; index<NUM_EXPLOSIONS; index++)
  1199.     explosions[index].state = EXPLOSION_DEAD;
  1200.  
  1201. } // Init_Explosions
  1202.  
  1203. //////////////////////////////////////////////////////////////////////////////
  1204.  
  1205. void Init_Subs(void)
  1206. {
  1207. // set the state of all subs to dead
  1208.  
  1209. int index;
  1210.  
  1211. for (index=0; index<NUM_SUBS; index++)
  1212.     subs[index].state = SUB_DEAD;
  1213.  
  1214. } // Init_Subs
  1215.  
  1216. ////////////////////////////////////////////////////////////////////////////
  1217.  
  1218. void Behind_Subs(void)
  1219. {
  1220. // this function scans the background under each sub
  1221.  
  1222. int index; // loop variable
  1223.  
  1224. // process each sub
  1225.  
  1226. for (index=0; index<NUM_EXPLOSIONS; index++)
  1227.     {
  1228.     // test if sub is active
  1229.  
  1230.     if (subs[index].state == SUB_ALIVE)
  1231.        {
  1232.  
  1233.        // extract proper sprite size
  1234.  
  1235.        sprite_width  = subs[index].object.width;
  1236.        sprite_height = subs[index].object.height;
  1237.  
  1238.        // scan behind sprite
  1239.  
  1240.        subs[index].object.x = subs[index].x;
  1241.        subs[index].object.y = subs[index].y;
  1242.  
  1243.        Behind_Sprite_DB((sprite_ptr)&subs[index].object);
  1244.  
  1245.        } // end if found a good one
  1246.  
  1247.     } // end for index
  1248.  
  1249. } // end Behind_Subs
  1250.  
  1251. ////////////////////////////////////////////////////////////////////////////
  1252.  
  1253. void Erase_Subs(void)
  1254. {
  1255. // this function erases all the subs
  1256.  
  1257. int index; // loop variable
  1258.  
  1259. // process each sub
  1260.  
  1261. for (index=0; index<NUM_EXPLOSIONS; index++)
  1262.     {
  1263.  
  1264.     // test if sub is active
  1265.  
  1266.     if (subs[index].state == SUB_ALIVE)
  1267.        {
  1268.  
  1269.  
  1270.        // extract proper sprite size
  1271.  
  1272.        sprite_width  = subs[index].object.width;
  1273.        sprite_height = subs[index].object.height;
  1274.  
  1275.        subs[index].object.x = subs[index].x;
  1276.        subs[index].object.y = subs[index].y;
  1277.  
  1278.        Erase_Sprite_DB((sprite_ptr)&subs[index].object);
  1279.  
  1280.        } // end if found a good one
  1281.  
  1282.     } // end for index
  1283.  
  1284. } // end Erase_Subs
  1285.  
  1286. ////////////////////////////////////////////////////////////////////////////
  1287.  
  1288. void Draw_Subs(void)
  1289. {
  1290.  
  1291. int index;
  1292.  
  1293. for (index=0; index<NUM_EXPLOSIONS; index++)
  1294.     {
  1295.  
  1296.     if (subs[index].state == SUB_ALIVE)
  1297.        {
  1298.  
  1299.        // extract proper sprite size
  1300.  
  1301.        sprite_width  = subs[index].object.width;
  1302.        sprite_height = subs[index].object.height;
  1303.  
  1304.        subs[index].object.x = subs[index].x;
  1305.        subs[index].object.y = subs[index].y;
  1306.  
  1307.        Draw_Sprite_DB((sprite_ptr)&subs[index].object);
  1308.  
  1309.        } // end if found a good one
  1310.  
  1311.     } // end for index
  1312.  
  1313. } // end Draw_Subs
  1314.  
  1315. ////////////////////////////////////////////////////////////////////////////
  1316.  
  1317. void Start_Sub(void)
  1318. {
  1319.  
  1320. // this function scans through the array of subs and tests if any of them
  1321. // can be used i.e. are not active, if one is found then it is started up
  1322.  
  1323. int index,             // loop index
  1324.     sub_type,          // type of sub small, large, boat
  1325.     range_start,       // where to look for the specific type of sub in array
  1326.     range_end;
  1327.  
  1328.     // select type of enemy
  1329.  
  1330.     sub_type = rand()%3;
  1331.  
  1332.     // find a free enemy of that type
  1333.  
  1334.     switch(sub_type)
  1335.           {
  1336.  
  1337.           case SUB_SMALL: // select proper scan range for small sub
  1338.                {
  1339.                // select scan range
  1340.  
  1341.                range_start = 0;
  1342.                range_end   = 3;
  1343.  
  1344.                } break;
  1345.  
  1346.           case SUB_LARGE: // select proper scan range for large sub
  1347.                {
  1348.                // select scan range
  1349.  
  1350.                range_start = 4;
  1351.                range_end   = 7;
  1352.  
  1353.                // play sound if it's a big sub
  1354.  
  1355.                if ((rand()%2)==0)
  1356.                    Play_Sound(SOUND_SONAR);
  1357.  
  1358.                } break;
  1359.  
  1360.           case SUB_BOAT: // select proper scan range for boat
  1361.                {
  1362.                // select scan range
  1363.  
  1364.                range_start = 8;
  1365.                range_end   = 11;
  1366.  
  1367.                } break;
  1368.  
  1369.           default:break;
  1370.  
  1371.           } // end switch
  1372.  
  1373. // now that we know where in array to look for a boat of the requested type,
  1374. // let's find one
  1375.  
  1376. for (index=range_start; index<=range_end; index++)
  1377.     {
  1378.  
  1379.     // is this one free
  1380.  
  1381.     if (subs[index].state == SUB_DEAD)
  1382.        {
  1383.  
  1384.        // set the water vehicle up
  1385.  
  1386.        subs[index].state = SUB_ALIVE;
  1387.  
  1388.        // record that another brave sole was sent out
  1389.  
  1390.        ships_so_far++;
  1391.  
  1392.        // set y velocity to zero for now
  1393.  
  1394.        subs[index].yv = 0;
  1395.  
  1396.        if (sub_type==SUB_BOAT)
  1397.           subs[index].y = 16;
  1398.        else
  1399.           subs[index].y = 24 + rand()%130;
  1400.  
  1401.        // select direction of motion
  1402.  
  1403.        if ((rand()%2)==SUB_LEFT)
  1404.           {
  1405.           // set all fields
  1406.  
  1407.           subs[index].xv                = -2 - rand()%6;
  1408.           subs[index].x                 = 320 - subs[index].object.width;
  1409.           subs[index].direction         = SUB_LEFT;
  1410.           subs[index].object.curr_frame = 1;
  1411.  
  1412.           } // end if left
  1413.        else
  1414.           {
  1415.           // set all fields
  1416.  
  1417.           subs[index].xv                = 2 + rand()%6;
  1418.           subs[index].x                 = 0;
  1419.           subs[index].direction         = SUB_RIGHT;
  1420.           subs[index].object.curr_frame = 0;
  1421.  
  1422.           } // end else direction right
  1423.  
  1424.        // scan background under sub
  1425.  
  1426.        // extract proper sprite size
  1427.  
  1428.        sprite_width  = subs[index].object.width;
  1429.        sprite_height = subs[index].object.height;
  1430.  
  1431.        // scan behind sprite
  1432.  
  1433.        subs[index].object.x = subs[index].x;
  1434.        subs[index].object.y = subs[index].y;
  1435.  
  1436.        Behind_Sprite_DB((sprite_ptr)&subs[index].object);
  1437.  
  1438.        // done so bail
  1439.  
  1440.        break;
  1441.  
  1442.        } // end if dead
  1443.  
  1444.     } // end for index
  1445.  
  1446. } // end Start_Sub
  1447.  
  1448. ///////////////////////////////////////////////////////////////////////////
  1449.  
  1450. void Move_Subs(void)
  1451. {
  1452. // thjis function moves all the subs and kills them if they hit the edge
  1453. // of the screen
  1454.  
  1455. int index,  // used for loop variable
  1456.     sx,sy;  // used for temporary position variables
  1457.  
  1458. // process each sub or boat in a rray
  1459.  
  1460. for (index=0; index<NUM_SUBS; index++)
  1461.     {
  1462.  
  1463.     // is this vehicle active ?
  1464.  
  1465.     if (subs[index].state == SUB_ALIVE)
  1466.        {
  1467.  
  1468.        // move the sub
  1469.  
  1470.        sx = (subs[index].x+=subs[index].xv);
  1471.        sy = (subs[index].y+=subs[index].yv);
  1472.  
  1473.        // do boundary tests
  1474.  
  1475.        if (sy>155)
  1476.           subs[index].y = 155;
  1477.        else
  1478.        if ((subs[index].type != SUB_BOAT) && sy<16)
  1479.           subs[index].y = 16;
  1480.  
  1481.        if ( ((subs[index].direction==SUB_LEFT) && (sx<0)) ||
  1482.             ((subs[index].direction==SUB_RIGHT) &&
  1483.              (sx>320-subs[index].object.width)) )
  1484.           {
  1485.  
  1486.           // terminate sub or boat
  1487.  
  1488.           subs[index].state = SUB_DEAD;
  1489.  
  1490.           // increment number of ships that got away
  1491.  
  1492.           got_away_this_wave++;
  1493.  
  1494.           } // end if off screen
  1495.  
  1496.        } // end if alive
  1497.  
  1498.     } // end for index
  1499.  
  1500. } // end Move_Subs
  1501.  
  1502. ////////////////////////////////////////////////////////////////////////////
  1503.  
  1504. void Draw_Score(void)
  1505. {
  1506.  
  1507. // this function draws the players score in the display module
  1508.  
  1509. char buffer[128];
  1510.  
  1511. // show the score
  1512.  
  1513. sprintf(buffer,"%ld",players_score);
  1514.  
  1515. Blit_String_DB(55,180,10,buffer,0);
  1516.  
  1517. } // end Draw_Score
  1518.  
  1519. /////////////////////////////////////////////////////////////////////////////
  1520.  
  1521. void Rotate_Lights(void)
  1522. {
  1523. // this is a self contained functions that uses color rotation to make the
  1524. // lights on the cannon rotate
  1525.  
  1526. static int clock=0,       // used for timing, note: they are static!
  1527.            entered_yet=0;
  1528.  
  1529. RGB_color color,          // used to hold color values during processing
  1530.           color_1,
  1531.           color_2,
  1532.           color_3;
  1533.  
  1534. // test if function is being called for first time
  1535.  
  1536. if (!entered_yet)
  1537.    {
  1538.  
  1539.    // reset the palette registers to bright blue, dark blue, dark blue
  1540.  
  1541.    color.red   = 0;
  1542.    color.green = 0;
  1543.    color.blue  = 63;
  1544.  
  1545.    Set_Palette_Register(246,(RGB_color_ptr)&color);
  1546.  
  1547.    color.blue  = 20;
  1548.  
  1549.    Set_Palette_Register(247,(RGB_color_ptr)&color);
  1550.    Set_Palette_Register(248,(RGB_color_ptr)&color);
  1551.  
  1552.    // system has initialized, so flag it
  1553.  
  1554.    entered_yet=1;
  1555.  
  1556.    } // end if first time into function
  1557.  
  1558. // try and rotate the light colors i.e. color rotation
  1559.  
  1560.    if (++clock==5)  // is it time to rotate
  1561.       {
  1562.       // get the colors
  1563.  
  1564.       Get_Palette_Register(246,(RGB_color_ptr)&color_1);
  1565.       Get_Palette_Register(247,(RGB_color_ptr)&color_2);
  1566.       Get_Palette_Register(248,(RGB_color_ptr)&color_3);
  1567.  
  1568.       // set the colors
  1569.  
  1570.       Set_Palette_Register(248,(RGB_color_ptr)&color_1);
  1571.       Set_Palette_Register(246,(RGB_color_ptr)&color_2);
  1572.       Set_Palette_Register(247,(RGB_color_ptr)&color_3);
  1573.  
  1574.       // reset the clock
  1575.  
  1576.       clock=0;
  1577.  
  1578.       } // end if time to rotate
  1579.  
  1580. } // end Rotate_Lights
  1581.  
  1582. ////////////////////////////////////////////////////////////////////////////
  1583.  
  1584. void Start_Wave(void)
  1585. {
  1586. // this function is used to start a wave, it resets all the system variables
  1587.  
  1588. // reset number of ships that got away
  1589.  
  1590. got_away_this_wave        = 0;
  1591.  
  1592. // reset wave end and clock
  1593.  
  1594. wave_end        = 0;
  1595.  
  1596. wave_clock      = 0;
  1597.  
  1598. // reset number of ships hit this wave
  1599.  
  1600. hits_this_wave  = 0;
  1601.  
  1602. ships_large_hit = 0;
  1603.  
  1604. ships_small_hit = 0;
  1605.  
  1606. ships_boat_hit  = 0;
  1607.  
  1608. // reset number of ships so far
  1609.  
  1610. ships_so_far    = 0;
  1611.  
  1612. // more ships as the wave number increases
  1613.  
  1614. ships_this_wave = 10 + wave_number*2;
  1615.  
  1616. // increase wave number
  1617.  
  1618. wave_number++;
  1619.  
  1620. } // end Start_Wave
  1621.  
  1622. /////////////////////////////////////////////////////////////////////////////
  1623.  
  1624. void Erase_End_Wave(void)
  1625. {
  1626. // this function is used to erase the imagery drawn by the end of wave display
  1627.  
  1628. int index;  // loop index
  1629.  
  1630. // draw a big  blue rectangle in area where stats will be displayed
  1631.  
  1632. for (index=40; index<=132; index++)
  1633.     {
  1634.  
  1635.     _fmemset((char far *)(double_buffer+((index<<8)+(index<<6))+88),
  1636.               WATER_COLOR,162);
  1637.  
  1638.     } // end for index
  1639.  
  1640. } // end Erase_End_Wave
  1641.  
  1642. /////////////////////////////////////////////////////////////////////////////
  1643.  
  1644. void Draw_End_Wave(void)
  1645. {
  1646. // this function is used to draw the imagery drawn by the end of wave display
  1647. // also note how it is self contained
  1648.  
  1649. static int entered=0;  // used to flag if the function has been entered once
  1650.  
  1651. char buffer[128];      // used for string printing
  1652.  
  1653. int bonus;             // used to compute players bonus
  1654.  
  1655. // should we play sound
  1656.  
  1657. if (!entered)
  1658.    {
  1659.    Play_Sound(SOUND_WAVE);
  1660.    entered=1;
  1661.    } // end if first time
  1662.  
  1663. // draw text
  1664.  
  1665. sprintf(buffer,"WAVE #%d...COMPLETE!",wave_number);
  1666.  
  1667. Blit_String_DB(88,40,12,buffer,1);
  1668.  
  1669. sprintf(buffer,"Hits        Target");
  1670.  
  1671. Blit_String_DB(88,50,15,buffer,1);
  1672.  
  1673. sprintf(buffer,"%d",ships_large_hit);
  1674.  
  1675. Blit_String_DB(96,64,15,buffer,1);
  1676.  
  1677. sprintf(buffer,"%d",ships_small_hit);
  1678.  
  1679. Blit_String_DB(96,64+20,15,buffer,1);
  1680.  
  1681. sprintf(buffer,"%d",ships_boat_hit);
  1682.  
  1683. Blit_String_DB(96,64+40,15,buffer,1);
  1684.  
  1685. // compute bonus and display
  1686.  
  1687. bonus = (ships_this_wave - got_away_this_wave) * 25;
  1688.  
  1689. sprintf(buffer,"BONUS  %d",bonus);
  1690.  
  1691. Blit_String_DB(88,64+60,10,buffer,1);
  1692.  
  1693. // draw icons
  1694.  
  1695. SET_SPRITE_SIZE(48,64);
  1696.  
  1697. Draw_Sprite_DB((sprite_ptr)&icons);
  1698.  
  1699. // increment counter and test
  1700.  
  1701. if (++wave_clock>75)
  1702.    {
  1703.  
  1704.    // add up total ships that got away to running total
  1705.  
  1706.    total_got_away+=got_away_this_wave;
  1707.  
  1708.    // start system back up
  1709.  
  1710.    Start_Wave();
  1711.  
  1712.    Erase_End_Wave();
  1713.  
  1714.    // add bonus to players score
  1715.  
  1716.    players_score+=bonus;
  1717.  
  1718.    // reset static
  1719.  
  1720.    entered=0;
  1721.  
  1722.    } // end if
  1723.  
  1724. } // end Draw_End_Wave
  1725.  
  1726. ////////////////////////////////////////////////////////////////////////////
  1727.  
  1728. void Load_Subs(void)
  1729. {
  1730. // this function loads the imagery for the subs
  1731.  
  1732. int index;  // looping index
  1733.  
  1734. // load in imagery for small subs
  1735.  
  1736. PCX_Init((pcx_picture_ptr)&imagery_pcx);
  1737.  
  1738. PCX_Load("sharksb1.pcx", (pcx_picture_ptr)&imagery_pcx,1);
  1739.  
  1740.  
  1741. SET_SPRITE_SIZE(32,10);
  1742.  
  1743. // load in frames for subs
  1744.  
  1745. for (index=0; index<=3; index++)
  1746.     {
  1747.  
  1748.  
  1749.     Sprite_Init((sprite_ptr)&subs[index].object,0,0,0,0,0,0);
  1750.  
  1751.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1752.                     (sprite_ptr)&subs[index].object,0,0,0);
  1753.  
  1754.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1755.                     (sprite_ptr)&subs[index].object,1,1,0);
  1756.  
  1757.     // set up fields
  1758.  
  1759.     subs[index].object.curr_frame = 0;
  1760.     subs[index].type              = SUB_SMALL;
  1761.     subs[index].state             = SUB_DEAD;
  1762.     subs[index].object.width      = 32;
  1763.     subs[index].object.height     = 10;
  1764.  
  1765.     } // end for index
  1766.  
  1767. // delete the pcx file
  1768.  
  1769. PCX_Delete((pcx_picture_ptr)&imagery_pcx);
  1770.  
  1771.  
  1772.  
  1773. // load in imagery for large subs
  1774.  
  1775. PCX_Init((pcx_picture_ptr)&imagery_pcx);
  1776.  
  1777. PCX_Load("sharksb2.pcx", (pcx_picture_ptr)&imagery_pcx,1);
  1778.  
  1779. SET_SPRITE_SIZE(48,20);
  1780.  
  1781. for (index=4; index<=7; index++)
  1782.     {
  1783.  
  1784.     Sprite_Init((sprite_ptr)&subs[index].object,0,0,0,0,0,0);
  1785.  
  1786.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1787.                     (sprite_ptr)&subs[index].object,0,0,0);
  1788.  
  1789.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1790.                     (sprite_ptr)&subs[index].object,1,1,0);
  1791.  
  1792.     // set up fields
  1793.  
  1794.     subs[index].object.curr_frame = 0;
  1795.     subs[index].type              = SUB_LARGE;
  1796.     subs[index].state             = SUB_DEAD;
  1797.     subs[index].object.width      = 48;
  1798.     subs[index].object.height     = 20;
  1799.  
  1800.     } // end for index
  1801.  
  1802. // delete the pcx file
  1803.  
  1804. PCX_Delete((pcx_picture_ptr)&imagery_pcx);
  1805.  
  1806.  
  1807.  
  1808. // load in imagery for boats
  1809.  
  1810. PCX_Init((pcx_picture_ptr)&imagery_pcx);
  1811.  
  1812. PCX_Load("sharkbot.pcx", (pcx_picture_ptr)&imagery_pcx,1);
  1813.  
  1814. SET_SPRITE_SIZE(24,8);
  1815.  
  1816. for (index=8; index<=11; index++)
  1817.     {
  1818.  
  1819.     Sprite_Init((sprite_ptr)&subs[index].object,0,0,0,0,0,0);
  1820.  
  1821.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1822.                     (sprite_ptr)&subs[index].object,0,0,0);
  1823.  
  1824.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1825.                     (sprite_ptr)&subs[index].object,1,1,0);
  1826.  
  1827.     // set up fields
  1828.  
  1829.     subs[index].object.curr_frame = 0;
  1830.     subs[index].type              = SUB_BOAT;
  1831.     subs[index].state             = SUB_DEAD;
  1832.     subs[index].object.width      = 24;
  1833.     subs[index].object.height     = 8;
  1834.  
  1835.     } // end for index
  1836.  
  1837. // delete the pcx file
  1838.  
  1839. PCX_Delete((pcx_picture_ptr)&imagery_pcx);
  1840.  
  1841. // load in imagery for ship icons
  1842.  
  1843. PCX_Init((pcx_picture_ptr)&imagery_pcx);
  1844.  
  1845. PCX_Load("sharkicn.pcx", (pcx_picture_ptr)&imagery_pcx,1);
  1846.  
  1847. // initialize icons and extract bitmaps
  1848.  
  1849. SET_SPRITE_SIZE(48,64);
  1850.  
  1851. Sprite_Init((sprite_ptr)&icons,0,0,0,0,0,0);
  1852.  
  1853. PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,(sprite_ptr)&icons,0,0,0);
  1854.  
  1855. icons.x          = 200;
  1856. icons.y          = 56;
  1857. icons.curr_frame = 0;
  1858. icons.state      = 1;
  1859.  
  1860. // delete the pcx file
  1861.  
  1862. PCX_Delete((pcx_picture_ptr)&imagery_pcx);
  1863.  
  1864. } // end Load_Subs
  1865.  
  1866. ///////////////////////////////////////////////////////////////////////////////
  1867.  
  1868. void Load_Player(void)
  1869. {
  1870. // this function loads the imagery for the players
  1871.  
  1872. int index;  // loop index
  1873.  
  1874. // load in imagery for player's gun
  1875.  
  1876. PCX_Init((pcx_picture_ptr)&imagery_pcx);
  1877.  
  1878. PCX_Load("sharkgun.pcx", (pcx_picture_ptr)&imagery_pcx,1);
  1879.  
  1880. // initialize player and extract bitmaps
  1881.  
  1882. SET_SPRITE_SIZE(24,24);
  1883.  
  1884. Sprite_Init((sprite_ptr)&player,0,0,0,0,0,0);
  1885.  
  1886. PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,(sprite_ptr)&player,0,0,0);
  1887. PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,(sprite_ptr)&player,1,1,0);
  1888. PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,(sprite_ptr)&player,2,2,0);
  1889.  
  1890. player.x          = 148;
  1891. player.y          = 149;
  1892. player.curr_frame = CANNON_NORTH;
  1893. player.state      = 1;
  1894.  
  1895. // delete the pcx file
  1896.  
  1897. PCX_Delete((pcx_picture_ptr)&imagery_pcx);
  1898.  
  1899. // load in imagery for missiles
  1900.  
  1901. PCX_Init((pcx_picture_ptr)&imagery_pcx);
  1902.  
  1903. PCX_Load("sharkmis.pcx", (pcx_picture_ptr)&imagery_pcx,1);
  1904.  
  1905. // initialize player and extract bitmaps
  1906.  
  1907. SET_SPRITE_SIZE(8,8);
  1908.  
  1909. // initialize the sprite for each missile
  1910.  
  1911. for (index=0; index<NUM_MISSILES; index++)
  1912.     {
  1913.  
  1914.     Sprite_Init((sprite_ptr)&missiles[index].object,0,0,0,0,0,0);
  1915.  
  1916.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1917.                     (sprite_ptr)&missiles[index].object,0,0,0);
  1918.  
  1919.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1920.                     (sprite_ptr)&missiles[index].object,1,1,0);
  1921.  
  1922.  
  1923.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1924.                     (sprite_ptr)&missiles[index].object,2,2,0);
  1925.  
  1926.     // set some important fields
  1927.  
  1928.     missiles[index].x                 = 0;
  1929.     missiles[index].y                 = 0;
  1930.     missiles[index].object.curr_frame = 0;
  1931.     missiles[index].state             = MISS_DEAD;
  1932.  
  1933.     } // end for
  1934.  
  1935. // delete the pcx file
  1936.  
  1937. PCX_Delete((pcx_picture_ptr)&imagery_pcx);
  1938.  
  1939.  
  1940. } // end Load_Player
  1941.  
  1942. ///////////////////////////////////////////////////////////////////////////////
  1943.  
  1944. void Load_Explosions(void)
  1945. {
  1946. // this function loads the imagery for the explosions (note there are 3 versions)
  1947.  
  1948. int index,  // loop variable
  1949.     row;    // used to select a random explosion
  1950.  
  1951. // load in imagery for explosions
  1952.  
  1953. PCX_Init((pcx_picture_ptr)&imagery_pcx);
  1954.  
  1955. PCX_Load("sharkexp.pcx", (pcx_picture_ptr)&imagery_pcx,1);
  1956.  
  1957. // initialize the explosions and extract bitmaps
  1958.  
  1959. SET_SPRITE_SIZE(32,32);
  1960.  
  1961. // load in frames for explosions
  1962.  
  1963. for (index=0; index<NUM_EXPLOSIONS; index++)
  1964.     {
  1965.  
  1966.     // select a random explosion to place in sprite
  1967.  
  1968.     row = rand()%2;
  1969.  
  1970.     Sprite_Init((sprite_ptr)&explosions[index],0,0,0,0,0,0);
  1971.  
  1972.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1973.                     (sprite_ptr)&explosions[index],0,0,row);
  1974.  
  1975.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1976.                     (sprite_ptr)&explosions[index],1,1,row);
  1977.  
  1978.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1979.                     (sprite_ptr)&explosions[index],2,2,row);
  1980.  
  1981.     PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  1982.                     (sprite_ptr)&explosions[index],3,3,row);
  1983.  
  1984.     } // end for
  1985.  
  1986. // delete the pcx file
  1987.  
  1988. PCX_Delete((pcx_picture_ptr)&imagery_pcx);
  1989.  
  1990. } // end Load_Explosions
  1991.  
  1992. //////////////////////////////////////////////////////////////////////////////
  1993.  
  1994. void Do_Intro(void)
  1995. {
  1996. // this function displays the introduction screen and then melts it
  1997.  
  1998. // load intro screen and display for a few secs.
  1999.  
  2000. PCX_Init((pcx_picture_ptr)&intro_pcx);
  2001.  
  2002. PCX_Load("sharkint.pcx", (pcx_picture_ptr)&intro_pcx,1);
  2003.  
  2004. PCX_Show_Buffer((pcx_picture_ptr)&intro_pcx);
  2005.  
  2006. // let user see it
  2007.  
  2008. Delay(50);
  2009.  
  2010. Fade_Lights();
  2011.  
  2012. PCX_Delete((pcx_picture_ptr)&intro_pcx);
  2013.  
  2014. // load in the background image into the double buffer
  2015.  
  2016. PCX_Init((pcx_picture_ptr)&background_pcx);
  2017.  
  2018. PCX_Load("sharkbak.pcx", (pcx_picture_ptr)&background_pcx,1);
  2019.  
  2020. // copy the background into the double buffer
  2021.  
  2022. _fmemcpy((char far *)double_buffer,
  2023.          (char far *)(background_pcx.buffer),
  2024.          SCREEN_WIDTH*SCREEN_HEIGHT);
  2025.  
  2026. PCX_Delete((pcx_picture_ptr)&background_pcx);
  2027.  
  2028.  
  2029. } // end Do_Intro
  2030.  
  2031. //////////////////////////////////////////////////////////////////////////////
  2032.  
  2033. void Show_Instructions(void)
  2034. {
  2035. // this function displays the instructions and then disolves them
  2036.  
  2037. // load instruction screen and display it until a key press
  2038.  
  2039. PCX_Init((pcx_picture_ptr)&intro_pcx);
  2040.  
  2041. PCX_Load("sharkins.pcx", (pcx_picture_ptr)&intro_pcx,1);
  2042.  
  2043. PCX_Show_Buffer((pcx_picture_ptr)&intro_pcx);
  2044.  
  2045. // let user see it
  2046.  
  2047. while(!kbhit()){};
  2048.  
  2049. getch();
  2050.  
  2051. Disolve();
  2052.  
  2053. PCX_Delete((pcx_picture_ptr)&intro_pcx);
  2054.  
  2055. } // end Show_Instructions
  2056.  
  2057. // M A I N /////////////////////////////////////////////////////////////////
  2058.  
  2059. void main(void)
  2060. {
  2061.  
  2062. int done=0,    // main event loop exit flag
  2063.     index;     // loop variable
  2064.  
  2065. char buffer[128]; // used for string printing
  2066.  
  2067. printf("\nStarting Sea Shark...");
  2068.  
  2069. // initialize sound system
  2070.  
  2071. sound_available = Initialize_Sound_System();
  2072.  
  2073. Delay(100);
  2074.  
  2075. // set video mode to 320x200 256 color mode
  2076.  
  2077. Set_Video_Mode(VGA256);
  2078.  
  2079. // create a double buffer
  2080.  
  2081. if (!Create_Double_Buffer(SCREEN_HEIGHT))
  2082.    {
  2083.    printf("\nNot enough memory to create double buffer.");
  2084.  
  2085.    } // end if
  2086.  
  2087. // clear the double buffer
  2088.  
  2089. Fill_Double_Buffer(0);
  2090.  
  2091. // impress user (at least try to)
  2092.  
  2093. Do_Intro();
  2094.  
  2095. // show instructions
  2096.  
  2097. Show_Instructions();
  2098.  
  2099. // load imagery for game
  2100.  
  2101. Load_Player();
  2102.  
  2103. Load_Explosions();
  2104.  
  2105. Load_Subs();
  2106.  
  2107. // initialize everything
  2108.  
  2109. Init_Missiles();
  2110.  
  2111. Init_Bubbles();
  2112.  
  2113. Init_Explosions();
  2114.  
  2115. Init_Subs();
  2116.  
  2117. // start up wave one
  2118.  
  2119. Start_Wave();
  2120.  
  2121. // scan background first time around under everything
  2122.  
  2123. // set sprite size for engine and scan background under player
  2124.  
  2125. SET_SPRITE_SIZE(24,24);
  2126.  
  2127. Behind_Sprite_DB((sprite_ptr)&player);
  2128.  
  2129. // begin main event loop
  2130.  
  2131. while(!done)
  2132.      {
  2133.  
  2134.      // erase all objects
  2135.  
  2136.      // set sprite size for engine
  2137.  
  2138.      SET_SPRITE_SIZE(24,24);
  2139.  
  2140.      Erase_Sprite_DB((sprite_ptr)&player);
  2141.  
  2142.      // erase missiles
  2143.  
  2144.      Erase_Missiles();
  2145.  
  2146.      // erase bubbles
  2147.  
  2148.      Erase_Bubbles();
  2149.  
  2150.      // erase explosions
  2151.  
  2152.      Erase_Explosions();
  2153.  
  2154.      // erase subs
  2155.  
  2156.      Erase_Subs();
  2157.  
  2158.      if (wave_end)
  2159.         Erase_End_Wave();
  2160.  
  2161.      // move all objects
  2162.  
  2163.      // test for keyboard press
  2164.  
  2165.      if (kbhit())
  2166.         {
  2167.  
  2168.         // what does user want to do?
  2169.  
  2170.         switch(getch())
  2171.               {
  2172.  
  2173.               case 'a': // move cannon one to the left
  2174.                       {
  2175.  
  2176.                       // decrement animation cell
  2177.  
  2178.                       if (--player.curr_frame<0)
  2179.                          player.curr_frame=0;
  2180.  
  2181.                       } break;
  2182.  
  2183.               case 's': // move cannon one to the right
  2184.                       {
  2185.  
  2186.                       // increment animation cell
  2187.  
  2188.                       if (++player.curr_frame==3)
  2189.                          player.curr_frame=2;
  2190.  
  2191.                       } break;
  2192.  
  2193.  
  2194.               case ' ': // start a missile
  2195.                       {
  2196.  
  2197.                       // try and start a missile
  2198.                       // remember to use direction and velocity look up
  2199.                       // so that direction of cannon is taken into
  2200.                       // consideration!
  2201.  
  2202.                       Start_Missile((sprite_ptr)&player,
  2203.                                     player.x+cannon_pos_x[player.curr_frame],
  2204.                                     player.y+cannon_pos_y[player.curr_frame],
  2205.                                     cannon_vel_x[player.curr_frame],
  2206.                                     cannon_vel_y[player.curr_frame],
  2207.                                     PLAYER_MISSILE);
  2208.  
  2209.                       } break;
  2210.  
  2211.               case 'q': // trying to exit
  2212.                       {
  2213.                       // set global exit flag
  2214.                       done=1;
  2215.  
  2216.                       } break;
  2217.  
  2218.               default:break;
  2219.  
  2220.               } // end switch
  2221.  
  2222.         } // end if kbhit
  2223.  
  2224.      // move subs
  2225.  
  2226.      Move_Subs();
  2227.  
  2228.      // move missiles
  2229.  
  2230.      Move_Missiles();
  2231.  
  2232.      // move bubbles
  2233.  
  2234.      Move_Bubbles();
  2235.  
  2236.      // animate explosions
  2237.  
  2238.      Animate_Explosions();
  2239.  
  2240.      // test if it's end of a wave
  2241.  
  2242.      if (game_over==0 && (got_away_this_wave+hits_this_wave >= ships_this_wave-1))
  2243.         {
  2244.         // set end of wave flag
  2245.  
  2246.         wave_end=1;
  2247.  
  2248.         // reset all subs so that they disapear
  2249.  
  2250.         Init_Subs();
  2251.  
  2252.         } // end if end of wave
  2253.  
  2254.      // BEGIN CRITICAL SECTION - this is where we can start new objects and
  2255.      // not have a problem
  2256.  
  2257.      // should a sub be sent out
  2258.  
  2259.      if (game_over==0 && wave_end==0 && (rand()%50)==0)
  2260.          Start_Sub();
  2261.  
  2262.      // test if the game is over
  2263.  
  2264.      if (total_got_away > 100 && game_over==0)
  2265.         {
  2266.         // set flag that game is over
  2267.  
  2268.         game_over=1;
  2269.  
  2270.         // allow game over sequence to last for 100 frames
  2271.  
  2272.         game_over_clock=100;
  2273.  
  2274.         } // end if game over
  2275.  
  2276.      // should we do the game over sequence
  2277.  
  2278.      if (game_over && game_over_clock > 0)
  2279.         {
  2280.  
  2281.         // start an explosion somewhere
  2282.  
  2283.         Start_Explosion(rand()%300, rand()%160, rand()%3);
  2284.  
  2285.         // draw score
  2286.  
  2287.         sprintf(buffer,"G A M E  O V E R !",wave_number);
  2288.  
  2289.         Blit_String_DB(84,64,12,buffer,1);
  2290.  
  2291.         sprintf(buffer,"Final Score %ld",players_score);
  2292.  
  2293.         Blit_String_DB(84,80,10,buffer,1);
  2294.  
  2295.         // test if it's time to exit game
  2296.  
  2297.         if (--game_over_clock==0)
  2298.            done=1;  // set main event loop exit flag
  2299.  
  2300.         } // end if game over sequence
  2301.  
  2302.  
  2303.      // END CRITICAL SECTION
  2304.  
  2305.  
  2306.      // now we scan and draw all objects
  2307.  
  2308.      // set sprite size for engine
  2309.  
  2310.      SET_SPRITE_SIZE(24,24);
  2311.      Behind_Sprite_DB((sprite_ptr)&player);
  2312.  
  2313.      Behind_Missiles();
  2314.  
  2315.      Behind_Subs();
  2316.  
  2317.      Behind_Bubbles();
  2318.  
  2319.      Behind_Explosions();
  2320.  
  2321.      // set sprite size for engine
  2322.  
  2323.      SET_SPRITE_SIZE(24,24);
  2324.      Draw_Sprite_DB((sprite_ptr)&player);
  2325.  
  2326.      Draw_Subs();
  2327.  
  2328.      Draw_Missiles();
  2329.  
  2330.      Draw_Bubbles();
  2331.  
  2332.      Draw_Explosions();
  2333.  
  2334.      Draw_Score();
  2335.  
  2336.      // test if the wave is over and statistics need to be displayed
  2337.  
  2338.      if (wave_end)
  2339.         Draw_End_Wave();
  2340.  
  2341.      // display double buffer
  2342.  
  2343.      Show_Double_Buffer((char far *)double_buffer);
  2344.  
  2345.      // do all color palette animation
  2346.  
  2347.      Rotate_Lights();
  2348.  
  2349.      // wait a sec
  2350.  
  2351.      Delay(1);
  2352.  
  2353.      } // end while
  2354.  
  2355. // were out of here!
  2356.  
  2357. Play_Sound(SOUND_END);
  2358.  
  2359. // exit system with a cool transition
  2360.  
  2361. Melt();
  2362.  
  2363. // reset the video mode back to text
  2364.  
  2365. Set_Video_Mode(TEXT_MODE);
  2366.  
  2367. // free the double buffer
  2368.  
  2369. Delete_Double_Buffer();
  2370.  
  2371. // close sound system
  2372.  
  2373. Close_Sound_System();
  2374.  
  2375. } // end main
  2376.  
  2377.  
  2378.