home *** CD-ROM | disk | FTP | other *** search
/ Teach Yourself Game Programming in 21 Days / TYGAMES_R.ISO / source / day_06 / paper.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-23  |  2.7 KB  |  125 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 library
  17. #include "graph4.h" // include our graphics library
  18.  
  19. // D E F I N E S /////////////////////////////////////////////////////////////
  20.  
  21. #define PLANE_START_COLOR_REG 17
  22. #define PLANE_END_COLOR_REG   30
  23.  
  24. // G L O B A L S /////////////////////////////////////////////////////////////
  25.                                                           // 18.2 clicks/sec
  26.  
  27. pcx_picture plane;
  28.  
  29. //////////////////////////////////////////////////////////////////////////////
  30.  
  31. void Animate_Plane(void)
  32. {
  33. // this function animates a paper plane drawn with 14 different colors by
  34. // illuminating a single color and turning off all the others in a sequence
  35.  
  36. RGB_color color_1, color_2;
  37. int index;
  38.  
  39. // clear out each of the color registers used by plane
  40.  
  41. color_1.red   = 0;
  42. color_1.green = 0;
  43. color_1.blue  = 0;
  44.  
  45. color_2.red   = 0;
  46. color_2.green = 63;
  47. color_2.blue  = 0;
  48.  
  49. // clear all the colors out
  50.  
  51. for (index=PLANE_START_COLOR_REG; index<=PLANE_END_COLOR_REG; index++)
  52.     {
  53.  
  54.     Set_Palette_Register(index, (RGB_color_ptr)&color_1);
  55.  
  56.     } // end for index
  57.  
  58. // make first plane green and then rotate colors
  59.  
  60. Set_Palette_Register(PLANE_START_COLOR_REG, (RGB_color_ptr)&color_2);
  61.  
  62. // animate the colors
  63.  
  64. while(!kbhit())
  65.      {
  66.      // rotate colors
  67.  
  68.      Get_Palette_Register(PLANE_END_COLOR_REG,(RGB_color_ptr)&color_1);
  69.  
  70.      for (index=PLANE_END_COLOR_REG-1; index>=PLANE_START_COLOR_REG; index--)
  71.          {
  72.  
  73.          Get_Palette_Register(index,(RGB_color_ptr)&color_2);
  74.          Set_Palette_Register(index+1,(RGB_color_ptr)&color_2);
  75.  
  76.          } // end for
  77.  
  78.          Set_Palette_Register(PLANE_START_COLOR_REG,(RGB_color_ptr)&color_1);
  79.  
  80.      // wait a while
  81.  
  82.      Delay(3);
  83.  
  84.      } // end while
  85.  
  86. } // end Animate_Plane
  87.  
  88. // M A I N ///////////////////////////////////////////////////////////////////
  89.  
  90. void main(void)
  91. {
  92.  
  93. // set video mode to 320x200 256 color mode
  94.  
  95. Set_Video_Mode(VGA256);
  96.  
  97. // initialize the pcx file that holds the plane
  98.  
  99. PCX_Init((pcx_picture_ptr)&plane);
  100.  
  101. // load the pcx file that holds the cells
  102.  
  103. PCX_Load("paper.pcx", (pcx_picture_ptr)&plane,1);
  104.  
  105. PCX_Show_Buffer((pcx_picture_ptr)&plane);
  106.  
  107. PCX_Delete((pcx_picture_ptr)&plane);
  108.  
  109. Blit_String(8,8,15,"Hit any key to see animation.",0);
  110.  
  111. getch();
  112.  
  113. Blit_String(8,8,15,"Hit any key to exit.         ",0);
  114.  
  115. Animate_Plane();
  116.  
  117. // go back to text mode
  118.  
  119. Set_Video_Mode(TEXT_MODE);
  120.  
  121. } // end main
  122.  
  123.  
  124.  
  125.