program tanim;
uses usebios, clock, queue, mcobj, animator, coproc, proc_man;
type
  ballp = ^ ball;
  ball = object (procdescr)
     drawer : animationObj;
     procedure lifecycle; virtual;
     procedure calc(VAR p:position);
  end;

  truck = object(animationObj)
     procedure draw; virtual;
     procedure erase;virtual;
  end;

var
  soccer : ballp;
  QQ : FifoQueue;
  QA : QueueAnimator;
  coin: randomdraw;
  rig : truck;
  {-----------------------------}
  procedure ball.lifecycle;
  const slice = 0.5;
  var
      dummy : elementptr;
  begin
     drawer.init(1,1);  {throw from upper left}
     while true do
       begin
        Sleep_for (slice);
        calc (drawer.new);
        if coin.draw then      {simulate a queue}
           begin
             new (dummy, init);
             QQ.Tail_insert(dummy);
           end
        else
         If not qq.isempty then
           begin
             dummy := QQ.get;
             dispose (dummy, destroy);
           end;
         rig.new.x := rig.new.x - 0.3;   {move the truck left}
       end;
  end ; {ball.lifecycle}

  procedure ball.calc (VAR p:position);
  begin
     with p do begin
        x:= 0.5 + time*0.75;          {const. velocity}
        y := sqr(time/15)+0.5;  {falling}
        if y > 24 then  y:=24;  {stick to ground and roll}
     end;
  end;

procedure truck.draw;
begin
    gotoXY (round(new.x), round(new.y));
      write('ÜÛÛÛÛÛÛ');
    gotoXY (round(new.x), round(new.y)+1);
      write('ø    øø');
end;

procedure truck.erase;
begin
    gotoXY (round(old.x), round(old.y));
      write('       ');
    gotoXY (round(old.x), round(old.y)+1);
      write('       ');
end;

begin
{   write ('Time slice (<60 sec): '); readln (slice); }
   new (soccer, init('Soccer Ball',1));
   resume (soccer);
    QQ.init;
    QA.init (1,22,10,QQ);
    coin.init (76431,0.55);
    rig.init (72,20);
   AnimationMonitor.RunAnimatedSimulation (100.0, 4444, 1.0, 0.1);
end.

