OK, das mit onPaint und Invalidate hab ich soweit hinbekommen, flackert jezz sogar viel weniger, aber erst auf ein Bitmap zu zeichnen bekomme ich noch nicht wirklich hin >.<
Und dann zu der Sache mit der Kollision, meinste das so?
Delphi-Quellcode:
//----------------------------------
//BALL BERECHNEN
//----------------------------------
procedure TForm1.Ball_berechnen;
begin
//Wand angestoßen?
if Ballposition.Y <= 0 then
Ballrichtung.Y := -Ballrichtung.Y;
if Ballposition.Y >= Hoehe then
Ballrichtung.Y := -Ballrichtung.Y;
//Spieler angestoßen?
if ((Ballposition.X <= Spielerposition[1].X + Spieler.Width) AND (Ballposition.Y + Ball.Height >= Spielerposition[1].Y) AND (Ballposition.Y <= Spielerposition[1].Y + Spieler.Height)) OR
((Ballposition.X + Ball.Width >= Spielerposition[2].X) AND (Ballposition.Y + Ball.Height >= Spielerposition[2].Y) AND (Ballposition.Y <= Spielerposition[2].Y + Spieler.Height)) then
Ballrichtung.X := -Ballrichtung.X;
//Gepunktet?
//Sp1
if Ballposition.X <= 0 then begin
Timer1.Enabled := False;
Button1.Enabled := True;
end;
//Sp2
if Ballposition.X + Ball.Width >= Breite then begin
Timer1.Enabled := False;
Button1.Enabled := True;
end;
if Ballposition.X < Spielerposition[1].X + Spieler.Width then
Ballposition.X := Spielerposition[1].X + Spieler.Width;
if Ballposition.X + Ball.Width> Spielerposition[2].X then
Ballposition.X := Spielerposition[2].X - Ball.Width;
if Ballposition.Y < 0 then
Ballposition.Y := 0;
if Ballposition.Y + Ball.Height > Hoehe then
Ballposition.Y := Hoehe - Ball.Height;
Ballposition := Point(Ballposition.X + Ballrichtung.X, Ballposition.Y + Ballrichtung.Y);
end;
//----------------------------------
Sorry dass ich das net so schnell versteh
Edit: Mir is grad aufgefallen dass da so noch einige Fehler drin sind, aber generell zu diesem Teil
Delphi-Quellcode:
if Ballposition.X < Spielerposition[1].X + Spieler.Width then
Ballposition.X := Spielerposition[1].X + Spieler.Width;
if Ballposition.X + Ball.Width> Spielerposition[2].X then
Ballposition.X := Spielerposition[2].X - Ball.Width;
if Ballposition.Y < 0 then
Ballposition.Y := 0;
if Ballposition.Y + Ball.Height > Hoehe then
Ballposition.Y := Hoehe - Ball.Height;
So meinst du das?
Und dann noch was

Kann man die Kollision nich irgendwie eleganter lösen??? Weil wenn ich hitnerher noch berechnen will, dass wenn der Ball weiter rechts aufprallt er beschleunigt/verlangsamt wird, dann verlier ich mich ja in endlosen IF-Bedigungen...
Hab schon die SuFu dazu benutzt und bin öfter auf so Wurzel und Quadrat Funktionen gestoßen, hab aber echt keinen Plan was ich damit anstellen soll =)