unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TeEngine, ExtCtrls, TeeProcs, Chart;
const
WM_KILL=WM_User + 123;
type
TSchuss=Class(TShape)
public
Procedure NextStep(CollCheck:TShape);
Constructor Create(AOwner:TComponent;aParent:TWinControl;x,y:Integer);
Overload;
End;
TForm2 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
CircleCursor: TShape;
Player: TShape;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
private
{ Private-Deklarationen }
Procedure WMKILL(
var MSG:TMessage);
message WM_KILL;
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
TSchuss.Create(self,self,Player.left,Player.Top);
Caption := DateTimeToStr(now);
end;
procedure TForm2.Timer1Timer(Sender: TObject);
var p: TPoint;
i:Integer;
begin
p := Mouse.CursorPos;
p := ScreenToClient(p);
Label1.Caption := IntToStr(p.X);
Label2.Caption := IntToStr(p.Y);
CircleCursor.Left := P.X;
CircleCursor.Top := P.Y;
if p.X < (Player.Left + round(Player.Width/2))
then
begin
Player.Left := Player.Left - 2;
end;
if p.X > (Player.Left + round(Player.Width/2))
then
begin
Player.Left := Player.Left + 2;
end;
for I := 0
to ControlCount - 1
do
if Controls[i]
is TSchuss
then
TSchuss(Controls[i]).NextStep(CircleCursor);
end;
procedure TForm2.WMKILL(
var MSG: TMessage);
begin
TObject(MSG.WParam).Free;
end;
{ TSchuss }
constructor TSchuss.Create(AOwner:TComponent;aParent:TWinControl;x,y:Integer);
begin
inherited Create(Aowner);
Parent := aParent;
Width := 10;
Height := 10;
Brush.Color := clBlack;
Left := x;
Top := y;
end;
procedure TSchuss.NextStep(CollCheck:TShape);
var
hit:Boolean;
r:TRect;
begin
Top := Top - 5;
hit := InterSectRect(r,BoundsRect,CollCheck.BoundsRect);
if hit
or (Top+Height < 0)
then PostMessage(Parent.handle,WM_KILL,Integer(self),0);
if Hit
then CollCheck.Brush.Color := clRed;
end;
end.