{$X+}

Uses Crt , Graph;

Const
     g = 1;
     l = 40;
   Col = White;

 Alpha : Extended = Pi / 4 ;
  Step : Extended = Pi /18 ;
  Vel0 : Extended = 10;
  VelX : Extended = 0;
  VelY : Extended = 0;
     X : Extended = 0;
     Y : Extended = 0;

Function Trans(a:Integer):string;
Var
  s:string;
Begin
  Str(a, S); Trans := s;
End;
Procedure SetGraph;

 Var
  Driver , Mode : Integer;
         Result : ShortInt;
 Begin
  DetectGraph ( Driver , Mode );
   InitGraph ( Driver , Mode , 'D:\TP\BGI' );
  Result := GraphResult;
   If Result <> GrOK then
        begin
         WriteLn ( ' Warning ! Graphic error number  ', Result ,' ,' );
         WriteLn ( ' ' , GraphErrorMsg ( Result ) , '! ');
         Halt ( 0 );
        end;
 End;

Procedure DrawGun ( Color : Integer );
 Begin
   SetFillStyle ( 1 , Color );
   MoveTo ( 0 , GetMaxY );
   Bar ( 0 , GetMaxY , l div 4 , GetMaxY - l div 4 );
   SetColor ( Color );
  LineRel ( Round( 1.2 * l * cos ( Alpha ) ), - Round ( 1.2 * l * sin ( Alpha ) ) );
 End;

Procedure Shoot;
 Begin
  Y := GetMaxY;
   VelX := Vel0 * Cos ( Alpha );
   VelY := Vel0 * Sin ( Alpha );
  Repeat
   VelX := VelX;
   VelY := VelY - g ;
      X := X + VelX;
      Y := Y - VelY;
    PutPixel ( Round ( X ) , Round ( Y ) , Col );
   Until False;
  End;


Procedure Control;
  Var Ch : Char;
 Begin
  SetLineStyle ( SolidLn , 0 , ThickWidth );
   Randomize;
  Repeat
   Ch := ReadKey;
   ClearDevice;
    If Ch = #27 then Halt;
    If Ch = #72 then Alpha := Alpha + Step / 10;
    If Ch = #80 then Alpha := Alpha - Step / 10;
    If Ch = #75 then Alpha := Alpha + Step;
    If Ch = #77 then Alpha := Alpha - Step;
    If Alpha > Pi / 2 then Alpha := Pi / 2;
    If Alpha < 0 then Alpha := 0;
    If Ch = #32 then Shoot;
   DrawGun ( Col );
    OutTextXY ( 0 , 0 , 'Alpha = ' + Trans ( Round ( 180*alpha/pi) ));
  Until False;
 End;

 Begin
  SetGraph;
  OutTextXY ( 0 , 0 , 'Alpha = ' + Trans ( Round ( 180*alpha/pi) ));
   DrawGun ( Col );
  Control;
 End.
