home *** CD-ROM | disk | FTP | other *** search
/ Game Programming - All in One (3rd Edition) / game_prog_all_in_one_3rd_ed.iso / software / Mappy / mappyal / mousecrd.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-03  |  3.1 KB  |  91 lines

  1. /* (C)2001 Robin Burrows! Playback demo mousecrd.c */
  2.  
  3. #include <stdio.h>
  4. #include <allegro.h>
  5. #include "mappyal.h"
  6.  
  7. #define SWIDTH 320        /* Standard VGA for this demo */
  8. #define SHEIGHT 200
  9.  
  10. int mapxoff = 0;        /* X and Y offset in pixels */
  11. int mapyoff = 0;
  12. BITMAP * mapdisplaybuffer;    /* Memory bitmap for double buffer */
  13.  
  14. int main (void)
  15. {
  16. BITMAP * escbmpt;        /* For hit ESC message */
  17. char mousettxt[80];
  18.  
  19.     allegro_init();    /* Normal Allegro calls to start with */
  20.     install_timer();
  21.     install_keyboard();
  22.     install_mouse();
  23.  
  24.     if (set_gfx_mode (GFX_AUTODETECT, SWIDTH, SHEIGHT, 0, 0)<0) exit (0);
  25.  
  26.     if (MapLoad ("HEXTST.FMP")) {            /* Load the FMP file, exit if error */
  27.         allegro_message ("Can't find HEXTST.FMP, please run exe from same folder");
  28.         exit (0);
  29.     }
  30.     MapSetPal8 ();                    /* Set palette */
  31.     MapInitAnims ();                    /* Reset animations */
  32.  
  33.     mapdisplaybuffer = create_bitmap (SWIDTH, SHEIGHT);    /* Double buffer */
  34.     if (mapdisplaybuffer==NULL) { MapFreeMem (); exit (0); }
  35.     clear (mapdisplaybuffer);
  36.  
  37. /* Next, put '* Hit ESC to exit*' text on a BITMAP */
  38.     escbmpt = create_bitmap (136, 8);
  39.     if (escbmpt==NULL) { destroy_bitmap (mapdisplaybuffer); MapFreeMem (); exit (0); }
  40.     clear (escbmpt); text_mode (-1);
  41.         textout (escbmpt, font, "*Hit ESC to exit*", 0, 0, makecol (255,255,255));
  42.  
  43. /* This is the main loop, which is repeated until SPACE or ESC is pressed */
  44.     while (1)
  45.     {
  46. /* copy the doublebuffer to display it */
  47.         vsync(); /* simple timing for this demo */
  48.         blit (mapdisplaybuffer, screen, 0, 0, 0, 0, SWIDTH, SHEIGHT);
  49.  
  50. /* Call this next function to update the animations */
  51.         MapUpdateAnims ();
  52.  
  53.         if (key[KEY_RIGHT]) mapxoff++; if (mapxoff > (75*16)) mapxoff = (75*16);
  54.         if (key[KEY_LEFT]) mapxoff--; if (mapxoff < 0) mapxoff = 0;
  55.         if (key[KEY_UP]) mapyoff--; if (mapyoff < 0) mapyoff = 0;
  56.         if (key[KEY_DOWN]) mapyoff++; if (mapyoff > (80*16)) mapyoff = (80*16);
  57.         if (key[KEY_ESC]) break;
  58.         if (key[KEY_SPACE]) break;
  59.  
  60. /* Here the Map Background layer is drawn... */
  61.         MapDrawBG (mapdisplaybuffer, mapxoff, mapyoff, 0, 0, SWIDTH, SHEIGHT);
  62.  
  63. /* Anything you want BETWEEN back and foreground goes in here... */
  64.         blit (escbmpt, mapdisplaybuffer, 0, 0, SWIDTH/2-68, SHEIGHT-30, 136, 8);
  65.  
  66. /* Lastly, the foreground is drawn, you can call this 0 to 3 times, depending
  67.  * on how many foreground layers you are using, or which you want displayed.
  68.  * The last paramater is the foreground layer number, and can be 0, 1, or 2 */
  69.         MapDrawFG (mapdisplaybuffer, mapxoff, mapyoff, 0, 0, SWIDTH, SHEIGHT, 0);
  70.  
  71.         text_mode (0);
  72.         textout (mapdisplaybuffer, font, "X", mouse_x-3, mouse_y-3, makecol (255,255,255));
  73. /* Find out exact block (pixel perfect!) */
  74.         sprintf (mousettxt, "Mouse over block at %d, %d",
  75.             MapGetXOffset (mouse_x+mapxoff, mouse_y+mapyoff),
  76.             MapGetYOffset (mouse_x+mapxoff, mouse_y+mapyoff));
  77.         textout (mapdisplaybuffer, font, mousettxt, 0, 0, makecol (255,255,255));
  78.     }
  79.  
  80. /* When ESC or SPACE has been pressed, it's time to clean up and leave */
  81.     destroy_bitmap (mapdisplaybuffer);
  82.     destroy_bitmap (escbmpt);
  83.     MapFreeMem ();
  84.     allegro_exit();
  85.     return 0;
  86. }
  87. #ifdef END_OF_MAIN
  88. END_OF_MAIN()
  89. #endif
  90.  
  91.