Registriert seit: 25. Mai 2009
322 Beiträge
Turbo Delphi für Win32
|
AW: Kollision mit Reflektion - Ich raffs net...
11. Feb 2011, 20:42
...solangsam gehn mir die Ideen aus... jetz funktionierts nix mehr ^^
Delphi-Quellcode:
procedure TFormMain.MoveBall(pCollisionObject: array of TPanel);
var tempObject,CollisionRect: TRect;
I,J,a,b,c,d: Integer;
begin
sball.left:=sball.left+XCor;
Ball.Left:=SBall.Left;
Ball.Right:=SBall.Left+SBall.Width;
if sball.left < (PLinks.Left+PLinks.Width) then
begin
sball.left := (PLinks.Left+PLinks.Width);
Xcor := -Xcor;
end;
if sball.left > PRechts.Left - sball.width then
begin
sball.left := (PRechts.Left - sball.width);
XCor := -XCor;
end;
for J := 0 to SBall.Width - 1 do
begin
tempObject.Left:=pCollisionObject[J].Left;
tempObject.Right:=pCollisionObject[J].Left+pCollisionObject[J].Width;
tempObject.Top:=pCollisionObject[J].Top;
tempObject.Bottom:=pCollisionObject[J].Top+pCollisionObject[J].Height;
if InterSectRect(CollisionRect,Ball,tempObject) then
begin
if not (pCollisionObject[J]=nil) then
begin
if (sball.Left < (pCollisionObject[J].Left+pCollisionObject[J].Width)) then
begin
XCor := -XCor;
pCollisionObject[J]:=nil;
end;
if ((sball.Left+sball.Width)>pCollisionObject[J].Left) then
begin
XCor:= -XCor;
pCollisionObject[J]:=nil;
end;
end;
end;
end;
sball.top := sball.top+YCor;
Ball.Top:=SBall.Top;
Ball.Bottom:=SBall.Top+SBall.Height;
if sball.top < (POben.Top+POben.Height) then
begin
sball.Top := (POben.Top+POben.Height);
YCor := -YCor;
end;
if sball.top > (self.height - sball.height) then
begin
sball.top := (self.height - sball.height);
YCor := -YCor;
end;
if IntersectRect(Collision,Ball,Stick) then
begin
sball.top := (PStick.top - sball.height);
YCor:= -YCor;
XCor:= XCor-1;
end;
if Sball.Top > PStick.Top then
begin
SBall.Visible:=False;
TMover.Enabled:=False;
MessageDLG('Game Over!',mtWarning,[mbOk],0);
SpawnBall;
end;
for I := 0 to SBall.Height - 1 do
begin
tempObject.Left:=pCollisionObject[I].Left;
tempObject.Right:=pCollisionObject[I].Left+pCollisionObject[I].Width;
tempObject.Top:=pCollisionObject[I].Top;
tempObject.Bottom:=pCollisionObject[I].Top+pCollisionObject[I].Height;
if InterSectRect(CollisionRect,Ball,tempObject) then
begin
if not (pCollisionObject[I]=nil) then
begin
if (sball.Top < (pCollisionObject[I].Top+pCollisionObject[I].Height)) then
begin
YCor := -YCor;
pCollisionObject[I]:=nil;
end;
if ((sball.Top+sball.Height)>pCollisionObject[I].Top) then
begin
YCor:= -YCor;
pCollisionObject[I]:=nil;
end;
end;
end;
end;
end;
|
|
|