unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 =
class(TForm)
Ball: TShape;
Timer1: TTimer;
player1: TShape;
player2: TShape;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
xspeed,yspeed,vx,vy,xpos,ypos: integer;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
ypos:= 0;
xpos:= 0;
ball.left:= xpos;
ball.top:= ypos;
xspeed:= -1;
yspeed:= 1;
vx:= 5;
vy:= 5;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var toleranz,schritt: integer;
begin
xpos:= xpos+xspeed*vx;
ypos:= ypos+yspeed*vy;
if (xpos<0)
then begin
xspeed:= 1;
xpos:= 0;
end;
if (xpos+ball.width>=form1.ClientWidth)
then begin
xspeed:= -1;
xpos:= form1.clientwidth-ball.width;
end;
if (ypos<0)
then begin
yspeed:= 1;
ypos:= 0;
end;
if (ypos+ball.height>=form1.Clientheight)
then begin
yspeed:= -1;
ypos:= form1.clientheight-ball.height;
end;
ball.top:= ypos;
ball.left:= xpos;
end;
end.