home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / sources / chapter03 / CircleFill / main.c < prev    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 - CircleFill Program
  4. /////////////////////////////////////////////////////////////////////////
  5.  
  6. #include <allegro.h>
  7.  
  8. int main(void)
  9. {
  10.     int x,y,radius;
  11.     int red,green,blue,color;
  12.     int ret;
  13.     
  14.     //initialize some stuff
  15.     allegro_init(); 
  16.     install_keyboard(); 
  17.     install_timer();
  18.     srand(time(NULL));
  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.         "CircleFill 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.         x = 30 + rand() % (SCREEN_W-60);
  37.         y = 30 + rand() % (SCREEN_H-60);
  38.         radius = rand() % 30;
  39.         
  40.         //set a random color
  41.         red = rand() % 255;
  42.         green = rand() % 255;
  43.         blue = rand() % 255;
  44.         color = makecol(red,green,blue);
  45.         
  46.         //draw the pixel
  47.         circlefill(screen, x, y, radius, color);
  48.         
  49.         rest(25); //replaced sleep()
  50.     }
  51.  
  52.     //end program
  53.     allegro_exit();
  54.     return 0;
  55. }
  56. END_OF_MAIN()
  57.