/*
** Name:      Mirror Demo
** Author:    Paul Manias
** Copyright: DreamWorld Productions, (c) 1996-1997
** SAS/C:     1> sc Mirror.c link startup=LIB:gms.o data=far nostackcheck
** Dice:      1> dcc -l0 -mD gms.o Mirror.c -o Mirror
**
** Demo of the mirroring effect.  When this effect is combined with a
** decrease in palette values at the same line, you can create the illusion of
** water.  Use the mouse to move the mirror around. LMB exits.
**
*/

#include <proto/games.h>

extern struct GMSBase *GMSBase;
ULONG PREFSNAME = DEFAULT;

ULONG WaterPalette[] = {
  0x000000,0x001000,0x706050,0x705040,0x604040,0x403020,0x302020,0x100000,
  0x200000,0x202020,0x707000,0x201010,0x606000,0x002000,0x200000,0x404000,
  0x103000,0x103000,0x104010,0x204010,0x205010,0x205020,0x303030,0x306020,
  0x304040,0x405050,0x606060,0x400000,0x400000,0x500010,0x300000,0x300000
};

ULONG Rasterlist[] = {
  WAITLINE(190),
  MIRROR,
  NEWPALETTE(0,32,WaterPalette),
  RASTEND
};

void main(void)
{
  struct GameScreen *GameScreen;
  struct Picture *MirrorPic;
  ULONG  mouse;
  WORD   maxX,maxY;

  if (MirrorPic = LoadPicFile("GMS:demos/data/PIC.Green",VIDEOMEM|GETPALETTE)) {

     if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
          GSA_MemPtr1,    MirrorPic->Data,
          GSA_Palette,    MirrorPic->Palette,
          GSA_Rasterlist, Rasterlist,
          GSA_ScrWidth,   MirrorPic->ScrWidth,
          GSA_ScrHeight,  MirrorPic->ScrHeight,
          GSA_PicWidth,   MirrorPic->Width,
          GSA_PicHeight,  MirrorPic->Height,
          GSA_Planes,     MirrorPic->Planes,
          GSA_AmtColours, MirrorPic->AmtColours,
          GSA_Attrib,     HSCROLL|VSCROLL,
          GSA_ScrMode,    MirrorPic->ScrMode,
          GSA_ScrType,    MirrorPic->ScrType,
          TAGEND)) {

       ShowScreen(GameScreen);
       InitJoyPorts();

       maxX = (GameScreen->PicWidth)-(GameScreen->ScrWidth);
       maxY = (GameScreen->PicHeight)-(GameScreen->ScrHeight);

       do {
          mouse = ReadJoyPort(JPORT1,JT_ZBXY);
          GameScreen->PicXOffset += GetX(mouse);
          GameScreen->PicYOffset += GetY(mouse);
          if (GameScreen->PicXOffset < 0) GameScreen->PicXOffset = 0;
          if (GameScreen->PicXOffset > maxX) GameScreen->PicXOffset = maxX;
          if (GameScreen->PicYOffset < 0) GameScreen->PicYOffset = 0;
          if (GameScreen->PicYOffset > maxY) GameScreen->PicYOffset = maxY;
          MovePicture(GameScreen);
          WaitVBL();
       } while (!(mouse & MB_LMB));

     DeleteScreen(GameScreen);
     }
  FreePic(MirrorPic);
  }
}

