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

  1. /* (C)2001 Robin Burrows Playback demo 3 */
  2.  
  3. #include <stdio.h>
  4. #include <allegro.h>
  5. #include "mappyal.h"
  6.  
  7. #define SWIDTH 320
  8. #define SHEIGHT 200
  9.  
  10. int mapxoff = 670;        /* X and Y offset in pixels */
  11. int mapyoff = 650;
  12. int fps = 0;
  13. int fpscounter = 0;
  14. BITMAP * dbuffer;        /* Memory bitmap for double buffer */
  15.  
  16. void fpsinterrupt (void)
  17. {
  18.     fps = fpscounter; fpscounter = 0;
  19. }
  20. END_OF_FUNCTION (fpsinterrupt);
  21.  
  22. void DisplayFPS (void)
  23. {
  24. char fpstext[8];
  25.  
  26.     sprintf (fpstext, "FPS=%d", fps);
  27.     text_mode (0);
  28.     textout (dbuffer, font, fpstext, 0, 0, 255);
  29. }
  30.  
  31. int main (void)
  32. {
  33. PALETTE pal;
  34. int quitit;
  35. BITMAP * escbmpt;        /* For hit ESC message */
  36. BITMAP * parallaxbm, * tempbm;
  37.  
  38.     allegro_init();    /* Normal Allegro calls to start with */
  39.     install_timer();
  40.     install_keyboard();
  41.  
  42.     if (set_gfx_mode (GFX_AUTODETECT, SWIDTH, SHEIGHT, 0, 0)<0) exit (0);    /* Lovely VGA */
  43.     if (MapLoad ("TEST.FMP")) {            /* Load the FMP file, exit if error */
  44.         allegro_message ("Can't find TEST.FMP, please run exe from same folder");
  45.         exit (0);
  46.     }
  47.     MapSetPal8 ();                    /* Set palette */
  48.     MapCorrectColours ();                /* Not needed for 8bit, but call anyway */
  49.  
  50.     MapInitAnims ();                    /* Reset animations */
  51.     tempbm = load_bitmap ("PARALLAX.BMP", pal);
  52.     parallaxbm = NULL;
  53. /* If loaded BMP OK, make it into a parallax bitmap */
  54.     if (tempbm != NULL) parallaxbm = MapMakeParallaxBitmap (tempbm, 0);
  55.  
  56.     dbuffer = create_bitmap (SWIDTH, SHEIGHT);    /* Double buffer */
  57.     if (dbuffer==NULL) { MapFreeMem (); exit (0); }
  58.     clear (dbuffer);
  59.  
  60. /* Next, put '* Hit ESC to exit*' text on a BITMAP */
  61.     escbmpt = create_bitmap (136, 8);
  62.     if (escbmpt==NULL) { destroy_bitmap (dbuffer); MapFreeMem (); exit (0); }
  63.     clear (escbmpt); text_mode (-1);
  64.         textout (escbmpt, font, "*Hit ESC to exit*", 0, 0, makecol(255,255,255));
  65.  
  66. /* Now draw a border to show that DrawMap clips properly */
  67.     rect (dbuffer, 3, 3, SWIDTH-4, SHEIGHT-4, makecol(255,255,255));
  68.     rect (dbuffer, 9, 9, SWIDTH-10, SHEIGHT-10, makecol(255,255,255));
  69.  
  70. /* See allegro docs for interrupts... */
  71.     LOCK_VARIABLE (fps); LOCK_VARIABLE (fpscounter); LOCK_FUNCTION (fpsinterrupt);
  72.     install_int (fpsinterrupt, 1000);
  73. /* This is the main loop, which is repeated until SPACE or ESC is pressed */
  74.     quitit = 0; while (!quitit)
  75.     {
  76. /* No Vsync to see how fast we can go, copy the doublebuffer to display it */
  77.         blit (dbuffer, screen, 0, 0, 0, 0, SWIDTH, SHEIGHT);
  78.  
  79. /* Call this next function to update the animations */
  80.         MapUpdateAnims ();
  81.  
  82.         if (key[KEY_RIGHT]) mapxoff++; if (mapxoff > (75*16)) mapxoff = (75*16);
  83.         if (key[KEY_LEFT]) mapxoff--; if (mapxoff < 0) mapxoff = 0;
  84.         if (key[KEY_UP]) mapyoff--; if (mapyoff < 0) mapyoff = 0;
  85.         if (key[KEY_DOWN]) mapyoff++; if (mapyoff > (80*16)) mapyoff = (80*16);
  86.         if (key[KEY_ESC]) quitit = 1;
  87.         if (key[KEY_SPACE]) quitit = 1;
  88.  
  89.         if (parallaxbm != NULL)
  90.             MapDrawParallax (dbuffer, parallaxbm, mapxoff, mapyoff, 10, 10, 300, 180);
  91. /* Here the Map Background layer is drawn... */
  92.         MapDrawBGT (dbuffer, mapxoff, mapyoff, 10, 10, 300, 180);
  93. /* Anything you want BETWEEN back and foreground goes in here... */
  94.         masked_blit (escbmpt, dbuffer, 0, 0, SWIDTH/2-68, SHEIGHT-30, 136, 8);
  95. /* Lastly, the foreground is drawn, you can call this 0 to 3 times, depending
  96.  * on how many foreground layers you are using, or which you want displayed.
  97.  * The last paramater is the foreground layer number, and can be 0, 1, or 2 */
  98.         MapDrawFG (dbuffer, mapxoff, mapyoff, 10, 10, 300, 180, 0);
  99.         fpscounter++; DisplayFPS ();
  100.     }
  101.  
  102. /* When ESC or SPACE has been pressed, it's time to clean up and leave */
  103.     remove_int (fpsinterrupt);
  104.     destroy_bitmap (dbuffer);
  105.     destroy_bitmap (escbmpt);
  106.     MapFreeMem ();
  107.     allegro_exit();
  108.     return 0;
  109. }
  110. #ifdef END_OF_MAIN
  111. END_OF_MAIN()
  112. #endif
  113.  
  114.