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

  1. /////////////////////////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Chapter 3 - Lines 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 random 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 1;
  28.     }
  29.  
  30.     //display screen resolution
  31.     textprintf_ex(screen, font, 0, 0, 15, -1,
  32.         "Lines 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.         x1 = 10 + rand() % (SCREEN_W-20);
  40.         y1 = 10 + rand() % (SCREEN_H-20);
  41.         x2 = 10 + rand() % (SCREEN_W-20);
  42.         y2 = 10 + rand() % (SCREEN_H-20);
  43.         
  44.         //set a random color
  45.         red = rand() % 255;
  46.         green = rand() % 255;
  47.         blue = rand() % 255;
  48.         color = makecol(red,green,blue);
  49.         
  50.         //draw the pixel
  51.         line(screen, x1,y1,x2,y2,color);
  52.     }
  53.  
  54.     //end program
  55.     allegro_exit();
  56.     return 0;
  57. }
  58. END_OF_MAIN()
  59.  
  60.