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

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