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

  1. /////////////////////////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Chapter 3 - Splines Program
  4. /////////////////////////////////////////////////////////////////////////
  5.  
  6. #include <allegro.h>
  7.  
  8. int main(void)
  9. {
  10.     int points[8] = {0,240,300,0,200,0,639,240};
  11.     int ret;
  12.     int y1, y2;
  13.     int dir1, dir2;
  14.     
  15.     //initialize Allegro
  16.     allegro_init(); 
  17.     install_keyboard(); 
  18.     install_timer();
  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.         "Splines Program - %dx%d - Press ESC to quit", 
  30.         SCREEN_W, SCREEN_H);
  31.  
  32.     y1 = 0;
  33.     y2 = SCREEN_H;
  34.     dir1 = 10;
  35.     dir2 = -10;
  36.  
  37.     //wait for keypress
  38.     while(!key[KEY_ESC])
  39.     {
  40.         //modify the first spline point
  41.         y1 += dir1;
  42.         if (y1 > SCREEN_H)
  43.         {
  44.             dir1 = -10;
  45.         }
  46.         if (y1 < 0)
  47.             dir1 = 10;
  48.         points[3] = y1;
  49.         
  50.         //modify the second spline point
  51.         y2 += dir2;
  52.         if (y2++ > SCREEN_H)
  53.         {
  54.             dir2 = -10;
  55.         }
  56.         if (y2 < 0)
  57.             dir2 = 10;
  58.         points[5] = y2;
  59.        
  60.         //draw the spline, pause, then erase it
  61.         spline(screen, points, 15);
  62.         rest(30); // replaced sleep()
  63.         spline(screen, points, 0);
  64.         
  65.     }
  66.  
  67.     //end program
  68.     allegro_exit();
  69.     return 0;
  70. }
  71. END_OF_MAIN()
  72.