home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / borland / chap_18 / krkm0.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-27  |  36.2 KB  |  1,176 lines

  1.  
  2. // KRK.C - Version 1.0, Andre' LaMothe
  3.  
  4. // I N C L U D E S ///////////////////////////////////////////////////////////
  5.  
  6. #include <io.h>
  7. #include <conio.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <dos.h>
  11. #include <bios.h>
  12. #include <fcntl.h>
  13. #include <memory.h>
  14. #include <malloc.h>
  15. #include <math.h>
  16. #include <string.h>
  17.  
  18. // include all of our stuff
  19.  
  20. #include "black3.h"
  21. #include "black4.h"
  22. #include "black5.h"
  23. #include "black6.h"
  24. #include "black8.h"
  25. #include "black9.h"
  26.  
  27. #include "black18.h"    // the newest version of the 3-D library
  28. #include "krkm0.h"
  29.  
  30. // G L O B A L S  ////////////////////////////////////////////////////////////
  31.  
  32. object static_obj[NUM_STATIONARY];      // there are six basic stationary object types
  33.  
  34. fixed_obj obstacles_1[NUM_OBSTACLES_1]; // general obstacles, rocks etc.
  35. fixed_obj obstacles_2[NUM_OBSTACLES_2]; // general obstacles, rocks etc.
  36.  
  37. fixed_obj barriers[NUM_BARRIERS];       // boundary universe boundaries
  38. fixed_obj towers[NUM_TOWERS];           // the control towers
  39. fixed_obj stations[NUM_STATIONS];       // the power stations
  40. fixed_obj telepods[NUM_TELEPODS];       // the teleporters
  41.  
  42.  
  43. object dynamic_obj[NUM_DYNAMIC];        // this array holds the models
  44.                                         // for the dynamic game objects
  45.  
  46. alien aliens[NUM_ALIENS];               // take a wild guess!
  47.  
  48. missile_obj missiles[NUM_MISSILES];     // holds the missiles
  49.  
  50. int active_player_missiles = 0;         // how many missiles has player activated
  51.  
  52. int total_active_missiles = 0;          // total active missiles
  53.  
  54. layer mountains;              // the background mountains
  55.  
  56. pcx_picture image_pcx,        // general PCX image used to load background and imagery
  57.             image_controls;   // this holds the controls screen
  58.  
  59. sprite tactical_spr,          // holds the images for the tactical displays
  60.        buttons_spr;           // holds the images for the control buttons
  61.  
  62. RGB_color color_1,color_2;    // used for temporaries during color rotation
  63.  
  64. RGB_palette game_palette;     // this will hold the startup system palette
  65.  
  66. bitmap tech_font[NUM_TECH_FONT];   // the tech font bitmaps
  67.  
  68. int game_state = GAME_SETUP;       // the overall state of the game
  69.  
  70. int scanner_state  = 0,            // state of scanner
  71.     hud_state      = 0,
  72.     tactical_state = TACTICAL_MODE_OFF;
  73.  
  74. int ship_pitch  = 0,   // current direction of ship
  75.     ship_yaw    = 0,   // not used
  76.     ship_roll   = 0,   // not used
  77.     ship_speed  = 0,   // speed of ship
  78.     ship_energy = 50,  // current energy of ship
  79.     ship_damage = 0,   // current damage up to 50 points
  80.     ship_message = 0,  // current message to ship state machine
  81.     ship_timer   = 0,  // a little timer
  82.     ship_kills   = 0,  // how many bad guys has player killed
  83.     ship_deaths  = 0;  // how many times has player been killed
  84.  
  85. vector_3d unit_z          = {0,0,1,1},  // a unit vector in the Z direction
  86.           ship_direction  = {0,0,1,1};  // the ships direction
  87.  
  88. int players_ship_type = PLAYER_TALLON;  // the player starts off with a tallon
  89.  
  90. // musical sequence information
  91.  
  92. int music_enabled   = 0,      // flags that enable music and sound FX
  93.     digital_enabled = 0;
  94.  
  95. int digital_FX_priority = 10; // the priority tracker of the current effect
  96.  
  97. int intro_sequence[] = {0+12,1+12,2+12,3+12,1+12,2+12,3+12,2+12,3+12,1+12,
  98.                         2+12,3+12,2+12,2+12};
  99.  
  100. int intro_seq_index  = 0; // starting intro index number of sequence to be played
  101.  
  102. int game_sequence[]  = {11,8,2,3,1,2,5,8,6,1,0,2,4,5,2,1,0,3,4,8};
  103.  
  104. int game_seq_index   = 0; // starting game index number of sequence to be played
  105.  
  106. music song;    // the music structure
  107.  
  108. // sound fx stuff
  109.  
  110. _sound digital_FX[NUM_SOUND_FX];
  111.  
  112. // basic colors
  113.  
  114. RGB_color  bright_red   = {63,0,0},    // bright red
  115.            bright_blue  = {0,0,63},    // bright blue
  116.            bright_green = {0,63,0},    // bright green
  117.  
  118.            medium_red   = {48,0,0},    // medium red
  119.            medium_blue  = {0,0,48},    // medium blue
  120.            medium_green = {0,48,0},    // medium green
  121.  
  122.            dark_red     = {32,0,0},    // dark red
  123.            dark_blue    = {0,0,32},    // dark blue
  124.            dark_green   = {0,32,0},    // dark green
  125.  
  126.                   black = {0,0,0},     // pure black
  127.                   white = {63,63,63},  // pure white
  128.  
  129.            color_1,color_2,color_3;    // general color variables
  130.  
  131. // the instruction pages
  132.  
  133. char *instructions[]={"KILL OR BE KILLED                  ",
  134.                       "                                   ",
  135.                       "INTERGALACTIC BATTLE FEDERATION    ",
  136.                       "THESE RULES APPLY TO ALL ENTRIES   ",
  137.                       "                                   ",
  138.                       "1. YOU MAY FREELY DESTROY ALL AND  ",
  139.                       "   ANY ENEMY THAT YOU MAY MEET UP  ",
  140.                       "   WITH.                           ",
  141.                       "                                   ",
  142.                       "2. ANY PARTICIPANT EXHIBITING MERCY",
  143.                       "   IN ANY FORM WILL BE SUMMARILY   ",
  144.                       "   TERMINATED. YOU MUST KILL!      ",
  145.                       "                                   ",
  146.                       "3. LEAVING THE GAME GRID WHILE     ",
  147.                       "   THERE ARE ANY OPPONENTS ALIVE IS",
  148.                       "   FORBIDDEN.                      ",
  149.                       "                1                  ",
  150.  
  151.                       "PLAYING THE GAME                   ",
  152.                       "                                   ",
  153.                       "AT THE MAIN MENU SELECT THE BATTLE ",
  154.                       "MECH THAT YOU WISH TO PLAY WITH    ",
  155.                       "BY USING THE (SELECT MECH) OPTION  ",
  156.                       "ITEM. YOU WILL THEN BE SENT TO     ",
  157.                       "THE HOLOGRAPHIC SPECIFICATION AREA.",
  158.                       "                                   ",
  159.                       "USE THE RIGHT AND LEFT ARROW KEYS  ",
  160.                       "TO VIEW DIFFERENT MECHS. WHEN YOU  ",
  161.                       "ARE SATIFIED THEN PRESS (ENTER).   ",
  162.                       "                                   ",
  163.                       "TO EXIT WITHOUT MAKING A SELECTION ",
  164.                       "PRESS (ESC).                       ",
  165.                       "                                   ",
  166.                       "                                   ",
  167.                       "                2                  ",
  168.  
  169.                       "AFTER YOU HAVE SELECTED A MECH THEN",
  170.                       "SELECT THE (CHALLENGE) ITEM OF THE ",
  171.                       "MAIN MENU. YOU WILL ENTER INTO THE ",
  172.                       "GAME AREA AT ITS EXACT CENTER.     ",
  173.                       "                                   ",
  174.                       "THE GAME AREA CONSISTS OF OBSTACLES",
  175.                       "SUCH AS ROCKS AND CRYSTAL GROWTHS. ",
  176.                       "                                   ",
  177.                       "AROUND THE PERIMETER OF THE GAME   ",
  178.                       "GRID IS AN LASER BARRIER SYSTEM    ",
  179.                       "POWERED BY LARGE BLACK MONOLITHS   ",
  180.                       "WITH GREEN BEACONS. STAY AWAY FROM ",
  181.                       "THESE IF POSSIBLE. AS NOTED ABOVE  ",
  182.                       "YOU WILL BE POSITIONED AT THE EXACT",
  183.                       "CENTER OF THE GAME GRID. IN FACT,  ",
  184.                       "THE POSITION YOU ARE STARTED AT    ",
  185.                       "                3                  ",
  186.  
  187.                       "IS THE LOCATION OF THE MAIN POWER  ",
  188.                       "SOURCE FOR THE GAME GRID. IT MAY BE",
  189.                       "POSSIBLE TO RE-CHARGE BY DRIVING   ",
  190.                       "OVER THIS ROTATING ENERGY SOURCE.  ",
  191.                       "                                   ",
  192.                       "HOWEVER, THERE ARE FOUR COM TOWERS ",
  193.                       "OVERLOOKING THIS CENTRAL POWER     ",
  194.                       "STATION AND ENTRIES TRYING TO STEEL",
  195.                       "POWER MAY BE DEALT WITH...         ",
  196.                       "                                   ",
  197.                       "FINALLY TO MAKE THE GAME MORE      ",
  198.                       "INTERESTING THERE ARE FOUR TELEPODS",
  199.                       "LOCATED AT THE FOUR CORNERS OF THE ",
  200.                       "GAME GRID. TO TELEPORT TO ANOTHER  ",
  201.                       "POD, SIMPLY NAVIGATE UNDER ONE OF  ",
  202.                       "THE PODS.                          ",
  203.                       "                4                  ",
  204.  
  205.                       "CONTROLING THE SHIP                ",
  206.                       "                                   ",
  207.                       "BOTH SHIPS HAVE THE SAME CONTROLS  ",
  208.                       "THEREFORE THE FOLLOWING EXPLAINA-  ",
  209.                       "TION IS VALID FOR BOTH TALLON AND  ",
  210.                       "SLIDER PILOTS.                     ",
  211.                       "                                   ",
  212.                       "INFORMATION DISPLAYS               ",
  213.                       "                                   ",
  214.                       "THE SHIPS ARE FITTED WITH THE      ",
  215.                       "FOLLOWING DISPLAYS.                ",
  216.                       "                                   ",
  217.                       "1. SCANNERS                        ",
  218.                       "2. HEADS UP DISPLAY (HUD)          ",
  219.                       "3. MULTI-FUNCTION DISPLAY (MFD)    ",
  220.                       "                                   ",
  221.                       "                5                  ",
  222.  
  223.                       "ENGAGING THE DISPLAYS              ",
  224.                       "                                   ",
  225.                       " SCANNER....S TOGGLES              ",
  226.                       " HUD........H TOGGLES              ",
  227.                       " MFD........T TO SELECT VARIOUS    ",
  228.                       "              DATA OUTPUTS.        ",
  229.                       "                                   ",
  230.                       "THE SCANNER IS LOCATED ON THE LEFT ",
  231.                       "MAIN VIEW SCREEN AND THE MFD IS    ",
  232.                       "LOCATED ON THE RIGHT MAIN VIEWING  ",
  233.                       "SCREEN.                            ",
  234.                       "                                   ",
  235.                       "THE SCANNER REPRESENTS YOU AS A    ",
  236.                       "BLUE BLIP AND YOU ENEMIES AS RED.  ",
  237.                       "OTHER IMPORTANT OBJECTS ARE ALSO   ",
  238.                       "SCANNED AND DISPLAYED.             ",
  239.                       "                6                  ",
  240.  
  241.                       "THE MFD IS CURRENTLY FIT TO DISPLAY",
  242.                       "TWO MAIN DATA SETS. THE FIRST IS   ",
  243.                       "THE SHIPS SPEED, DAMAGE AND ENERGY ",
  244.                       "IN LINEAR GRAPHS AND THE SECOND IS ",
  245.                       "AN OUTSIDE HULL DAMAGE SYSTEM.     ",
  246.                       "                                   ",
  247.                       "THE HUD IS A STANDARD POSITION,    ",
  248.                       "TRAJECTORY AND SPEED INDICATOR.    ",
  249.                       "                                   ",
  250.                       "MOTION AND WEAPONS CONTROL         ",
  251.                       "                                   ",
  252.                       "TO ROTATE THE SHIP RIGHT AND LEFT  ",
  253.                       "USE THE RIGHT AND LEFT ARROW KEYS. ",
  254.                       "                                   ",
  255.                       "TO INCREASE FORWARD THRUST USE THE ",
  256.                       "UP ARROW AND TO DECREASE THRUST USE",
  257.                       "                7                  ",
  258.  
  259.  
  260.                       "THE DOWN ARROW.                    ",
  261.                       "                                   ",
  262.                       "TO FIRE THE PULSE CANNON PRESS THE ",
  263.                       "SPACE BAR.                         ",
  264.                       "                                   ",
  265.                       "TO EXIT THE GAME PRESS ESCAPE.     ",
  266.                       "                                   ",
  267.                       "HAVE FUN AND REMEMBER:             ",
  268.                       "                                   ",
  269.                       "KILL OR BE KILLED!!!               ",
  270.                       "                                   ",
  271.                       "                                   ",
  272.                       "                                   ",
  273.                       "                                   ",
  274.                       "                                   ",
  275.                       "                                   ",
  276.                       "           END OF FILE             ",};
  277.  
  278.  
  279. // specification for the tallon
  280.  
  281. char *tallon_specs[] = {"MASS:      2567 KS        ",
  282.                         "LENGTH:    25.3 M         ",
  283.                         "HEAT DIS:  2.3 E.S        ",
  284.                         "WEAPONS:   POSITRON PLASMA",
  285.                         "SHIELDS:   STANDARD E-MAG ",
  286.                         "MAX SPD:   50 M.S         ",
  287.                         "ANG VEL:   72 D.S         ",
  288.                         "PROP UNIT: FUSION PULSE   "};
  289.  
  290. // specifications for the slider
  291.  
  292. char *slider_specs[] = {"MASS:      2245 KS        ",
  293.                         "LENGTH:    22.3 M         ",
  294.                         "HEAT DIS:  3.4 E.S        ",
  295.                         "WEAPONS:   POSITRON PLASMA",
  296.                         "SHIELDS:   STANDARD E-MAG ",
  297.                         "MAX SPD:   45 M.S         ",
  298.                         "ANG VEL:   80 D.S         ",
  299.                         "PROP UNIT: FUSION PULSE   "};
  300.  
  301. // F U N C T I O N S ////////////////////////////////////////////////////////
  302.  
  303. // M A I N //////////////////////////////////////////////////////////////////
  304.  
  305. void main(int argc, char **argv)
  306. {
  307.  
  308. // the main controls most of the platyer and remote logic, normally we would
  309. // probably move most of the code into functions, but for instructional purposes
  310. // this is easier to follow, believe me there are already enough function calls
  311. // to make your head spin!
  312.  
  313. int index,               // looping variable
  314.     sel,                 // used for input
  315.     players_key_state,   // state of players input
  316.     current_sel=0,       // currently highlighted interface selection
  317.     weapons_lit_count=0; // times how long the light flash from a missile
  318.                          // should be displayed when player fires
  319.  
  320. unsigned char seed;      // a random number seed
  321.  
  322. char buffer[64],         // general buffer
  323.      number[32],         // used to print strings
  324.      ch;                 // used for keyboard input
  325.  
  326.  
  327.  
  328. //INITIALIZATION SECTION///////////////////////////////////////////////////////
  329.  
  330. // set up viewing system
  331.  
  332. Set_3D_View();
  333.  
  334. // build all look up tables
  335.  
  336. Build_Look_Up_Tables();
  337.  
  338. // load in all 3d models
  339.  
  340. Load_3D_Objects();
  341.  
  342. // parse the command line and set up configuration
  343.  
  344. Parse_Commands(argc,argv);
  345.  
  346. // set the graphics mode to mode 13h
  347.  
  348. Set_Graphics_Mode(GRAPHICS_MODE13);
  349.  
  350. // start up music system
  351.  
  352. if (music_enabled)
  353.    {
  354.    Music_Init();
  355.    Music_Play((music_ptr)&song,16);
  356.    } // end if music enabled
  357.  
  358. //INTRODUCTION SECTION/////////////////////////////////////////////////////////
  359.  
  360. // put up Waite header
  361.  
  362. Intro_Waite();
  363.  
  364. // put up my header
  365.  
  366. Intro_KRK();
  367.  
  368. // seed the random number generator with time
  369.  
  370. srand((unsigned int)Timer_Query());
  371.  
  372. Tech_Print(START_MESS_X,START_MESS_Y," KILL OR BE KILLED 1.0 STARTING UP...",video_buffer);
  373. Time_Delay(5);
  374.  
  375. // initialize font engine
  376.  
  377. Font_Engine_1(0,0,0,0,NULL,NULL);
  378. Tech_Print(START_MESS_X,START_MESS_Y+16," LANGUAGE TRANSLATION ENABLED",video_buffer);
  379.  
  380. // create the double buffer
  381.  
  382. Create_Double_Buffer(129);
  383. Tech_Print(START_MESS_X,START_MESS_Y+26," DOUBLE BUFFER CREATED",video_buffer);
  384.  
  385. // install the keyboard driver
  386.  
  387. Keyboard_Install_Driver();
  388. Tech_Print(START_MESS_X,START_MESS_Y+36," NEURAL INTERFACE ACTIVATED",video_buffer);
  389.  
  390. // load and create background layer
  391.  
  392. Tech_Print(START_MESS_X,START_MESS_Y+46," BACKGROUND ENABLED",video_buffer);
  393.  
  394. PCX_Init((pcx_picture_ptr)&image_pcx);
  395. PCX_Load("krkbak.pcx",(pcx_picture_ptr)&image_pcx,1);
  396. PCX_Copy_To_Buffer((pcx_picture_ptr)&image_pcx,double_buffer);
  397. PCX_Delete((pcx_picture_ptr)&image_pcx);
  398.  
  399. Layer_Create((layer_ptr)&mountains,MOUNTAIN_WIDTH,MOUNTAIN_HEIGHT);
  400. Layer_Build((layer_ptr)&mountains,0,0,
  401.             double_buffer,
  402.             0,36,SCREEN_WIDTH,43);
  403.  
  404.  
  405. Load_Tactical();
  406. Tech_Print(START_MESS_X,START_MESS_Y+56," TACTICAL ONLINE",video_buffer);
  407.  
  408.  
  409. // memory problem
  410.  
  411. if (digital_enabled)
  412.    {
  413.    Sound_Load("KRKPOW.VOC" ,  (_sound_ptr)&digital_FX[KRKPOW_VOC ],1);
  414.    Digital_FX_Play(KRKPOW_VOC,3);
  415.    Sound_Unload((_sound_ptr)&digital_FX[KRKPOW_VOC]);
  416.    } // end if
  417.  
  418. // end memory problem
  419.  
  420. // all systems powered
  421.  
  422. Tech_Print(START_MESS_X,START_MESS_Y+108," ALL SYSTEMS POWERED AND AVAILABLE",video_buffer);
  423.  
  424. for (index=0; index<3; index++)
  425.     {
  426.     // draw the message and the erase the message
  427.     Font_Engine_1(START_MESS_X,START_MESS_Y+108,0,0," ALL SYSTEMS POWERED AND AVAILABLE",video_buffer);
  428.     Time_Delay(8);
  429.  
  430.     Font_Engine_1(START_MESS_X,START_MESS_Y+108,0,0,"                                  ",video_buffer);
  431.     Time_Delay(8);
  432.  
  433.     } // end for
  434.  
  435. // start up digital FX system
  436.  
  437. if (digital_enabled)
  438.    {
  439.    Digital_FX_Init();
  440.    } // end if digital sound enabled
  441.  
  442.  
  443. // do intro piece
  444.  
  445. Intro_Planet();
  446.  
  447. // save the system pallete here because we are going to really thrash it!!!
  448.  
  449. Read_Palette(0,255,(RGB_palette_ptr)&game_palette);
  450.  
  451.  
  452. //MAIN EVENT LOOP//////////////////////////////////////////////////////////////
  453.  
  454.  
  455. // main event loop ///////////////////////////////////////////////////////////
  456.  
  457. while(game_state!=GAME_OVER)
  458.      {
  459.      // test the overall game state
  460.  
  461.  
  462. //SETUP SECTION////////////////////////////////////////////////////////////////
  463.  
  464.      if (game_state==GAME_SETUP)
  465.         {
  466.  
  467.         // user in in the setup state
  468.  
  469.         Intro_Controls();
  470.  
  471.         Draw_Box(SELECT_BOX_SX,
  472.                  SELECT_BOX_SY+current_sel*SELECT_BOX_DY,
  473.                  SELECT_BOX_SX+SELECT_BOX_WIDTH,
  474.                  SELECT_BOX_SY+SELECT_BOX_HEIGHT+current_sel*SELECT_BOX_DY,
  475.                  254);
  476.  
  477.  
  478.         Draw_Rectangle(SELECT_LGT_SX,
  479.                       SELECT_LGT_SY+current_sel*SELECT_LGT_DY,
  480.                       SELECT_LGT_SX+SELECT_LGT_WIDTH,
  481.                       SELECT_LGT_SY+SELECT_LGT_HEIGHT+current_sel*SELECT_LGT_DY,
  482.                       254);
  483.  
  484.         // restore pallete
  485.  
  486.         Write_Palette(0,255,(RGB_palette_ptr)&game_palette);
  487.  
  488.         // enter setup event loop
  489.  
  490.         Panel_FX(1);
  491.  
  492.         while(game_state==GAME_SETUP)
  493.              {
  494.              // this event loop is for the setup phase
  495.  
  496.              // test for up or down
  497.  
  498.              if (keyboard_state[MAKE_UP])
  499.                 {
  500.  
  501.                 // erase current cursor position
  502.  
  503.                 Draw_Box(SELECT_BOX_SX,
  504.                          SELECT_BOX_SY+current_sel*SELECT_BOX_DY,
  505.                          SELECT_BOX_SX+SELECT_BOX_WIDTH,
  506.                          SELECT_BOX_SY+SELECT_BOX_HEIGHT+current_sel*SELECT_BOX_DY,
  507.                          0);
  508.  
  509.                 Draw_Rectangle(SELECT_LGT_SX,
  510.                                SELECT_LGT_SY+current_sel*SELECT_LGT_DY,
  511.                                SELECT_LGT_SX+SELECT_LGT_WIDTH,
  512.                                SELECT_LGT_SY+SELECT_LGT_HEIGHT+current_sel*SELECT_LGT_DY,
  513.                                0);
  514.  
  515.                 // move up one and draw cursor and box
  516.  
  517.                 if (--current_sel<0)
  518.                    current_sel = MAX_SELECTION;
  519.  
  520.                 // draw the new selected selection
  521.  
  522.                 Draw_Box(SELECT_BOX_SX,
  523.                          SELECT_BOX_SY+current_sel*SELECT_BOX_DY,
  524.                          SELECT_BOX_SX+SELECT_BOX_WIDTH,
  525.                          SELECT_BOX_SY+SELECT_BOX_HEIGHT+current_sel*SELECT_BOX_DY,
  526.                          254);
  527.  
  528.  
  529.                 Draw_Rectangle(SELECT_LGT_SX,
  530.                               SELECT_LGT_SY+current_sel*SELECT_LGT_DY,
  531.                               SELECT_LGT_SX+SELECT_LGT_WIDTH,
  532.                               SELECT_LGT_SY+SELECT_LGT_HEIGHT+current_sel*SELECT_LGT_DY,
  533.                               254);
  534.  
  535.  
  536.                 Digital_FX_Play(KRKKEY_VOC,3);
  537.  
  538.                 Time_Delay(1);
  539.  
  540.                 } // end if
  541.  
  542.              if (keyboard_state[MAKE_DOWN])
  543.                 {
  544.  
  545.                 // erase current cursor position
  546.  
  547.                 Draw_Box(SELECT_BOX_SX,
  548.                          SELECT_BOX_SY+current_sel*SELECT_BOX_DY,
  549.                          SELECT_BOX_SX+SELECT_BOX_WIDTH,
  550.                          SELECT_BOX_SY+SELECT_BOX_HEIGHT+current_sel*SELECT_BOX_DY,
  551.                          0);
  552.  
  553.  
  554.                 Draw_Rectangle(SELECT_LGT_SX,
  555.                               SELECT_LGT_SY+current_sel*SELECT_LGT_DY,
  556.                               SELECT_LGT_SX+SELECT_LGT_WIDTH,
  557.                               SELECT_LGT_SY+SELECT_LGT_HEIGHT+current_sel*SELECT_LGT_DY,
  558.                               0);
  559.  
  560.  
  561.                 // move up one and draw cursor and box
  562.  
  563.                 if (++current_sel>MAX_SELECTION)
  564.                    current_sel = 0;
  565.  
  566.                 // draw the new selected selection
  567.  
  568.                 Draw_Box(SELECT_BOX_SX,
  569.                          SELECT_BOX_SY+current_sel*SELECT_BOX_DY,
  570.                          SELECT_BOX_SX+SELECT_BOX_WIDTH,
  571.                          SELECT_BOX_SY+SELECT_BOX_HEIGHT+current_sel*SELECT_BOX_DY,
  572.                          SELECT_REG);
  573.  
  574.  
  575.                 Draw_Rectangle(SELECT_LGT_SX,
  576.                               SELECT_LGT_SY+current_sel*SELECT_LGT_DY,
  577.                               SELECT_LGT_SX+SELECT_LGT_WIDTH,
  578.                               SELECT_LGT_SY+SELECT_LGT_HEIGHT+current_sel*SELECT_LGT_DY,
  579.                               SELECT_REG);
  580.  
  581.                 Digital_FX_Play(KRKKEY_VOC,3);
  582.  
  583.                 Time_Delay(1);
  584.  
  585.                 } // end if
  586.  
  587.              // test for a selection via enter key
  588.  
  589.              if (keyboard_state[MAKE_ENTER])
  590.                 {
  591.  
  592.                 Digital_FX_Play(KRKKEY_VOC,3);
  593.  
  594.                 // what is the selection?
  595.  
  596.                 switch(current_sel)
  597.                       {
  598.  
  599.                       case 0:
  600.                            {
  601.  
  602.                            game_state = GAME_RUNNING;
  603.  
  604.                            } break;
  605.  
  606.                       case 1:
  607.                            {
  608.                            // call the mech selection function
  609.  
  610.                            Select_Mech();
  611.  
  612.                            // re-draw main menu
  613.  
  614.                            Intro_Controls();
  615.  
  616.                            } break;
  617.  
  618.  
  619.                       case 2:
  620.                            {
  621.                            // show user the rules and instructions
  622.  
  623.                            Intro_Briefing();
  624.  
  625.                            // re-draw main menu
  626.  
  627.                            Intro_Controls();
  628.  
  629.                            } break;
  630.  
  631.                       case 3:
  632.                            {
  633.  
  634.                            game_state = GAME_OVER;
  635.  
  636.                            } break;
  637.  
  638.                       default: break;
  639.  
  640.                       } //  end switch
  641.  
  642.                 Draw_Box(SELECT_BOX_SX,
  643.                          SELECT_BOX_SY+current_sel*SELECT_BOX_DY,
  644.                          SELECT_BOX_SX+SELECT_BOX_WIDTH,
  645.                          SELECT_BOX_SY+SELECT_BOX_HEIGHT+current_sel*SELECT_BOX_DY,
  646.                          254);
  647.  
  648.  
  649.                 Draw_Rectangle(SELECT_LGT_SX,
  650.                               SELECT_LGT_SY+current_sel*SELECT_LGT_DY,
  651.                               SELECT_LGT_SX+SELECT_LGT_WIDTH,
  652.                               SELECT_LGT_SY+SELECT_LGT_HEIGHT+current_sel*SELECT_LGT_DY,
  653.                               254);
  654.  
  655.  
  656.                 } // end if
  657.  
  658.              // slow things down a bit
  659.  
  660.              Time_Delay(1);
  661.  
  662.              // check on music
  663.  
  664.              if (music_enabled)
  665.                 {
  666.                 // test if piece is complete or has been stopped
  667.  
  668.                 if (Music_Status()==2 || Music_Status()==0)
  669.                    {
  670.                    // advance to next sequence
  671.  
  672.                    if (++intro_seq_index==14)
  673.                       intro_seq_index=0;
  674.  
  675.                    Music_Play((music_ptr)&song,intro_sequence[intro_seq_index]);
  676.  
  677.                    } // end if
  678.  
  679.                 } // end if music enabled
  680.  
  681.              // do special fx
  682.  
  683.              Panel_FX(0);
  684.  
  685.              } // end setup event loop
  686.  
  687.         } // end if in control state
  688.  
  689. //GAME RUNNING SECTION/////////////////////////////////////////////////////////
  690.  
  691.      else
  692.      if (game_state==GAME_RUNNING)
  693.         {
  694.  
  695.         // restore pallete
  696.  
  697.         Write_Palette(0,255,(RGB_palette_ptr)&game_palette);
  698.  
  699.         // reset system variables
  700.  
  701.         Reset_System();
  702.  
  703.         // restart everything
  704.  
  705.         Init_Missiles();
  706.  
  707.         Init_Aliens();
  708.  
  709.         // start music
  710.  
  711.         if (music_enabled)
  712.            {
  713.            Music_Stop();
  714.  
  715.            // start from begining sequence
  716.  
  717.            game_seq_index=0;
  718.  
  719.            Music_Play((music_ptr)&song,game_sequence[game_seq_index]);
  720.  
  721.            } // end if music enabled
  722.  
  723.         // clear double buffer
  724.  
  725.         Fill_Double_Buffer_32(0);
  726.  
  727.         // load in instrument area
  728.  
  729.         PCX_Init((pcx_picture_ptr)&image_pcx);
  730.         PCX_Load("krkcp.pcx", (pcx_picture_ptr)&image_pcx,1);
  731.         PCX_Show_Buffer((pcx_picture_ptr)&image_pcx);
  732.         PCX_Delete((pcx_picture_ptr)&image_pcx);
  733.  
  734.         // set up displays
  735.  
  736.         Draw_Scanner(SCANNER_CLEAR);
  737.         Draw_Scanner(SCANNER_LOGO);
  738.  
  739.         Draw_Tactical(TACTICAL_CLEAR);
  740.         Draw_Tactical(TACTICAL_DRAW);
  741.  
  742.         // reset color animation registers
  743.  
  744.         Misc_Color_Init();
  745.  
  746.         // enter into the main game loop
  747.  
  748.         while(game_state==GAME_RUNNING)
  749.              {
  750.              // compute starting time of this frame
  751.  
  752.              starting_time = Timer_Query();
  753.  
  754.              // keyboard input section
  755.  
  756.              // change ship velocity
  757.  
  758.              if (keyboard_state[MAKE_UP])
  759.                 {
  760.                 // speed up
  761.  
  762.                 if ((ship_speed+=5)>55)
  763.                     ship_speed=55;
  764.  
  765.                 } // end if speed increase
  766.  
  767.              if (keyboard_state[MAKE_DOWN])
  768.                 {
  769.                 // slow down
  770.  
  771.                 if ((ship_speed-=5)<-55)
  772.                     ship_speed=-55;
  773.  
  774.                 } // end if speed decrease
  775.  
  776.              // test for turns
  777.  
  778.              if (keyboard_state[MAKE_RIGHT])
  779.                 {
  780.                 // rotate ship to right
  781.  
  782.                 if ((ship_yaw+=4)>=360)
  783.                    ship_yaw-=360;
  784.  
  785.                 } // end if
  786.  
  787.              if (keyboard_state[MAKE_LEFT])
  788.                 {
  789.  
  790.                 // rotate ship to left
  791.  
  792.                 if ((ship_yaw-=4)<0)
  793.                    ship_yaw+=360;
  794.  
  795.                 } // end if
  796.  
  797.              // test for weapons fire
  798.  
  799.              if (keyboard_state[MAKE_SPACE])
  800.                 {
  801.                 // fire a missile
  802.  
  803.                 Start_Missile(PLAYER_OWNER,
  804.                               &view_point,
  805.                               &ship_direction,
  806.                               ship_speed+30,
  807.                               100);
  808.  
  809.                 // illuminate instrument panel to denote a shot has
  810.                 // been fired
  811.  
  812.                 Write_Color_Reg(PLAYERS_WEAPON_FIRE_REG,(RGB_color_ptr)&bright_red);
  813.  
  814.                 // set timer to turn off illumination
  815.  
  816.                 weapons_lit_count = 2;
  817.  
  818.                 } // end if
  819.  
  820.               // instrumentation checks
  821.  
  822.               // left hand scanner
  823.  
  824.               if (keyboard_state[MAKE_S])
  825.                  {
  826.                  if (scanner_state==1)
  827.                     {
  828.                     // turn the scanner off
  829.  
  830.                     scanner_state=0;
  831.  
  832.                     // replace krk logo
  833.  
  834.                     Draw_Scanner(SCANNER_CLEAR);
  835.  
  836.                     Draw_Scanner(SCANNER_LOGO);
  837.  
  838.                     }
  839.                  else
  840.                     {
  841.                     // turn the scanner on
  842.  
  843.                     scanner_state=1;
  844.  
  845.                     // clear the scanner area for radar inage
  846.  
  847.                     Draw_Scanner(SCANNER_CLEAR);
  848.  
  849.                     Digital_FX_Play(KRKSCN_VOC,1);
  850.  
  851.  
  852.                     } // end else
  853.  
  854.                  } // end
  855.  
  856.              // right half tactical display
  857.  
  858.              if (keyboard_state[MAKE_T])
  859.                 {
  860.  
  861.                 // test if tactical was off
  862.  
  863.                 if (tactical_state==TACTICAL_MODE_OFF)
  864.                    {
  865.                    // playe sound
  866.  
  867.                    Digital_FX_Play(KRKTAC_VOC,1);
  868.  
  869.  
  870.                    } // end if
  871.  
  872.                 // toggle to next state of tactical display
  873.  
  874.                 // clear tactical display before next state
  875.  
  876.                 Draw_Tactical(TACTICAL_CLEAR);
  877.  
  878.                 // move to next state
  879.  
  880.                 if (++tactical_state>TACTICAL_MODE_OFF)
  881.                    tactical_state = TACTICAL_MODE_STS;
  882.  
  883.                 // based on new tactical state draw proper display
  884.  
  885.                 Draw_Tactical(TACTICAL_DRAW);
  886.  
  887.                 } // end if
  888.  
  889.              // heads up display
  890.  
  891.              if (keyboard_state[MAKE_H])
  892.                 {
  893.                 // toggle hud
  894.  
  895.                 if (hud_state==1)
  896.                    {
  897.                    hud_state=0;
  898.  
  899.                    // set indicator to proper illumination
  900.  
  901.                    Write_Color_Reg(HUD_REG,(RGB_color_ptr)&dark_blue);
  902.  
  903.                    } // end if
  904.                 else
  905.                    {
  906.                    hud_state = 1;
  907.  
  908.                    // set indicator to proper illumination
  909.  
  910.                    Write_Color_Reg(HUD_REG,(RGB_color_ptr)&bright_blue);
  911.  
  912.                    Digital_FX_Play(KRKHUD_VOC,1);
  913.  
  914.                    } // end else
  915.  
  916.                 } // end if
  917.  
  918.              // test for exit
  919.  
  920.              if (keyboard_state[MAKE_ESC])
  921.                 game_state=GAME_SETUP;
  922.  
  923.  
  924.              // motion and control section
  925.  
  926.              // create a trajectory vector aligned with view direction
  927.  
  928.              ship_direction.x = sin_look[ship_yaw];
  929.              ship_direction.y = 0;
  930.              ship_direction.z = cos_look[ship_yaw];
  931.  
  932.              // move viewpoint based on ship trajectory
  933.  
  934.              view_point.x+=ship_direction.x*ship_speed;
  935.              view_point.z+=ship_direction.z*ship_speed;
  936.  
  937.              // move objects here
  938.  
  939.              Move_Missiles();
  940.  
  941.              // move and perform AI for aliens
  942.  
  943.              Process_Aliens();
  944.  
  945.              // test ship against universe boundaries
  946.  
  947.              if (view_point.x>GAME_MAX_WORLD_X)
  948.                  view_point.x=GAME_MAX_WORLD_X;
  949.              else
  950.              if (view_point.x<GAME_MIN_WORLD_X)
  951.                  view_point.x=GAME_MIN_WORLD_X;
  952.  
  953.              if (view_point.z>GAME_MAX_WORLD_Z)
  954.                  view_point.z=GAME_MAX_WORLD_Z;
  955.              else
  956.              if (view_point.z<GAME_MIN_WORLD_Z)
  957.                  view_point.z=GAME_MIN_WORLD_Z;
  958.  
  959.              // add in vibrational noise due to terrain
  960.  
  961.              if (ship_speed)
  962.                  view_point.y = 40+rand()%(1+abs(ship_speed)/8);
  963.              else
  964.                  view_point.y = 40;
  965.  
  966.              // test for ship hit message
  967.  
  968.              if (ship_message == SHIP_HIT)
  969.                 {
  970.                 // do screen shake
  971.  
  972.                 view_point.y = 40+5*(rand()%10);
  973.  
  974.                 // perform color fx
  975.  
  976.                 // test if shake complete
  977.  
  978.                 if (--ship_timer < 0)
  979.                    {
  980.                    // reset ships state
  981.  
  982.                    ship_message = SHIP_STABLE;
  983.  
  984.                    view_point.y = 40;
  985.  
  986.                    // reset colors
  987.  
  988.                    } // end if screen shake complete
  989.  
  990.                 } // end if
  991.  
  992.  
  993.              // transform stationary objects here
  994.  
  995.              Rotate_Object(&static_obj[STATIONS_TEMPLATE],0,10,0);
  996.  
  997.              Rotate_Object(&static_obj[TELEPODS_TEMPLATE],0,15,0);
  998.  
  999.              // set view angles based on trajectory of ship
  1000.  
  1001.              view_angle.ang_y = ship_yaw;
  1002.  
  1003.              // now that user has possible moved viewpoint, create the global
  1004.              // world to camera transformation matrix
  1005.  
  1006.              Create_World_To_Camera();
  1007.  
  1008.              // reset the polygon list
  1009.  
  1010.              Generate_Poly_List(NULL,RESET_POLY_LIST);
  1011.  
  1012.              // perform general 3-D pipeline for all 3-D objects
  1013.  
  1014.              // first draw stationary objects
  1015.  
  1016.              Draw_Stationary_Objects();
  1017.  
  1018.              // draw dynamic objects
  1019.  
  1020.              Draw_Aliens();
  1021.  
  1022.              // draw the missiles
  1023.  
  1024.              Draw_Missiles();
  1025.  
  1026.              // draw background
  1027.  
  1028.              Draw_Background((int)(ship_yaw*.885));
  1029.  
  1030.              // sort the polygons
  1031.  
  1032.              Sort_Poly_List();
  1033.  
  1034.              // draw the polygon list
  1035.  
  1036.              Draw_Poly_List();
  1037.  
  1038.              // draw the instruments here
  1039.  
  1040.              if (scanner_state==1)
  1041.                 {
  1042.                 // erase old blips
  1043.  
  1044.                 Draw_Scanner(SCANNER_ERASE_BLIPS);
  1045.  
  1046.                 // refresh scanner image
  1047.  
  1048.                 Draw_Scanner(SCANNER_DRAW_BLIPS);
  1049.  
  1050.                 } // end if
  1051.  
  1052.              // update tactical display
  1053.  
  1054.              if (tactical_state!=TACTICAL_MODE_OFF)
  1055.                  Draw_Tactical(TACTICAL_UPDATE);
  1056.  
  1057.              if (hud_state==1)
  1058.                 Draw_Hud();
  1059.  
  1060.              // do special color fx
  1061.  
  1062.              // flicker the engines of the aliens
  1063.  
  1064.              Tallon_Color_FX();
  1065.  
  1066.              Slider_Color_FX();
  1067.  
  1068.              // strobe the perimeter barriers
  1069.  
  1070.              Barrier_Color_FX();
  1071.  
  1072.              // take care of weapons flash
  1073.  
  1074.              if (weapons_lit_count>0)
  1075.                 {
  1076.                 // test if it's time to to off flash
  1077.  
  1078.                 if (--weapons_lit_count==0)
  1079.                    Write_Color_Reg(PLAYERS_WEAPON_FIRE_REG,(RGB_color_ptr)&black);
  1080.  
  1081.                 } // end if
  1082.  
  1083.              // test if screen should be colored to simulate fire blast
  1084.  
  1085.              if (ship_message==SHIP_HIT)
  1086.                 {
  1087.                 // test for time intervals
  1088.  
  1089.                 if (ship_timer>5 && (rand()%3)==1)
  1090.                    Fill_Double_Buffer_32(SHIP_FLAME_COLOR+rand()%16);
  1091.  
  1092.                 } // end if ship hit
  1093.  
  1094.              // display double buffer
  1095.  
  1096.              Display_Double_Buffer_32(double_buffer,0);
  1097.  
  1098.              // lock onto 18 frames per second max
  1099.  
  1100.              while((Timer_Query()-starting_time)<1);
  1101.  
  1102.              // check on music
  1103.  
  1104.              if (music_enabled)
  1105.                 {
  1106.                 if (Music_Status()==2 || Music_Status()==0)
  1107.                    {
  1108.  
  1109.                    // advance to next sequence
  1110.  
  1111.                    if (++game_seq_index==21)
  1112.                       game_seq_index=0;
  1113.  
  1114.                    Music_Play((music_ptr)&song,game_sequence[game_seq_index]);
  1115.  
  1116.                     } // end if
  1117.  
  1118.                  } // end if music enabled
  1119.  
  1120.              } // end game loop
  1121.  
  1122.         // test if there is a winner or user just decided to exit
  1123.  
  1124.         Screen_Transition(SCREEN_DARKNESS);
  1125.  
  1126.         // restart intro music
  1127.  
  1128.         if (music_enabled)
  1129.            {
  1130.            // stop game music, start intro music again
  1131.  
  1132.            intro_seq_index=0;
  1133.            Music_Stop();
  1134.            Music_Play((music_ptr)&song,intro_sequence[intro_seq_index]);
  1135.  
  1136.            } // end if music enabled
  1137.  
  1138.         } // end if running
  1139.  
  1140.      } // end main system event loop
  1141.  
  1142. //GAME OVER SECTION////////////////////////////////////////////////////////////
  1143.  
  1144. // exit in a very cool way
  1145.  
  1146. Screen_Transition(SCREEN_SWIPE_X);
  1147.  
  1148. // free up all resources
  1149.  
  1150. Delete_Double_Buffer();
  1151.  
  1152. // close down FX
  1153.  
  1154. Digital_FX_Close();
  1155.  
  1156. // show the credits
  1157.  
  1158. Closing_Screen();
  1159.  
  1160. // close down music
  1161.  
  1162. Music_Close();
  1163.  
  1164. // remove the keyboard handler
  1165.  
  1166. Keyboard_Remove_Driver();
  1167.  
  1168. Set_Graphics_Mode(TEXT_MODE);
  1169.  
  1170. // see ya!
  1171.  
  1172. printf("\nKILL OR BE KILLED:Normal Shutdown.\n");
  1173.  
  1174. } // end main
  1175.  
  1176.