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

  1. ////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Chapter 5, MouseWheel Program
  4. ////////////////////////////////////////////////////
  5.  
  6. #include <allegro.h>
  7.  
  8. #define WHITE makecol(255,255,255)
  9. #define BLACK makecol(0,0,0)
  10. #define AQUA makecol(0,200,255)
  11.  
  12. int main(void)
  13. {
  14.     int n, color, value;
  15.     BITMAP *lever;
  16.  
  17.     //initialize program    
  18.     allegro_init();
  19.     set_color_depth(16);
  20.     set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
  21.     install_keyboard();
  22.     install_mouse();
  23.     textout_ex(screen,font,"MouseWheel Program (ESC to quit)",0,0,WHITE,0);
  24.     textout_ex(screen,font,"USE MOUSE WHEEL TO MOVE THE LEVER",0,10,WHITE,0);
  25.     
  26.     //load the control lever image
  27.     lever = load_bitmap("lever.bmp", NULL);
  28.     
  29.     //draw the throttle control
  30.     for (n=0; n<200; n++)
  31.     {
  32.         color = makecol(255-n,10,10);
  33.         rectfill(screen, 200, 40 + n * 2, 400, 42 + n * 2, color);
  34.     }
  35.     
  36.     value=200;
  37.     position_mouse_z(value);
  38.  
  39.     while (!key[KEY_ESC])
  40.     {
  41.         //erase the lever
  42.         rectfill(screen, 450, 29 + value, 550, value + 65, BLACK);
  43.  
  44.         //update lever position
  45.         value = mouse_z;
  46.         if (value < 0) 
  47.             value = 0;
  48.         if (value > 390)
  49.             value = 390;
  50.  
  51.         //draw the lever
  52.         blit(lever, screen, 0, 0, 450, 30 + value, lever->w, lever->h);
  53.         
  54.         //display value
  55.         textprintf_ex(screen, font, 520, 30 + value + lever->h / 2,0,
  56.             AQUA,"%d", value);
  57.         
  58.         rest(30);
  59.     }
  60.  
  61.     allegro_exit();
  62.     return 0;
  63. }
  64. END_OF_MAIN()
  65.  
  66.