|
Постоянный
Регистрация: 17.07.2005
Сообщений: 475
Провел на форуме: 1665310
Репутация:
488
|
|
Так, как я уже писал, остается вычислить соприкасается ли Удав и точка...
Чтобы мне сравнить координаты точки(он же зайчек) и удава, мне нужно чтобы ф-я возвращала в программу параметры? Правильно я написал? Что-то нет у меня радостного сообщения на экране " congrats!"
Код:
uses crt,graph;
var vx,vy,q,p,err,det,dm,x1,y1,x2,y2,i,a:integer;
function point(k,l:integer):integer;
begin
putpixel(k,l,2);
delay(9000);
putpixel(k,l,0);
end;
procedure lie(var c,d,e,f:integer);
begin
for i:=c to d do
begin
delay(1000);
setcolor(5);
LineTo(i,d);
delay(500);
setcolor(15);
LineTo(i+5,d);
end;
for i:=d to f do
begin
delay(1000);
setcolor(5);
LineTo(e,i);
delay(500);
setcolor(15);
LineTo(e,i+5);
end;
for i:=e downto c do
begin
delay(1000);
setcolor(5);
LineTo(i,f);
delay(500);
setcolor(15);
LineTo(i-5,f);
end;
for i:=f downto d do
begin
delay(1000);
setcolor(5);
LineTo(c,i);
delay(500);
setcolor(15);
LineTo(c,i-5);
end;
end;
begin
det:=detect;
initgraph(det,dm,'e:\bp\bgi\');
err:=graphresult;
if err<>grOk then writeln(grapherrormsg(err));
readln(x1,y1,x2,y2,a);
rectangle(x1,y1,x2,y2);
{вычисление приращений для отскока}
p:=x1; vx:=round(sin(a)+3);
q:=y1; vy:=round(cos(a)+3);
repeat
if ((p+vx)<=x2) and ((p+vx)>=x1) then p:=p+vx else if vx>=0 then vx:=-3 else vx:=+3;
if ((q+vy)<=y2) and ((q+vy)>=y1) then q:=q+vy else if vy>=0 then vy:=-3 else vy:=+3;
point(p,q);
lie(x1,y1,x2,y2);
if ( (p=x1) or (p=x2) ) and ( (q=y1) or (q=y2) ) then
begin
setcolor(10);
settextstyle(3,0,8);
outtextxy(150,200,'CONGRATS! Udav fucked the rabbit! ');
end;
until keypressed;
readkey;
closegraph;
end.
|