this slowpoke moves

Animate Components

const  Speed = 2;
  
// 

procedure TForm1.FormCreate(Sender: TObject);
begin
  Self.DoubleBuffered := TRUE;
  RadioGroup1.DoubleBuffered := TRUE;

  Randomize;
  repeat
    vx := -Speed * Random(Speed +1);
    vy := -Speed * Random(Speed +1);
  until (vx <> 0) and (vy <> 0);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if (Shape1.Top > ClientHeight - Shape1.Height - 1) or (Shape1.Top < 1) then
    vy := vy * -1;

  if (Shape1.Left > ClientWidth - Shape1.Width - 1) or (Shape1.Left < 1) then
    vx := vx * -1;

  Shape1.Left := Shape1.Left + vx;
  Shape1.Top := Shape1.Top + vy;

  RadioGroup1.Left := RadioGroup1.Left - (vx * -1);
  RadioGroup1.Top := RadioGroup1.Top + (vy * -1);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate