[Delphi] Kolizje

0

Witam. Jak sprawdzić czy 2 komponenty TImage o kształcie prostokąta ze sobą kolidują?
Szukałem w gogle lecz nie ma [glowa] :-/ :-| Dziękuje za pomoc.

maciej-01 [diabel]

0

ok.. używać googla umiesz.. a mózgu? przecież to jest proste jak dwa plus dwa.. wystarczy ruszyć głową..

0
ybook napisał(a)

ok.. używać googla umiesz..

:| tez nie umie.
http://www.google.pl/search?&q=delphi+kolizje

0
var
l,p,g,d: boolean;
begin
if image1.Left+ image1.Width > image2.Left then l:= true else l:= false;
if image1.Left < image2.Left+ image2.Width then p:= true else l:= false;
if image1.Top+ image1.Height > image2.Top then g:= true else l:= false;
if image1.Top< image2.Top+ image2.Height then d:= true else l:= false;

if (l and p and g and d) then ShowMessage('kolizja');
end;
0
lankusiek napisał(a)
var
l,p,g,d: boolean;
begin
if image1.Left+ image1.Width > image2.Left then l:= true else l:= false;
if image1.Left < image2.Left+ image2.Width then p:= true else l:= false;
if image1.Top+ image1.Height > image2.Top then g:= true else l:= false;
if image1.Top< image2.Top+ image2.Height then d:= true else l:= false;

if (l and p and g and d) then ShowMessage('kolizja');
end;

Nie wnikając w merytoryczną poprawność i pomijając prawdopodobną literówkę przy else, funkcjonalnie równoważne, a lepsze, będzie:

begin
  if (image1.Left + image1.Width > image2.Left) and
     (image1.Left < image2.Left + image2.Width) and
     (image1.Top + image1.Height > image2.Top) and
     (image1.Top < image2.Top + image2.Height) then
    ShowMessage('kolizja');
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1