/*
** Sprite example
** --------------
** This example shows you how to set up a 16 colour OCS sprite with a
** doubled X axis (32 pixels width).  Those with hardware experience will
** know that it takes 4 sprite banks to do this successfully in OCS, which
** leaves you with another 4 banks to do with what you will.  You can do
** this same demo in AGA with just 2 banks used.
** 
** The sprite is attached to the mouse, so try moving it around a bit.
**
** To compile with SAS/C
**  1> sc Sprites.c link startup=LIB:gms.o data=far
**
*/

#include <proto/games.h>

extern struct GMSBase *GMSBase;
ULONG  _XCEXIT = NULL;
APTR   PREFSNAME = DEFAULT;

ULONG Palette[] = {
   0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,
   0x000000,0x608080,0x406060,0x304040,0xC0C000,0x908000,0x807000,0x605000,
   0x10C020,0x005000,0xB000B0,0x600060,0xF02000,0x901000,0xB0B0B0,0xF0F0F0,
   0x00B0F0,0x006080,0x506080,0x90B0F0,0xF0F000,0xE0E000,0xB0A000,0x504000
};

void main(void)
{
  struct Sprite *Sparkie;
  struct GameScreen *GameScreen;
  APTR  SparkieData;
  UWORD Timer=0;
  ULONG ZBXY=0;

  if (SparkieData = SmartLoad("GMS:demos/data/RAW.Sparkie",0,MEM_VIDEO)) {
  
    if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
       GSA_Palette,Palette,
       GSA_AmtColours,32,
       GSA_Planes,1,
       GSA_Attrib,SPRITES|NOSCRBDR,
       TAGEND)) {
  
       if (Sparkie = InitSpriteTags(GameScreen,TAGS_SPRITE,NULL,
          SPA_Data,SparkieData,
          SPA_XCoord,100,
          SPA_YCoord,100,
          SPA_Width,16,
          SPA_Height,21,
          SPA_AmtColours,16,
          SPA_ColStart,16,
          SPA_Planes,2,
          SPA_ScrMode,LORES,
          SPA_Attrib,XLONG,
          TAGEND)) {

          UpdateSprite(GameScreen,Sparkie);
          ShowScreen(GameScreen);
  
          InitJoyPorts();
  
          while (!(ZBXY&MB_LMB)) {
  
             if (++Timer&0x1) {
                if (Sparkie->Frame == 5) Sparkie->Frame = 0;
                else Sparkie->Frame++;
             }
  
             ZBXY = ReadMouse(JPORT1);
             Sparkie->XPos += GetX(ZBXY);
             Sparkie->YPos += GetY(ZBXY);
             WaitVBL();
             UpdateSprite(GameScreen, Sparkie);
          }
       FreeSprite(Sparkie);
       }
    DeleteScreen(GameScreen);
    }
  FreeMemBlock(SparkieData);
  }
}

