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

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