home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / sources / chapter03 / Rect / main.c next >
Encoding:
C/C++ Source or Header  |  2006-09-10  |  1.4 KB  |  56 lines

  1. /////////////////////////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Chapter 3 - Rect Program
  4. /////////////////////////////////////////////////////////////////////////
  5.  
  6. #include <allegro.h>
  7.  
  8. int main(void)
  9. {
  10.     int x1,y1,x2,y2;
  11.     int red,green,blue,color;
  12.     int ret;
  13.     
  14.     //initialize Allegro
  15.     allegro_init(); 
  16.     
  17.     //initialize the keyboard
  18.     install_keyboard(); 
  19.  
  20.     //initialize video mode to 640x480
  21.     ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
  22.     if (ret != 0) {
  23.         allegro_message(allegro_error);
  24.         return 1;
  25.     }
  26.  
  27.     //display screen resolution
  28.     textprintf_ex(screen, font, 0, 0, 15, -1,
  29.         "Rect Program - %dx%d - Press ESC to quit", 
  30.         SCREEN_W, SCREEN_H);
  31.  
  32.     //wait for keypress
  33.     while(!key[KEY_ESC])
  34.     {
  35.         //set a random location
  36.         x1 = 10 + rand() % (SCREEN_W-20);
  37.         y1 = 10 + rand() % (SCREEN_H-20);
  38.         x2 = 10 + rand() % (SCREEN_W-20);
  39.         y2 = 10 + rand() % (SCREEN_H-20);
  40.         
  41.         //set a random color
  42.         red = rand() % 255;
  43.         green = rand() % 255;
  44.         blue = rand() % 255;
  45.         color = makecol(red,green,blue);
  46.         
  47.         //draw the pixel
  48.         rect(screen,x1,y1,x2,y2,color);
  49.     }
  50.  
  51.     //end program
  52.     allegro_exit();
  53.     return 0;
  54. }
  55. END_OF_MAIN()
  56.