home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / C / BlitWorm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-16  |  4.4 KB  |  186 lines

  1. /* BOB Demo
  2. ** --------
  3. ** Blits a Worm to screen using a BOB structure.  This version does not include
  4. ** the sound from the asm version.
  5. **
  6. */
  7.  
  8. #include <proto/games.h>
  9. #include <proto/exec.h>
  10.  
  11. struct GMSBase *GMSBase;
  12. extern struct ExecBase *SysBase;
  13.  
  14. struct GameScreen *GameScreen;
  15. struct RestoreList *RestoreList;
  16. struct Picture *PIC_Bobs;
  17.  
  18. #define AMT_PLANES 5
  19. #define TRUE 1
  20. #define FALSE 0
  21.  
  22. struct Picture PIC_Background = {
  23.   PCV1,                     /* Version header */
  24.   0,                        /* Source data */
  25.   320,0,256,                /* Width, Height */
  26.   AMT_PLANES,               /* Amount of Planes */
  27.   0,                        /* Amount of colours */
  28.   0,                        /* Source palette */
  29.   LORES|COL12BIT,           /* Screen mode */
  30.   ILBM,                     /* Destination */
  31.   GETPALETTE,               /* Parameters */
  32.   "GAMESLIB:data/IFF.Pic320"
  33. };
  34.  
  35. WORD FrameList[] = {
  36.     0,0,0,0,
  37.    32,0,0,0,
  38.    64,0,0,0,
  39.    96,0,0,0,
  40.   128,0,0,0,
  41.   160,0,0,0,
  42.   192,0,0,0,
  43.   224,0,0,0,
  44.   256,0,0,0,
  45.   288,0,0,0,
  46.    0,48,0,0,
  47.   32,48,0,0,
  48.   64,48,0,0,
  49.   -1
  50. };
  51.  
  52. struct BOB BOB_Rambo = {
  53.   BBV1,                  /* Structure version */
  54.   0,0,                   /* Graphics & Mask data */
  55.   0,                     /* Current frame */
  56.   FrameList,             /* Pointer to frame list */
  57.   0,                     /* Page Width */
  58.   32,32/8,24,            /* Width, Width in bytes, Height */
  59.   150,150,               /* X/Y destination */
  60.   0,0,                   /* Border restriction LeftX/8, TopY */
  61.   0,0,                   /* Border restrictions RightX/8, EndY */
  62.   0,0,                   /* Amount of planes */
  63.   0,                     /* Size of plane, not required */
  64.   RESTORE|GENMASKS|CLIP, /* Attributes */
  65.   0                      /* Picture struct (Bob origin) */
  66. };
  67.  
  68. void Demo(void);
  69.  
  70. /*=========================================================================*/
  71.  
  72. void main(void)
  73. {
  74.  if (GMSBase = (struct GMSBase *) OpenLibrary("games.library",0))
  75.  {
  76.   SetUserPrefs(0); 
  77.   if (AllocBlitter() == ERR_OK)
  78.   {
  79.    if (AllocAudio() == ERR_OK)
  80.    {
  81.     if (GameScreen = AddScreenTags(TAGS,NULL,
  82.         GSA_Planes,AMT_PLANES,
  83.         GSA_ScrMode,LORES|COL12BIT,
  84.         GSA_ScrWidth,320,
  85.         GSA_ScrHeight,256,
  86.         GSA_ScrType,ILBM,
  87.         GSA_Attrib,DBLBUFFER,
  88.         TAGEND))
  89.     {
  90.      PIC_Background.Data = GameScreen->MemPtr2; 
  91.      if (LoadPic(&PIC_Background) == ERR_OK)
  92.      {
  93.       GameScreen->Palette = PIC_Background.Palette; 
  94.       UpdatePalette(GameScreen);
  95.       SwapBuffers(GameScreen);
  96.       CopyBuffer(GameScreen,BUFFER1,BUFFER2);
  97.       if (RestoreList = InitRestore(2,1))
  98.       {
  99.        if (PIC_Bobs = LoadPicTags(TAGS,NULL,
  100.           PCA_Planes,AMT_PLANES,
  101.           PCA_ScrType,ILBM,
  102.           PCA_Options,VIDEOMEM,
  103.           PCA_File,"GAMESLIB:data/IFF.Rambo",
  104.           TAGEND))
  105.        {
  106.         BOB_Rambo.Picture = PIC_Bobs;
  107.         if (InitBOB(GameScreen,&BOB_Rambo) == ERR_OK)
  108.         {
  109.           ShowScreen(GameScreen); 
  110.           Demo();
  111.         FreeBOB(&BOB_Rambo); 
  112.         }
  113.        FreePic(PIC_Bobs); 
  114.        }
  115.       FreeRestore(RestoreList); 
  116.       }
  117.      FreePic(&PIC_Background); 
  118.      }
  119.     DeleteScreen(GameScreen); 
  120.     }
  121.    FreeAudio(); 
  122.    }
  123.   FreeBlitter(); 
  124.   }
  125.  CloseLibrary((struct Library *)GMSBase); 
  126.  }
  127. }
  128.  
  129. /*=========================================================================*/
  130.  
  131. void Demo(void)
  132. {
  133.   ULONG mouse=0; 
  134.   UWORD anim=0,fire=FALSE;
  135.  
  136.   InitJoyPorts(); 
  137.  
  138.   do
  139.   {
  140.     Restore(GameScreen,RestoreList); 
  141.     DrawBOB(GameScreen,&BOB_Rambo,RestoreList,BUFFER2); 
  142.     WaitSVBL(); 
  143.     SwapBuffers(GameScreen);
  144.  
  145.     /* Animate the Worm's movements */
  146.  
  147.     anim++;
  148.  
  149.     if (fire == FALSE) {
  150.       if (anim > 5) {
  151.         anim = 0;
  152.         BOB_Rambo.Frame++;
  153.         if (BOB_Rambo.Frame > 9)
  154.            BOB_Rambo.Frame = 0;
  155.       }
  156.     }
  157.     else if (anim > 1) {
  158.       anim = 0;
  159.       if (BOB_Rambo.Frame < 10)
  160.          BOB_Rambo.Frame = 9;
  161.  
  162.       BOB_Rambo.Frame++;
  163.  
  164.       if (BOB_Rambo.Frame > 12) {
  165.          if (mouse & MB_LMB)
  166.             BOB_Rambo.Frame = 11;
  167.          else {
  168.             BOB_Rambo.Frame = 0;
  169.             fire = FALSE;
  170.          }
  171.       }
  172.     }
  173.  
  174.     /* Get the user input */
  175.  
  176.     mouse = ReadJoyPort(JPORT1,JT_ZBXY);
  177.     BOB_Rambo.XCoord += GetX(mouse);
  178.     BOB_Rambo.YCoord += GetY(mouse);
  179.     if (mouse & MB_LMB)
  180.        fire = TRUE;
  181.  
  182.   } while (!(mouse & MB_RMB)); 
  183. }
  184.  
  185. /*=========================================================================*/
  186.