Uses Crt,Gif,ModeXLib,Sprites;

Const Sprite_Number=3;          {number of sprites used in the program}

Var Sprite:Array[1..Sprite_Number] of SpriteTyp;
                                {data records of sprites}
    i:Word;                     {counter}

Begin
  Init_ModeX;                   {enable Mode X}
  LoadGif('sprites');           {load image with the three sprites}
  GetSprite(62 +114*320,58,48,Sprite[1]);  {coordinates (62/114), width 58*48}
  GetSprite(133+114*320,58,48,Sprite[2]); {(133/114), 58*48}
  GetSprite(203+114*320,58,48,Sprite[3]); {(203/114), 58*48}
                                {load the three sprites}
  LoadGif('wallpape');          {load wallpaper}
  p13_2_ModeX(48000,16000);     {and copy to background page}
  With Sprite[1] do Begin       {coordinates and speeds}
    px:=160;py:=100;            {of all three spites to (random values)}
    sx:=1;sy:=2;
  End;
  With Sprite[2] do Begin
    px:=0;py:=0;
    sx:=1;sy:=-1;
  End;
  With Sprite[3] do Begin
    px:=250;py:=150;
    sx:=-2;sy:=-1;
  End;
  Repeat
    CopyScreen(vpage,48000);    {wallpaper to current page}
    For i:=1 to Sprite_Number do{run for all 3 sprites}
      With Sprite[i] do Begin
        Inc(px,sx); Inc(py,sy); {movement}
        If (px < -dtx div 2)    {at left or right border ? -> turn around}
          or (px > 320-dtx div 2) Then sx:=-sx;
        If (py < -dty div 2)    {at top or bottom border ? -> turn around}
          or (py > 200-dty div 2) Then sy:=-sy;
        PutSprite(vpage,px,py,Sprite[i]);
                                {draw sprite}
      End;
    switch;                     {switch to calculated page}
    WaitRetrace;                {only after next retrace can screen}
  Until KeyPressed;             {be changed again}
  ReadLn;
  TextMode(3);
End.
