procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin Shape2.Top := MyMouse.CursorPos.y-Form1.top- 25-Shape2.Height div 2; Shape2.Left:= MyMouse.CursorPos.x-Form1.left- 8-Shape2.Width div 2; if (sqr(2*Shape1.Top + Shape1.Height - 2*Shape2.Top - Shape2.Height) + sqr(2*Shape1.Left + Shape1.Width - 2*Shape2.Left - Shape2.Width)) < sqr( Shape1.Width+ Shape2.Width) then begin Shape1.Top := random(Form1.Height - Shape1.Height); Shape1.Left:= random(Form1.Width - Shape1.Width); end; end;