home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / borland / chap_4 / speed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  4.1 KB  |  171 lines

  1.  
  2. // SPEED.C - A demo of 3-D palette animation
  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 "black3.h"
  19. #include "black4.h"
  20.  
  21. // D E F I N E S //////////////////////////////////////////////////////////////
  22.  
  23. // the color register ranges used by the road and side markers
  24.  
  25. #define START_ROAD_REG    16
  26. #define END_ROAD_REG      23
  27.  
  28. #define START_MARKER_REG  32
  29. #define END_MARKER_REG    34
  30.  
  31. // G L O B A L S  ////////////////////////////////////////////////////////////
  32.  
  33. pcx_picture image_pcx;  // general PCX image used to load background and imagery
  34.  
  35.  
  36. // M A I N ///////////////////////////////////////////////////////////////////
  37.  
  38. void main(int argc, char **argv)
  39. {
  40.  
  41. RGB_color color_1, color_2;  // used to perform the color rotation
  42.  
  43. int index;                   // looping variable
  44.  
  45. // set the graphics mode to mode 13h
  46.  
  47. Set_Graphics_Mode(GRAPHICS_MODE13);
  48.  
  49. // load the screen image
  50.  
  51. PCX_Init((pcx_picture_ptr)&image_pcx);
  52.  
  53. // load a PCX file (make sure it's there)
  54.  
  55. if (PCX_Load("speed.pcx", (pcx_picture_ptr)&image_pcx,1))
  56.    {
  57.    // copy the image to the display buffer
  58.  
  59.    PCX_Show_Buffer((pcx_picture_ptr)&image_pcx);
  60.  
  61.    // delete the PCX buffer
  62.  
  63.    PCX_Delete((pcx_picture_ptr)&image_pcx);
  64.  
  65.    // remap color registers to more appropriate values
  66.  
  67.    // remap the side marker colors to red, red, white
  68.  
  69.    color_1.red    = 63;
  70.    color_1.green  = 0;
  71.    color_1.blue   = 0;
  72.  
  73.    Write_Color_Reg(START_MARKER_REG,  (RGB_color_ptr)&color_1);
  74.    Write_Color_Reg(START_MARKER_REG+1,(RGB_color_ptr)&color_1);
  75.  
  76.    color_1.green  = 63;
  77.    color_1.blue   = 63;
  78.  
  79.    Write_Color_Reg(START_MARKER_REG+2,(RGB_color_ptr)&color_1);
  80.  
  81.    // now color the road all grey except for three slices
  82.  
  83.    color_1.red    = 20;
  84.    color_1.green  = 20;
  85.    color_1.blue   = 20;
  86.  
  87.    for (index=START_ROAD_REG; index<=END_ROAD_REG; index++)
  88.        Write_Color_Reg(index,(RGB_color_ptr)&color_1);
  89.  
  90.    // now color three of the slices a slightly brighter grey
  91.  
  92.    color_1.red    = 30;
  93.    color_1.green  = 30;
  94.    color_1.blue   = 30;
  95.  
  96.    for (index=START_ROAD_REG; index<=END_ROAD_REG; index+=4)
  97.        Write_Color_Reg(index,(RGB_color_ptr)&color_1);
  98.  
  99.    // wait for a keyboard press
  100.  
  101.    while(!kbhit())
  102.         {
  103.  
  104.         // rotate road colors
  105.  
  106.         // temp = r1
  107.         // r1 <--- r2 <---- r3 <---- ... ri-1 <---- ri
  108.         // ri = temp
  109.  
  110.  
  111.         Read_Color_Reg(END_ROAD_REG, (RGB_color_ptr)&color_1);
  112.  
  113.         for (index=END_ROAD_REG; index>START_ROAD_REG; index--)
  114.             {
  115.  
  116.             // read the (i-1)th register
  117.  
  118.             Read_Color_Reg(index-1, (RGB_color_ptr)&color_2);
  119.  
  120.             // assign it to the ith
  121.  
  122.             Write_Color_Reg(index, (RGB_color_ptr)&color_2);
  123.  
  124.             } // end rotate loop
  125.  
  126.          // place the value of the first color register into the last to
  127.          // complete the rotation
  128.  
  129.          Write_Color_Reg(START_ROAD_REG, (RGB_color_ptr)&color_1);
  130.  
  131.         // rotate side marker colors
  132.  
  133.         Read_Color_Reg(END_MARKER_REG, (RGB_color_ptr)&color_1);
  134.  
  135.         for (index=END_MARKER_REG; index>START_MARKER_REG; index--)
  136.             {
  137.  
  138.             // read the (i-1)th register
  139.  
  140.             Read_Color_Reg(index-1, (RGB_color_ptr)&color_2);
  141.  
  142.             // assign it to the ith
  143.  
  144.             Write_Color_Reg(index, (RGB_color_ptr)&color_2);
  145.  
  146.             } // end rotate loop
  147.  
  148.          // place the value of the first color register into the last to
  149.          // complete the rotation
  150.  
  151.          Write_Color_Reg(START_MARKER_REG, (RGB_color_ptr)&color_1);
  152.  
  153.         // synchronize to 2/18th of second or 9 FPS
  154.  
  155.         Time_Delay(1);
  156.  
  157.         } // end main loop
  158.  
  159.    // use a screen transition to exit
  160.  
  161.    Screen_Transition(SCREEN_WHITENESS);
  162.  
  163.    } // end if pcx file found
  164.  
  165. // reset graphics to text mode
  166.  
  167. Set_Graphics_Mode(TEXT_MODE);
  168.  
  169. } // end main
  170.  
  171.