Код
uses dos,crt,graph;
type
Coords = record
x,y:real;
end;
const
step = 50;
l = 100; {lenght}
h = 10; {height}
size = 5;
spd_ = 0.1;
k = 1;
var
pos,spd:Coords;
angle,gd,gm,i,x,y:integer;
procedure Draw(x,y,color:integer);
begin
SetColor(color);
Rectangle(x,y,x+l,y+h);
end;
procedure DrawBall(color:byte);
begin
SetColor(color);
Circle(trunc(pos.x),trunc(pos.y),size);
end;
procedure RecalcBall;
procedure ChX;
begin
pos.x := pos.x - spd.x * spd_;
spd.x := - spd.x * k;
end;
procedure ChY;
begin
pos.y := pos.y - spd.y * spd_;
spd.y := - spd.y * k;
end;
begin
DrawBall(black);
pos.x := pos.x + spd.x * spd_;
if (pos.x >= GetMaxX - size) or (pos.x <= size) then
ChX;
pos.y := pos.y + spd.y * spd_;
if (pos.y <= size) then
ChY;
if (pos.Y = GetMaxY-(size+h)) and (pos.X >= x) and (pos.X <= X+l) then
ChY;
if (pos.y >= GetMaxY) then
begin
pos.x := Random(640);
pos.y := Random(480)-10;
end;
DrawBall(white);
end;
var
scancod:word;
begin
gd := Detect;
InitGraph(gd,gm,'');
x := 0;
y := 469;
Draw(x,y,white);
spd.x := random(7) + 4;
spd.y := 10;
pos.x := GetMaxX div 2;
pos.y := GetMaxY div 2;
repeat
RecalcBall;
delay(500);
if port[$60]<$80 then
begin
scancod:=port[$60];
mem[0:$41C]:=mem[0:$41A];
case scancod of
77:begin{right}
Draw(x,y,black);
inc(x,step);
if x >= (GetMaxX - l) then
x := GetMaxX - l;
Draw(x,y,white);
end;
75:begin{left}
Draw(x,y,black);
dec(x,step);
if x <= 0 then
x := 0;
Draw(x,y,white);
end;
end;
port[$60]:=$80;
end;
if (scancod<>1) and (scancod<>0) then begin port[$60]:=$80; scancod:=0 end;
until scancod=1;
CloseGraph;
end.