
    (* ************************************************************** *)
    (*                                                                *)
    (*                        SpriteDemo6.Pas                         *)
    (*                                                                *)
    (*   This program shows how to use sprites for multiple page      *)
    (*   animation. The basic strategy is to use three pages:         *)
    (*   the colorscreen, a hidden workbuffer which is a identical    *)
    (*   and may be written to unseen, and a third buffer which is    *)
    (*   the part of the scene that does not change. One creates      *)
    (*   the background and stores it both in backgroundbuffer and    *)
    (*   in the workbuffer. Next, one writes to the workbuffer        *)
    (*   ( that is, draws the sprites ).  Next the workbuffer is      *)
    (*   displayed by transferring it to the colorscreen. Then one    *)
    (*   erases the workbuffer by transferring the backgroundbuffer   *)
    (*   to it. The now blank workscreen can again be modified,       *)
    (*   displayed, and erased again ... and again ... and ...        *)
    (*                                                                *)
    (*   The workbuffer and the backgroundbuffer each use 16K of      *)
    (*   your data segment ( 32K out of your total of 64K ). You can  *)
    (*   easily reduce this to 16K if after writing the background-   *)
    (*   buffer you store it in the heapspace rather than in the      *)
    (*   the data segment. However, in this small program it is not   *)
    (*   necessary.                                                   *)
    (*                                                                *)
    (*   These techniques are similar to those of Demo1, but the      *)
    (*   present example is more complicated.                         *)
    (*                                                                *)
    (*                            (c) Donald L. Pavia                 *)
    (*        Ver 2.0             Department of Chemistry             *)
    (*                            Western Washington University       *)
    (*                            Bellingham, Washington  98225       *)
    (*                                         January 25, 1986       *)
    (*                                                                *)
    (* ************************************************************** *)

program SpriteDemo6;

{----------------------------------------------------------------------------}
{$I Sprites.Lib}
{----------------------------------------------------------------------------}

const SoundOn : boolean = true;

var   k,l : integer;

{----------------------------------------------------------------------------}
procedure Introduction;

begin
     TextColor (3);
     gotoxy (2,5); write ('TURBO PASCAL');
     TextColor (1);
     gotoxy (7,7); write ('SPRITE DESIGNER');
     TextColor (3);
     gotoxy (12,9); write ('AND');
     TextColor (1); write (' ANIMATION PACKAGE ');
     TextColor (3); write ('DEMO');
     gotoxy (1,21); write ('Action Continues Until a KeyPress');
     gotoxy (1,23); write ('Donald Pavia, December 1985');
     gotoxy (29,17); TextColor (2);
     gotoxy (25,17); write ('Press <Enter>');
     TextColor (3);
     read (kbd,Wait);

end; { procedure Introduction }
{----------------------------------------------------------------------------}

BEGIN
     clrscr;
     GraphColorMode; GraphBackGround (1); Palette (2);

     WorkBuffer := ColorBuffer;     { copy blank screen into workbuffer }

     LoadTable ('DEMO1.TAB');       { load the table of sprites }

     Introduction;

REPEAT
        {----- Create BackGround Screen and Display ------------------}

         for times := 1 to 14 do
            begin                { XorSpriteW writes to hidden workbuffer }
                                 { - row of 14 dwarf sprites is created   }

              Sprite := Table[ 9];            { Dwarf1 - upper body }
              XorSpriteW (20 * times,90);

              Sprite := Table[17];            { Dwarf2 - lower body }
              XorSpriteW (20 * times,110);

            end;

     ColorBuffer := WorkBuffer;              { display workbuffer }

     BackGroundBuffer := WorkBuffer;   { copy workbuffer into background  }
                                       { to use for refresh of workbuffer }
        {------------------------------------------------------------}

  Repeat
     count := 8;

     (* ******* REPEAT LOOP ONE ************************************* *)

     repeat

        {-- Display Cycle One ----------------------------------------}
                                     { write to blank workbuffer }
         count := count + 8;

         Sprite := Table[12]; XorSpriteW (220,20);         {Dragon}

         Sprite := Table[2];                               {Dog1}
         if count < 307 then XorSpriteW (count,153);

         Sprite := Table[5];                               {Duck1}
         if count < 300 then XorSpriteW (count+8,141);

         Sprite := Table[20];                              {Boy1}
         if (count >48) and (count < 204) then XorSpriteW (count-40,140);

         Sprite := Table[20];                              {Boy1}
         if count >= 204 then XorSpriteW (164,140);

         ColorBuffer := WorkBuffer;           { display workbuffer }
         WorkBuffer := BackGroundBuffer;      { erase workbuffer   }

        {-- Display Cycle Two ----------------------------------------}
                                       { write to blank workbuffer }
         count := count + 8;

         Sprite := Table[13]; XorSpriteW (220,20);         {Dragon2}

         Sprite := Table[3];                               {Dog2}
         if count < 307 then XorSpriteW (count,153);

         Sprite := Table[6];                               {Duck2}
         if count < 300 then XorSpriteW (count+16,136);

         Sprite := Table[21];                              {Boy2}
         if (count > 56) and (count < 212) then XorSpriteW (count-40,140);

         Sprite := Table[20];                              {Boy1}
         if (count > 212) then XorSpriteW (164,140);

         ColorBuffer := WorkBuffer;           { display workbuffer }
         WorkBuffer := BackGroundBuffer;      { erase workbuffer   }

        {-------------------------------------------------------------}
                                       { naive attempt at dog bark }
         if SoundOn then begin
           if ((count > 32) and (count < 128))
            or (count > 210) then   begin
           Sound ( 40); delay (10);   Sound (120); delay (20);
           Sound (400); delay (15);   Sound (880); delay (20);
           Sound (1600); NoSound;   end;   end;
        {-------------------------------------------------------------}

     until count >= 340;

     (* ******* END LOOP ONE ****************************************** *)

     count := 4;

     (* ******** REPEAT LOOP TWO ************************************* *)

     repeat
        {-- Display Cycle Three --------------------------------------}
                                         { write to hidden workbuffer }
         count := count + 8;

         Sprite := Table[12]; XorSpriteW (220,20);         {Dragon}

         Sprite := Table[23];  XorSpriteW (244,20);        {Blast}

         Sprite := Table[2];                               {Dog1}
         if count < 307 then XorSpriteW (count,153);

         Sprite := Table[5];                               {Duck1}
         if count < 300 then XorSpriteW (count+8,141);

         Sprite := Table[22];                              {Boy3}
         if count < 180 then XorSpriteW (164,140);

         if (count >= 180) and (count < 204) then begin
                Sprite := Table[20];                       {Boy1}
                XorSpriteW (164,140); end;

         Sprite := Table[20];                              {Boy1}
         if count >= 204 then XorSpriteW (count-40,140);

         ColorBuffer := WorkBuffer;             { display workbuffer }
         WorkBuffer := BackGroundBuffer;        { erase workbuffer   }

        {-- Display Cycle Four ---------------------------------------}
                                         { write to hidden workbuffer }
         count := count + 8;

         Sprite := Table[13]; XorSpriteW (220,20);         {Dragon2}

         Sprite := Table[3];                               {Dog2}
         if count < 307 then XorSpriteW (count,153);

         Sprite := Table[6];                               {Duck2}
         if count < 300 then XorSpriteW (count+16,136);

         Sprite := Table[22];                              {Boy3}
         if (count < 188) then XorSpriteW (164,140);

         if (count >= 188) and (count < 212) then begin
                 Sprite := Table[20];                      {Boy1}
                 XorSpriteW (164,140); end;

         Sprite := Table[21];                              {Boy2}
         if count >= 212 then XorSpriteW (count-40,140);

         ColorBuffer := WorkBuffer;           { display workbuffer }
         WorkBuffer := BackGroundBuffer;      { erase workbuffer   }

    {--------------------------------------------------------------}
                                     { barking again }
         if SoundOn then begin
           if ((count > 32) and (count < 128))
            or (count > 210) then   begin
           Sound ( 40); delay (10);   Sound (120); delay (20);
           Sound (400); delay (15);   Sound (880); delay (20);
           Sound (1600); NoSound;   end;   end;
    {-------------------------------------------------------------}

     until count >= 340;

    (* ******** END LOOP TWO ************************************* *)

   Until keypressed;

   {---------------------------------------------------------------------}
     FIllChar (ColorBuffer,16192,0);             { erase everything }
     FillChar (WorkBuffer,16192,0);              { clrscr doesn't   }
     FillChar (BackGroundBuffer,16192,0);        { work in graphics }

     gotoxy (10,10); write ('Repeat Again ? Y/N ?  ');
       repeat
          read (Kbd,Again);
       until UpCase(Again) in ['Y','N'];

     FillChar (WorkBuffer,16383,0);
   {---------------------------------------------------------------------}

UNTIL UpCase(Again) = 'N';

      gotoxy (1,23);
      TextMode (c80); clrscr;                     { exit gracefully }

END.
