unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, math;
type
TForm1 =
class(TForm)
Shape1: TShape;
Button1: TButton;
Timer1: TTimer;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
x, y: Integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.enabled := true;
x := 5;
//Startwerte für X&Y-Speed
y := 3;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
//Kollissionstests
if (shape1.Top < 0)
or (shape1.Top > clientheight - shape1.Height)
then
y := -y;
if (shape1.Left < 0)
or (shape1.Left > clientwidth - shape1.width)
then
x := -x;
//eigentliche bewegung
shape1.Top := shape1.Top + y;
shape1.Left := shape1.Left + x;
form1.caption := floattostr(sqrt(x*x+y*Y))
//pythagoras(schreibt man den so?) hilft weiter
end;
end.