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

  1. ////////////////////////////////////////////////////
  2. // Game Programming All In One, Third Edition
  3. // Chapter 5, Stargate Program
  4. ////////////////////////////////////////////////////
  5.  
  6. #include <allegro.h>
  7.  
  8. #define WHITE makecol(255,255,255)
  9. #define BLUE makecol(64,64,255)
  10. #define RED makecol(255,64,64)
  11.  
  12. typedef struct POINT
  13. {
  14.     int x, y;
  15. } POINT;
  16.  
  17. POINT coords[] = {{25,235},
  18.                   {15,130},
  19.                   {60,50},
  20.                   {165,10},
  21.                   {270,50},
  22.                   {325,135},
  23.                   {315,235}};
  24.  
  25. BITMAP *stargate;
  26. BITMAP *water;
  27. BITMAP *symbols[7];
  28. int count = 0;
  29.  
  30. //helper function to highlight each shevron
  31. void shevron(int num)
  32. {
  33.     floodfill(screen, 20+coords[num].x, 50+coords[num].y, RED);
  34.  
  35.     if (++count > 6)
  36.     { 
  37.         masked_blit(water,screen,0,0,67,98,water->w,water->h);
  38.         textout_centre_ex(screen,font,"WORMHOLE ESTABLISHED!",
  39.             SCREEN_W/2, SCREEN_H-30, RED,-1);
  40.     }
  41. }
  42.  
  43. //main function
  44. int main(void)
  45. {
  46.     int n;
  47.  
  48.     //initialize program    
  49.     allegro_init();
  50.     set_color_depth(16);
  51.     set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
  52.     install_keyboard();
  53.  
  54.     //load the stargate image
  55.     stargate = load_bitmap("stargate.bmp", NULL);
  56.     blit(stargate,screen,0,0,20,50,stargate->w,stargate->h);
  57.     
  58.     //load the water image
  59.     water = load_bitmap("water.bmp", NULL);
  60.  
  61.     //load the symbol images
  62.     symbols[0] = load_bitmap("symbol1.bmp", NULL);
  63.     symbols[1] = load_bitmap("symbol2.bmp", NULL);
  64.     symbols[2] = load_bitmap("symbol3.bmp", NULL);
  65.     symbols[3] = load_bitmap("symbol4.bmp", NULL);
  66.     symbols[4] = load_bitmap("symbol5.bmp", NULL);
  67.     symbols[5] = load_bitmap("symbol6.bmp", NULL);
  68.     symbols[6] = load_bitmap("symbol7.bmp", NULL);
  69.     
  70.     //display the symbols
  71.     textout_ex(screen,font,"DIALING SEQUENCE", 480, 50, WHITE, -1);
  72.     for (n=0; n<7; n++)
  73.     {
  74.         textprintf_ex(screen,font,480,70+n*40,BLUE,-1,"%d", n+1);
  75.         blit(symbols[n],screen,0,0,530,70+n*40,32,32);
  76.     }
  77.     
  78.     //display title
  79.     textout_ex(screen,font,"STARGATE PROGRAM (ESC to quit)", 0, 0, RED,-1);
  80.     textout_ex(screen,font,"PRESS THE CORRECT KEYS (A-Z) "\
  81.         "TO DIAL THE STARGATE", 0, 10, RED,-1);
  82.  
  83.     //main loop
  84.     while (!key[KEY_ESC])
  85.     {
  86.         //check for proper sequence
  87.         switch (count)
  88.         {
  89.             case 0:
  90.                 if (key[KEY_A]) shevron(0);
  91.                 break;
  92.             case 1:
  93.                 if (key[KEY_Y]) shevron(1);
  94.                 break;
  95.             case 2:
  96.                 if (key[KEY_B]) shevron(2);
  97.                 break;
  98.             case 3:
  99.                 if (key[KEY_A]) shevron(3);
  100.                 break;
  101.             case 4:
  102.                 if (key[KEY_B]) shevron(4);
  103.                 break;
  104.             case 5:
  105.                 if (key[KEY_T]) shevron(5);
  106.                 break;
  107.             case 6:
  108.                 if (key[KEY_U]) shevron(6);
  109.                 break;
  110.         }
  111.     }
  112.     
  113.     //clean up
  114.     destroy_bitmap(stargate);
  115.     destroy_bitmap(water);
  116.     for (n=0; n<7; n++)
  117.         destroy_bitmap(symbols[n]);
  118.         
  119.     allegro_exit();
  120.     return 0;
  121. }
  122. END_OF_MAIN()
  123.  
  124.