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 / pbdemo1.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-03  |  3.0 KB  |  85 lines

  1. /* (C)2001 Robin Burrows! Playback demo 1 */
  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. int quitit;
  17. BITMAP * escbmpt;        /* For hit ESC message */
  18.  
  19.     allegro_init();    /* Normal Allegro calls to start with */
  20.     install_timer();
  21.     install_keyboard();
  22.  
  23.     if (set_gfx_mode (GFX_AUTODETECT, SWIDTH, SHEIGHT, 0, 0)<0) exit (0);
  24.     if (MapLoad ("TEST.FMP")) {            /* Load the FMP file, exit if error */
  25.         allegro_message ("Can't find TEST.FMP, please run exe from same folder");
  26.         exit (0);
  27.     }
  28.     MapSetPal8 ();                    /* Set palette */
  29.  
  30.     MapInitAnims ();                    /* Reset animations */
  31.  
  32.     mapdisplaybuffer = create_bitmap (SWIDTH, SHEIGHT);    /* Double buffer */
  33.     if (mapdisplaybuffer==NULL) { MapFreeMem (); exit (0); }
  34.     clear (mapdisplaybuffer);
  35.  
  36. /* Next, put '* Hit ESC to exit*' text on a BITMAP */
  37.     escbmpt = create_bitmap (136, 8);
  38.     if (escbmpt==NULL) { destroy_bitmap (mapdisplaybuffer); MapFreeMem (); exit (0); }
  39.     clear (escbmpt); text_mode (-1);
  40.         textout (escbmpt, font, "*Hit ESC to exit*", 0, 0, makecol (255,255,255));
  41.  
  42. /* Now draw a border to show that DrawMap clips properly */
  43.     rect (mapdisplaybuffer, 3, 3, SWIDTH-4, SHEIGHT-4, makecol (255,255,255));
  44.     rect (mapdisplaybuffer, 9, 9, SWIDTH-10, SHEIGHT-10, makecol (255,255,255));
  45.  
  46. /* This is the main loop, which is repeated until SPACE or ESC is pressed */
  47.     quitit = 0; while (!quitit)
  48.     {
  49. /* copy the doublebuffer to display it */
  50.         vsync(); /* simple timing for this demo */
  51.         blit (mapdisplaybuffer, screen, 0, 0, 0, 0, SWIDTH, SHEIGHT);
  52.  
  53. /* Call this next function to update the animations */
  54.         MapUpdateAnims ();
  55.  
  56.         if (key[KEY_RIGHT]) mapxoff++; if (mapxoff > (75*16)) mapxoff = (75*16);
  57.         if (key[KEY_LEFT]) mapxoff--; if (mapxoff < 0) mapxoff = 0;
  58.         if (key[KEY_UP]) mapyoff--; if (mapyoff < 0) mapyoff = 0;
  59.         if (key[KEY_DOWN]) mapyoff++; if (mapyoff > (80*16)) mapyoff = (80*16);
  60.         if (key[KEY_ESC]) quitit = 1;
  61.         if (key[KEY_SPACE]) quitit = 1;
  62.  
  63. /* Here the Map Background layer is drawn... */
  64. /* For a really psychadelic experience, change the next line to MapDraw8BGT */
  65.         MapDrawBG (mapdisplaybuffer, mapxoff, mapyoff, 10, 10, 300, 180);
  66. /* Anything you want BETWEEN back and foreground goes in here... */
  67.         masked_blit (escbmpt, mapdisplaybuffer, 0, 0, SWIDTH/2-68, SHEIGHT-30, 136, 8);
  68. /* Lastly, the foreground is drawn, you can call this 0 to 3 times, depending
  69.  * on how many foreground layers you are using, or which you want displayed.
  70.  * The last paramater is the foreground layer number, and can be 0, 1, or 2 */
  71.         MapDrawFG (mapdisplaybuffer, mapxoff, mapyoff, 10, 10, 300, 180, 0);
  72.     }
  73.  
  74. /* When ESC or SPACE has been pressed, it's time to clean up and leave */
  75.     destroy_bitmap (mapdisplaybuffer);
  76.     destroy_bitmap (escbmpt);
  77.     MapFreeMem ();
  78.     allegro_exit();
  79.     return 0;
  80. }
  81. #ifdef END_OF_MAIN
  82. END_OF_MAIN()
  83. #endif
  84.  
  85.