/*
** Name:      BounceLine.c
** Author:    Paul Manias
** Copyright: DreamWorld Productions, 1997.
** Doc:       Line bouncing demo that works on a screen of any type of
**            dimensions as specified by the user in GMSPrefs.
**
** SAS/C:     1> sc BounceLine.c link startup=LIB:gms.o data=far nostackcheck
** Dice:      1> dcc -l0 -mD gms.o BounceLine.c -o BounceLine
**
*/

#include <proto/games.h>

extern struct GMSBase *GMSBase;
ULONG PREFSNAME = DEFAULT;

void main(void)
{
  struct GameScreen *GameScreen;
  ULONG palette[] = { 0x000000,0x80f0f0 };
  ULONG mousestat;
  int sx,sy,ex,ey;
  int dsx,dsy,dex,dey;

  if (AllocBlitter() == NULL) {
    if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
       GSA_Palette,palette,
       GSA_AmtColours,2,
       GSA_Attrib,DBLBUFFER,
       TAGEND)) {

       sx = SlowRandom(GameScreen->ScrWidth);  dsx = -1;
       sy = SlowRandom(GameScreen->ScrHeight); dsy = 2;
       ex = SlowRandom(GameScreen->ScrWidth);  dex = 3;
       ey = SlowRandom(GameScreen->ScrHeight); dey = 1;

       ShowScreen(GameScreen);

       do
       {
         ClearBitmap(GameScreen->Bitmap);
         mousestat = ReadJoyPort(JPORT1,JT_ZBXY);
         sx += dsx;
         sy += dsy;
         ex += dex;
         ey += dey;

         if(sx<0) { sx = 0; dsx = -(dsx); }
         if(sy<0) { sy = 0; dsy = -(dsy); }
         if(ex<0) { ex = 0; dex = -(dex); }
         if(ey<0) { ey = 0; dey = -(dey); }

         if(sx>GameScreen->ScrWidth-1) {
           sx  = GameScreen->ScrWidth-1;
           dsx = -(dsx);
         }

         if(sy>GameScreen->ScrHeight-1) {
           sy  = GameScreen->ScrHeight-1;
           dsy = -(dsy);
         }

         if(ex>GameScreen->ScrWidth-1) {
           ex  = GameScreen->ScrWidth-1;
           dex = -(dex);
         }

         if(ey>GameScreen->ScrHeight-1) {
           ey  = GameScreen->ScrHeight-1;
           dey = -(dey);
         }

         DrawUCLine(GameScreen->Bitmap,sx,sy,ex,ey,1);
         WaitVBL();
         SwapBuffers(GameScreen);
       } while (!(mousestat & MB_LMB));

    DeleteScreen(GameScreen);
    }
  FreeBlitter();
  }
}

