Car

 
 

program car;

uses Types,QuickDraw,Events,MiscTool;


var

  x: integer;

  speed: integer;

  poly: handle;

  tick: longInt;

  r: rect;

 

{ Draw hills }

 

procedure drawHills;

begin

  setSolidPenPat(0);

 

  poly:=openPoly;

    moveTo(0,100);

    lineTo(106,50);

    lineTo(159,100);

    lineTo(212,50);

    lineTo(265,100);

    lineTo(318,50);

    lineTo(371,100);

    lineTo(0,100);

  closePoly;

 

  setSolidPenPat(10);

  paintPoly(poly); 

end;

 

{ Draw car }

 

procedure drawCar;

begin     

  setSolidPenPat(7);

  setRect(r,x,145,x+170,170);

  paintRect(r);

  setSolidPenPat(4);

  setRect(r,x+10,110,x+150,145);

  paintRect(r);

   

  setSolidPenPat(0);

  setRect(r,x+20,150,x+73,200);  

  paintOval(r);

  setRect(r,x+94,150,x+147,200);

  paintOval(r);

   

  setSolidPenPat(11);

  setRect(r,x+15,115,x+75,140);

  paintRect(r);

  setRect(r,x+85,115,x+145,140);

  paintRect(r);

end; 

 

begin

  x:=0;

  tick:=getTick;

  speed:=random mod 6+1;

 

  graphics(320);

  hideCursor;

  setSolidBackPat(0);

 

  { Draw the blue sky }

 

  setSolidPenPat(13);

  setRect(r,0,0,320,100);

  paintRect(r);

 

  drawHills;

 

  repeat

   

    { Draw road }

   

    setSolidPenPat(1);

    setRect(r,0,100,320,200);

    paintRect(r);

      

    { Move car }

       

    x:=x+speed;  

    drawCar;  

   

    repeat until getTick-tick > 5;

      tick:=getTick;

     

    if x > 320 then begin

      x:=0;

      speed:=random mod 6+1;

    end;


    if(x > 70)and(x < 90)then

      sysBeep;       

   

  until button(0);

end.

A car moving and horn.


It demonstrate the use of procedure, polygons, and complex object animation.