Code: Alles auswählen
procedure TForm1.tmrMoveBallTimer(Sender: TObject); {Selbstbewegung des Balles durch Timer/
Richtungsänderung}
//...
LXChange:= trunc(cos(Pi / 180 * FDirection) * FSpeed);
LYChange:= trunc(sin(Pi / 180 * FDirection) * FSpeed);
DrawBall(FBallX + LXChange, FBallY + LYChange);
if (FBallX <= 0) or (FBallX >= ClientWidth - CBallSize) then
FDirection:= FDirection + (90 - FDirection) * 2
else if (FBallY <= 0) or (FBallY >= ClientHeight - CBallSize) then
FDirection:= FDirection + (180 - FDirection) * 2;
// FDirection:= FDirection * -1;
end;
Ohne Beachtung des Winkels muss es etwa so aussehen:
Code: Alles auswählen
BallX:= BallX + (BallGeschwindigkeit * BallXRichtung);
BallY:= BallY + (BallGeschwindigkeit * BallYRichtung);
if (BallX<0) or (BallY>RechteRand) then BallXRichtung:= BallXRichtung * -1; // durch *-1 wird immer richtung geändert
if (BallY<0) or (BallY>UntereRand) then BallYRichtung:= BallYRichtung * -1;