unit LaufenUnit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 =
class(TForm)
Shape1: TShape;
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
var absu,absl,absr,abso: integer;
begin
//beim rand anstoßen
abso:= shape1.top;
absu:= form1.clientheight-(shape1.top+shape1.height);
absl:= shape1.left;
absr:= form1.clientwidth-(shape1.left+shape1.width);
if (abso>10)
then abso:= 10;
if (absu>10)
then absu:= 10;
if (absl>10)
then absl:= 10;
if (absr>10)
then absr:= 10;
//bewegung des balles
if (key=38)
then shape1.top:= shape1.top-abso;
if (key=40)
then shape1.top:= shape1.top+absu;
if (key=37)
then shape1.left:= shape1.left-absl;
if (key=39)
then shape1.left:= shape1.left+absr;
end;
end.