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

  1. /* (C)2001 Robin Burrows! Proja demo */
  2.  
  3. #include <stdio.h>
  4. #include <allegro.h>
  5. #include "mappyal.h"
  6.  
  7. #define SWIDTH 320
  8. #define SHEIGHT 240
  9.  
  10. int mapxoff = 16;        /* 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 ("PROJA.FMP")) {            /* Load the FMP file, exit if error */
  25.         allegro_message ("Can't find PROJA.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.     mapyoff = (mapheight*mapblockheight)-(SHEIGHT*2);
  43. /* This is the main loop, which is repeated until SPACE or ESC is pressed */
  44.     quitit = 0; while (!quitit)
  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.         MapUpdateAnims ();
  51.  
  52.         if (mapyoff > 0) mapyoff--;
  53.         if (key[KEY_ESC]) quitit = 1;
  54.         if (key[KEY_SPACE]) quitit = 1;
  55.  
  56.         MapChangeLayer (0);
  57.         MapDrawBG (mapdisplaybuffer, mapxoff/2, mapyoff/2, 0, 0, SWIDTH, SHEIGHT);
  58. /* Anything you want BETWEEN back and foreground goes in here... */
  59.         masked_blit (escbmpt, mapdisplaybuffer, 0, 0, SWIDTH/2-68, SHEIGHT-30, 136, 8);
  60.         MapChangeLayer (1);
  61.         MapDrawBGT (mapdisplaybuffer, mapxoff, mapyoff, 0, 0, SWIDTH, SHEIGHT);
  62.     }
  63.  
  64. /* When ESC or SPACE has been pressed, it's time to clean up and leave */
  65.     destroy_bitmap (mapdisplaybuffer);
  66.     destroy_bitmap (escbmpt);
  67.     MapFreeMem ();
  68.     allegro_exit();
  69.     return 0;
  70. }
  71. #ifdef END_OF_MAIN
  72. END_OF_MAIN()
  73. #endif
  74.  
  75.