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

  1. ////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Chapter 5, PositionMouse Program
  4. ////////////////////////////////////////////////////
  5.  
  6. #include <allegro.h>
  7.  
  8. #define WHITE makecol(255,255,255)
  9.  
  10. int mouseinside(int x1,int y1,int x2,int y2)
  11. {
  12.     if (mouse_x > x1 && mouse_x < x2 && mouse_y > y1 && mouse_y < y2)
  13.         return 1;
  14.     else
  15.         return 0;
  16. }
  17.  
  18. int main(void)
  19. {
  20.     int n;
  21.     BITMAP *ship;
  22.     
  23.     //initialize program    
  24.     allegro_init();
  25.     set_color_depth(16);
  26.     set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
  27.     install_keyboard();
  28.     install_mouse();
  29.     textout_ex(screen,font,"PositionMouse Program (ESC to quit)",0,0,WHITE,0);
  30.     
  31.     //load the custom mouse pointer
  32.     ship = load_bitmap("spaceship.bmp", NULL);
  33.     set_mouse_sprite(ship);
  34.     set_mouse_sprite_focus(ship->w/2,ship->h/2);
  35.     show_mouse(screen);
  36.  
  37.     //draw the wormholes
  38.     for (n=0;n<20;n++)
  39.     {
  40.         circle(screen,150-3*n,150-3*n,n*2,makecol(10*n,10*n,10*n));
  41.         circle(screen,480+3*n,330+3*n,n*2,makecol(10*n,10*n,10*n));
  42.     }
  43.  
  44.     while (!key[KEY_ESC])
  45.     {
  46.         if (mouseinside(90,90,150,150))
  47.             position_mouse(550,400);
  48.         
  49.         if (mouseinside(480,330,540,390))
  50.             position_mouse(80,80);
  51.     }
  52.     set_mouse_sprite(NULL);
  53.     destroy_bitmap(ship);
  54.     allegro_exit();
  55.     return 0;
  56. }
  57. END_OF_MAIN()
  58.