home *** CD-ROM | disk | FTP | other *** search
/ Teach Yourself Game Programming in 21 Days / TYGAMES_R.ISO / source / day_12 / cellw.c next >
Text File  |  1994-07-14  |  4KB  |  166 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.  
  20. // D E F I N E S /////////////////////////////////////////////////////////////
  21.  
  22. #define CELL_WIDTH       16   // size of bitmaps in world
  23. #define CELL_HEIGHT      16
  24.  
  25. #define NUM_ROWS         12   // number of rows and columns in terrain
  26. #define NUM_COLUMNS      20
  27.  
  28. // G L O B A L S  ////////////////////////////////////////////////////////////
  29.  
  30. pcx_picture imagery_pcx;      // the background bitmaps
  31.  
  32. // the sprites used in the demo
  33.  
  34. sprite objects;
  35.  
  36. int terrain[NUM_ROWS][NUM_COLUMNS] = {0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,3,3,3,3,0,
  37.                                       0,0,0,0,2,0,0,0,0,3,0,0,0,0,0,3,0,0,3,0,
  38.                                       0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,0,0,3,0,
  39.                                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,3,0,
  40.                                       0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,3,3,3,3,0,
  41.                                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  42.                                       0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,
  43.                                       0,0,0,0,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,
  44.                                       0,0,0,2,2,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,
  45.                                       0,0,2,2,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,3,
  46.                                       0,0,2,2,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,
  47.                                       0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  48.  
  49.  
  50. // M A I N ////////////////////////////////////////////////////////////////////
  51.  
  52. void main(void)
  53. {
  54. // this is the main function
  55.  
  56. int x,y;
  57.  
  58.  
  59. // SECTION 1 /////////////////////////////////////////////////////////////////
  60.  
  61. // set video mode to 320x200 256 color mode
  62.  
  63. Set_Video_Mode(VGA256);
  64.  
  65. // create a double buffer
  66.  
  67. if (!Create_Double_Buffer(SCREEN_HEIGHT))
  68.    {
  69.    printf("\nNot enough memory to create double buffer.");
  70.  
  71.    } // end if
  72.  
  73. // clear the double buffer
  74.  
  75. Fill_Double_Buffer(0);
  76.  
  77. // SECTION 2 /////////////////////////////////////////////////////////////////
  78.  
  79. // load in imagery for the background objects
  80.  
  81. PCX_Init((pcx_picture_ptr)&imagery_pcx);
  82.  
  83. PCX_Load("terrain.pcx", (pcx_picture_ptr)&imagery_pcx,1);
  84.  
  85. // initialize player and extract bitmaps
  86.  
  87. sprite_width  = 16;
  88. sprite_height = 16;
  89.  
  90. // initialize the object sprite
  91.  
  92. Sprite_Init((sprite_ptr)&objects,0,0,0,0,0,0);
  93.  
  94. // load the bitmaps
  95.  
  96. PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  97.                 (sprite_ptr)&objects,0,0,0);
  98.  
  99. PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  100.                 (sprite_ptr)&objects,1,1,0);
  101.  
  102. PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  103.                 (sprite_ptr)&objects,2,2,0);
  104.  
  105. PCX_Grab_Bitmap((pcx_picture_ptr)&imagery_pcx,
  106.                 (sprite_ptr)&objects,3,3,0);
  107.  
  108.  
  109. objects.curr_frame = 0;
  110. objects.state      = 1;
  111.  
  112. // SECTION 3 /////////////////////////////////////////////////////////////////
  113.  
  114. // based on terrain array draw world
  115.  
  116. // loop through data array
  117.  
  118. for (y=0; y<NUM_ROWS; y++)
  119.     {
  120.  
  121.     for (x=0; x<NUM_COLUMNS; x++)
  122.         {
  123.  
  124.         // draw the proper bitmap at the proper position
  125.  
  126.         objects.x = x*CELL_WIDTH;
  127.         objects.y = y*CELL_HEIGHT;
  128.  
  129.         // extract the cell element
  130.  
  131.         objects.curr_frame  = terrain[y][x];
  132.  
  133.         Draw_Sprite_DB((sprite_ptr)&objects);
  134.  
  135.         } // end for x
  136.  
  137.     } // end for y
  138.  
  139.  
  140. // SECTION 4 /////////////////////////////////////////////////////////////////
  141.  
  142. Blit_String_DB(2,2,10,"Press any key to exit.",1);
  143.  
  144. // let's see what we drew
  145.  
  146. Show_Double_Buffer(double_buffer);
  147.  
  148. // main event loop
  149.  
  150. while(!kbhit())
  151.      {
  152.  
  153.      } // end while
  154.  
  155. // reset the video mode back to text
  156.  
  157. Set_Video_Mode(TEXT_MODE);
  158.  
  159. // free the double buffer
  160.  
  161. Delete_Double_Buffer();
  162.  
  163. } // end main
  164.  
  165.  
  166.