unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
Ttest = class(TObject)
private
Auge1top : Integer;
Auge1left : Integer;
Auge2top : Integer;
Auge2left : Integer;
//Nasetop : Integer;
//Naseleft : Integer;
//Mundtop : Integer;
//Mundleft : Integer;
Start : Boolean;
procedure Berechne();
public
end;
TForm1 = class(TForm)
Shape1: TShape;
Auge2: TShape;
Auge1: TShape;
Shape4: TShape;
Shape5: TShape;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure OnClose(Sender: TObject; var Action: TCloseAction);
procedure Timer1Timer(Sender: TObject);
procedure OnKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private-Deklarationen }
test : Ttest;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Test : Ttest;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
test.Create;
test.Berechne();
test.Start:= false;
end;
procedure TForm1.OnClose(Sender: TObject; var Action: TCloseAction);
begin
Test.Free;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Auge1.Top := Shape1.Top + Test.Auge1top;
Auge1.Left := Shape1.Left - Test.Auge1left;
Auge2.Top := Shape1.Top + Test.Auge2top;
Auge2.Left := Shape1.Left + Test.Auge2left;
end;
procedure TForm1.OnKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if test.Start=true then
begin
if key = VK_UP then
begin
shape1.Top := shape1.Top - 16;
end;
if key = VK_DOWN then
begin
shape1.Top := shape1.Top + 16;
end;
if key = VK_LEFT then
begin
shape1.Left := shape1.Left - 16;
end;
if key = VK_RIGHT then
begin
shape1.Left := shape1.Left +16;
end;
end;
end;
procedure TTest.Berechne();
begin
Auge1top := Form1.Auge1.Top - Form1.Shape1.Top;
Auge1left := Form1.Shape1.Left- Form1.Auge1.Left;
Auge2top := Form1.Auge2.Top - Form1.Shape1.Top;
Auge2left := Form1.Auge2.Left - Form1.Shape1.Left;
form1.Timer1.Enabled := true;
start :=true;
end;
end.