home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / sources / chapter18 / TestDat / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2006-09-16  |  1.2 KB  |  53 lines

  1. //////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Chapter 18 - TestDat
  4. //////////////////////////////////////////////////////
  5.  
  6. #include <allegro.h>
  7.  
  8. #define MODE GFX_AUTODETECT_WINDOWED
  9. #define WIDTH 640
  10. #define HEIGHT 480
  11. #define WHITE makecol(255,255,255)
  12.  
  13. //define objects in datfile
  14. #define BACK_BMP 0
  15. #define SHIP_BMP 1
  16.  
  17.  
  18. int main(void)
  19. {
  20.     DATAFILE *data;
  21.     BITMAP *sprite;
  22.  
  23.     //initialize the program
  24.     allegro_init();
  25.     install_keyboard(); 
  26.     install_timer();
  27.     set_color_depth(16);
  28.     set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
  29.  
  30.     //load the datfile
  31.     data = load_datafile("test.dat");
  32.  
  33.     //blit the background image using datfile directly
  34.     blit(data[BACK_BMP].dat, screen, 0, 0, 0, 0, WIDTH-1, HEIGHT-1);
  35.  
  36.     //grab sprite and store in separate BITMAP
  37.     sprite = (BITMAP *)data[SHIP_BMP].dat;
  38.     draw_sprite(screen, sprite, WIDTH/2-sprite->w/2,HEIGHT/2-sprite->h/2);
  39.  
  40.     //display title
  41.     textout_ex(screen,font,"TestDat Program (ESC to quit)",0,0,WHITE,-1);
  42.  
  43.     //pause
  44.     while(!keypressed());
  45.  
  46.     //remove datfile from memory
  47.     unload_datafile(data);
  48.  
  49.     allegro_exit();
  50.     return 0;
  51. }
  52. END_OF_MAIN()
  53.