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

  1. /////////////////////////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Chapter 3 - Triangles Program
  4. /////////////////////////////////////////////////////////////////////////
  5.  
  6. #include <allegro.h>
  7.  
  8. int main(void)
  9. {
  10.     int x1,y1,x2,y2,x3,y3;
  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.     install_timer();
  20.  
  21.     //initialize video mode to 640x480
  22.     ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
  23.     if (ret != 0) {
  24.         allegro_message(allegro_error);
  25.         return 1;
  26.     }
  27.  
  28.     //display screen resolution
  29.     textprintf_ex(screen, font, 0, 0, 15, -1,
  30.         "Triangles Program - %dx%d - Press ESC to quit", 
  31.         SCREEN_W, SCREEN_H);
  32.  
  33.     //wait for keypress
  34.     while(!key[KEY_ESC])
  35.     {
  36.         //set a random location
  37.         x1 = 10 + rand() % (SCREEN_W-20);
  38.         y1 = 10 + rand() % (SCREEN_H-20);
  39.         x2 = 10 + rand() % (SCREEN_W-20);
  40.         y2 = 10 + rand() % (SCREEN_H-20);
  41.         x3 = 10 + rand() % (SCREEN_W-20);
  42.         y3 = 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.         triangle(screen,x1,y1,x2,y2,x3,y3,color);
  52.         
  53.         rest(100);
  54.     }
  55.  
  56.     //end program
  57.     allegro_exit();
  58.     return 0;
  59. }
  60. END_OF_MAIN()
  61.  
  62.