unit Tabletest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 =
class(TForm)
Timer1: TTimer;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Shape1: TShape;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
vx, vy: Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
vx := -10 + Random(20);
vy := -10 + Random(20);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Shape1.Left := Shape1.Left + vx;
Shape1.Top := Shape1.Top + vy;
if (Shape1.Left > ClientWidth - Shape1.Width - 1)
or (Shape1.Left < 1)
then
vx := vx * -1;
{if (Shape1.Top > ClientHeight - Shape1.Height - 1) or (Shape1.Top < 1) then
vy := vy * -1;} //Hier prallt der Ball oben und unten ab
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
case Key
of
VK_LEFT:
begin
Panel2.Left := Panel2.Left - 5;
Key := 0;
end;
VK_RIGHT:
begin
Panel2.Left := Panel2.Left + 5;
Key := 0;
end;
end;
end;
end.