unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ComCtrls,
Vcl.StdCtrls,
Vcl.ExtCtrls,
Vcl.ExtDlgs,
Vcl.Imaging.pngimage;
type
TForm1 =
class(TForm)
Button1: TButton;
TrackBar1: TTrackBar;
Button2: TButton;
OpenPictureDialog1: TOpenPictureDialog;
Timer1: TTimer;
Image1: TImage;
Panel1: TPanel;
procedure TrackBar1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
vx: Integer = 1;
i: Integer = 0;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.DoubleBuffered := True;
Timer1.Enabled := true;
end;
function IsCollision (Rect1, Rect2: TRect): Boolean;
begin
Result := (Rect1.Right > Rect2.Left)
and
(Rect2.Right > Rect1.Left)
and
(Rect1.Bottom > Rect2.Top)
and
(Rect2.Bottom > Rect1.Top);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Image1.Left := Image1.Left + vx;
if Image1.Left > ClientWidth - Image1.Width - 1
then
vx := vx * -1;
if Image1.Left < 1
then
vx := vx * -1;
if IsCollision(Image1.BoundsRect, Panel1.BoundsRect)
then
If i = 0
then
begin
i := i+1;
Timer1.Enabled := false;
ShowMessage('
TORR!!!11');
Panel1.SendToBack;
end
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Image1.Width := 30 * Trackbar1.Position;
Image1.Height := 30 * Trackbar1.Position;
end;
end.