//---------------------------------------------------------------------------
// Rock paper scissors
//---------------------------------------------------------------------------

void RockPaperScissors (DoubleBuffer *db, u_long memptr)
{
   int        spru[4] = { 0,  0,  0,140};
   int        sprv[4] = {65,127,  2,  0};
   int        sprw[4] = {88,138,138, 98};
   int        sprh[4] = {61, 63, 62,183};
   int        tiscclut;
   TIM_IMAGE  timimg;
   POLY_FT4   *spr;
   point      Po;
   int        whichone = 0, whichone2 = 6;
   int        trig, buttons = 0, vabnbr;
   Foreground *frgnd;
//   Background bkd;
   short      VramHandle;

   memptr = (memptr + 3) & 0xFFFFFFFC;

//   bkd.Load ("\\BACKGRND\\MISCELLA\\RPS.BKD", &memptr);
//   bkd.SetLocation (0,0);

   memptr = (memptr + 3) & 0xFFFFFFFC;

   if (ReadFont ("\\SPRITES\\RPS.TIM", memptr) == 0)
      return;

   if (OpenTIM ((u_long *)memptr))
      return;

   if (!ReadTIM (&timimg))
      return;

   Po = AllocVram (timimg.prect->w, timimg.prect->h, &VramHandle, 1);
   if (Po.x == -1)
      return;

   RECT shit5 = {Po.x, Po.y, timimg.prect->w, timimg.prect->h};
   LoadImage (&shit5, timimg.paddr);

   if ((tiscclut = AllocClut ()) == -1)
      return;
   else
      tiscclut += 480;

   RECT shit1 = {0,tiscclut, 256,1};
   if (timimg.crect)
      LoadImage (&shit1, (u_long *)timimg.caddr);

   DrawSync (0);

   while (~buttons & 1)
   {
      Control_Read (&trig, frgnd, -1, &buttons);

      int wo = (whichone % 15) / 5;
      int wo2 = (whichone2 % 15) / 5;

      spr = db->Get_Poly ();
      setUV4 (spr, spru[wo], sprv[wo],
                   spru[wo] + sprw[wo], sprv[wo],
                   spru[wo], sprv[wo] + sprh[wo],
                   spru[wo] + sprw[wo], sprv[wo] + sprh[wo]);
      spr->tpage = GetTPage (1, 0, Po.x, Po.y);
      setXY4 (spr, 0,120 - sprh[wo] / 2,
                   sprw[wo], 120 - sprh[wo] / 2,
                   0,120 + sprh[wo] / 2,
                   sprw[wo], 120 + sprh[wo] / 2);
      spr->clut = GetClut (0, tiscclut);
      db->Add_Poly (spr, 14);

      spr = db->Get_Poly ();
      setUV4 (spr, spru[wo2], sprv[wo2],
                   spru[wo2] + sprw[wo2], sprv[wo2],
                   spru[wo2], sprv[wo2] + sprh[wo2],
                   spru[wo2] + sprw[wo2], sprv[wo2] + sprh[wo2]);
      spr->tpage = GetTPage (1, 0, Po.x, Po.y);
      setXY4 (spr, 319,120 - sprh[wo2] / 2,
                   319 - sprw[wo2], 120 - sprh[wo2] / 2,
                   319,120 + sprh[wo2] / 2,
                   319 - sprw[wo2], 120 + sprh[wo2] / 2);
      spr->clut = GetClut (0, tiscclut);
      db->Add_Poly (spr, 14);

//      bkd.Draw (db, 0);

      whichone++;
      whichone2++;

      db->ClearDrawArea (0,255,0);
      db->Swap (debug);
   }

//   bkd.Clear ();
   FreeVram (VramHandle);
   FreeClut (tiscclut - 480);
}
