[Delphi] Problem z kolizjami.

0

cześć... piszę ten post po raz 2 i myślę że mi ktoś pomoże...
robie prostą gierke (arkanoid :-)) i napotkałem problem. Oto on :
mam na formie na dole panela, a u góry znajduje się 5 paneli. Chcę żeby po "zderzeniu" się shapa z którymś z tych 5 paneli, dany panel po prostu znikł. Chciałem to zrobić sam, ale w momencie gdy shape "zderzył" się z obojętnie jakim panelem znikały wszystkie.A ja chcę żeby zniknął ten panel na którego najechał shape. Tutaj mam kod którym się posługiwałem :
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (shape1.Top < klocek.width - shape1.Width)
and (shape1.Top < klocek.Width + shape1.Width)
and (shape1.Left < klocek.Left + klocek.Width)
then
klocek.Visible := false;
begin
if (shape1.Top < klocek1.width - shape1.Width)
and (shape1.Top < klocek1.Width + shape1.Width)
and (shape1.Left < klocek1.Left + klocek1.Width)
then
klocek1.Visible := false;
ktoś mi pomoże ?
z góry dzięki

0

k****, zapomniałem o znaczkach &lt i &gt

begin
if (shape.top = klocek.top + klocek.height) and
(shape.left &gt = klocek.left) and
(shape.left &lt = klocek.left + klocek.width) then
klocek.visible := true;
if (shape.top = klocek1.top + klocek1.height) and
(shape.left &gt = klocek1.left) and
(shape.left &lt = klocek1.left + klocek1.width) then
klocek1.visible := true;
...
end;

0

nie działa :-(...poza tym klocek visible powinienieś dać na false :-)

0

Założenie, że piłka jest mniejsza od klocka. W innym wypadku musisz dopasować warunki.

var
i: Integer;
begin
for i := 0 to ComponentCount-1 do
if Components[i] is TPanel then
if Visible then
if (Shape1.Top < (Components[i] as TPanel).Top + (Components[i] as TPanel).Height) and (Shape1.Left + Shape1.Width div 2 > (Components[i] as TPanel).Left) and (Shape1.Left + Shape1.Width div 2 < (Components[i] as TPanel).Left + (Components[i] as TPanel).Width) then
begin
(Components[i] as TPanel).Visible := False;
Break;
end;
end;

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