home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / C / Sprites.c < prev   
Encoding:
C/C++ Source or Header  |  1997-01-19  |  3.2 KB  |  103 lines

  1. /*
  2. ** Sprite example
  3. ** --------------
  4. ** This example shows you how to set up a 16 colour OCS sprite with a
  5. ** doubled X axis (32 pixels width).  Those with hardware experience will
  6. ** know that it takes 4 sprite banks to do this successfully in OCS, which
  7. ** leaves you with another 4 banks to do with what you will.  You can do
  8. ** this same demo in AGA with just 2 banks used.
  9. ** 
  10. ** The sprite is attached to the mouse, so try moving it around a bit.
  11. */
  12.  
  13. #include <exec/memory.h>
  14. #include <proto/games.h>
  15. #include <proto/exec.h>
  16.  
  17. struct GMSBase *GMSBase;
  18. extern struct ExecBase *SysBase;
  19.  
  20. UWORD  Timer;
  21. APTR   SprMemBase;
  22. ULONG  ZBXY;
  23.  
  24. struct Sprite Sprite0 = {
  25.    SPV1,             /* Version number */
  26.    0,                /* Bank Number 0 */
  27.    0,                /* Ptr to graphic */
  28.    100,100,          /* Beginning X/Y positions */
  29.    0,                /* Current frame */
  30.    16,21,            /* Width, Height */
  31.    16,               /* Amt of colours */
  32.    16,               /* Colour start in palette */
  33.    2,                /* Amt of planes */
  34.    LORES,            /* Resolution */
  35.    0,                /* Position in relation to playfields */
  36.    XLONG             /* Special attributes */
  37. };
  38.  
  39. UWORD Palette[] = {
  40.    0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
  41.    0x000,0x688,0x466,0x344,0xCC0,0x980,0x870,0x650,
  42.    0x1C2,0x050,0xB0B,0x606,0xF20,0x910,0xBBB,0xFFF,
  43.    0x0BF,0x068,0x568,0x9BF,0xFF0,0xEE0,0xBA0,0x540
  44. };
  45.  
  46. struct GameScreen GameScreen = {
  47.    GSV1,             /* GameScreen Version */
  48.    0,0,0,            /* Screen Memory 1,2,3 */
  49.    0,                /* ScreenLink */
  50.    &Palette,         /* Address of Palette */
  51.    0,                /* Address of RasterList */
  52.    32,               /* Amount of colours */
  53.    320,256,          /* Screen Width and Height */
  54.    320,320/8,256,    /* Picture Width/8 and Height */
  55.    1,                /* Amount of planes */
  56.    0,0,              /* X/Y screen offset */
  57.    0,0,              /* X/Y picture offset */
  58.    SPRITES|NOSCRBDR, /* Special attributes */
  59.    LORES|COL12BIT,   /* Screen mode */
  60.    INTERLEAVED       /* Screen type */
  61. };
  62.  
  63. struct GameScreen *OurScreen = &GameScreen;
  64. struct Sprite *Sparkie = &Sprite0;
  65.  
  66. /*=========================================================================*/
  67.  
  68. void main(void)
  69. {
  70.    if (GMSBase = (struct GMSBase *) OpenLibrary("games.library",0)) {
  71.       SetUserPrefs(0);
  72.       Sparkie->Data = SmartLoad("GAMESLIB:data/Sparkie.raw",0,MEMF_CHIP);
  73.  
  74.       if (AddScreen(OurScreen) == NULL) {
  75.          if (InitSprite(OurScreen,Sparkie) == ERR_OK) {
  76.             UpdateSprite(OurScreen,Sparkie);
  77.             ShowScreen(OurScreen);
  78.  
  79.             ZBXY = ReadMouse(JPORT1);         /* Initialise the mouse port */
  80.  
  81.             while (!(ZBXY&MB_LMB)) {
  82.  
  83.                if (++Timer&0x1) {
  84.                   if (Sparkie->Frame == 5) Sparkie->Frame = 0;
  85.                   else Sparkie->Frame++;
  86.                }
  87.  
  88.                ZBXY = ReadMouse(JPORT1);
  89.                Sparkie->XPos += GetX(ZBXY);
  90.                Sparkie->YPos += GetY(ZBXY);
  91.                WaitSVBL();
  92.                UpdateSprite(OurScreen, Sparkie);
  93.             }
  94.          FreeSprite(Sparkie);
  95.          }
  96.       DeleteScreen(OurScreen);
  97.       }
  98.    FreeMemBlock(Sparkie->Data);
  99.    CloseLibrary((struct Library *)GMSBase);
  100.    }
  101. }
  102.  
  103.