home *** CD-ROM | disk | FTP | other *** search
/ Teach Yourself Game Programming in 21 Days / TYGAMES_R.ISO / source / day_12 / linew.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-14  |  2.4 KB  |  112 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 "graph5.h"  // need polygon stuff
  19. #include "graph6.h"
  20.  
  21. // D E F I N E S //////////////////////////////////////////////////////////////
  22.  
  23. #define MAX_LINES 128
  24.  
  25. // S T R U C T U R E S ////////////////////////////////////////////////////////
  26.  
  27. typedef struct line_typ
  28.         {
  29.  
  30.         int color;      // color of the line
  31.         int x1;         // first endpoint of the line
  32.         int y1;
  33.         int x2;         // second endpoint of the line
  34.         int y2;
  35.  
  36.         } line, *line_ptr;
  37.  
  38. // G L O B A L S /////////////////////////////////////////////////////////////
  39.  
  40. // the data structure that holds all the lines
  41.  
  42. line line_data[MAX_LINES];
  43.  
  44. // M A I N ////////////////////////////////////////////////////////////////////
  45.  
  46. void main(void)
  47. {
  48.  
  49. FILE *fp;
  50.  
  51. int color,x1,y1,x2,y2,num_lines,lines;  // working variables
  52.  
  53. // this is the main function
  54.  
  55. // SECTION 1 /////////////////////////////////////////////////////////////////
  56.  
  57. // set video mode to 320x200 256 color mode
  58.  
  59. Set_Video_Mode(VGA256);
  60.  
  61. // SECTION 2 /////////////////////////////////////////////////////////////////
  62.  
  63. // open the data file
  64.  
  65. fp = fopen("linew.dat","r");
  66.  
  67. // extract number of lines
  68.  
  69. fscanf(fp,"%d",&num_lines);
  70.  
  71. // load each line and draw
  72.  
  73. for (lines=0; lines<num_lines;lines++)
  74.     {
  75.  
  76.     // load a line structure
  77.  
  78.     fscanf(fp,"%d %d %d %d %d",&color,&x1,&y1,&x2,&y2);
  79.  
  80.     // save line in data structure
  81.  
  82.     line_data[lines].color = color;
  83.     line_data[lines].x1    = x1;
  84.     line_data[lines].y1    = y1;
  85.     line_data[lines].x2    = x2;
  86.     line_data[lines].y2    = y2;
  87.  
  88.     // render the line
  89.  
  90.     Bline(x1,y1,x2,y2,color);
  91.  
  92.     } // end for lines
  93.  
  94. // SECTION 3 /////////////////////////////////////////////////////////////////
  95.  
  96. Blit_String(2,2,10,"Press any key to exit.",1);
  97.  
  98. // main event loop
  99.  
  100. while(!kbhit())
  101.      {
  102.      // do nothing !
  103.      } // end while
  104.  
  105. // reset the video mode back to text
  106.  
  107. Set_Video_Mode(TEXT_MODE);
  108.  
  109. } // end main
  110.  
  111.  
  112.