Animasi 2 ball move
Sintak:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Shape1: TShape;
Shape2: TShape;
Button1: TButton;
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
atas, bawah, kiri, kanan, at, bu, kr, kn:integer;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
{shape1}
if (atas=1) then
shape1.top:=shape1.Top-1;
if (bawah=1) then
shape1.Top:=shape1.Top+1;
if (kanan=1) then
shape1.left:=shape1.Left+1;
if (kiri=1) then
shape1.Left:=shape1.Left-1;
if (shape1.left>390) then
begin
kiri:=1;
kanan:=0;
end;
if (shape1.left<=0) then
begin
kanan:=1;
kiri:=0;
end;
if (shape1.top<=0) then
begin
atas:=0;
bawah:=1;
end;
if (shape1.top>370) then
begin
atas:=1;
bawah:=0;
end;
{shape2}
if (at=1) then
shape2.Top:=shape2.Top-1;
if (bu=1) then
shape2.Top:=shape2.Top+1;
if (kn=1) then
shape2.Left:=shape2.Left+1;
if (kr=1) then
shape2.Left:=shape2.Left-1;
if (shape2.left>390) then
begin
kr:=1;
kn:=0;
end;
if (shape2.left<=0) then
begin
kn:=1;
kr:=0;
end;
if (shape2.top<=0) then
begin
at:=0;
bu:=1;
end;
if (shape2.top>370) then
begin
at:=1;
bu:=0;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
application.Terminate;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
timer1.Enabled:=true;
{shape1}
kanan:=1;bawah:=1;
{shape2}
kr:=1;at:=1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
application.terminate;
end;
end.
Tidak ada komentar:
Posting Komentar