喂!孟田尾。
下面是我用一个星期搞的类,它能够自动生成,还有 moveto/setposition等功能。
如果要快速移动的话,只要改变sleep中的参数,而且还没有闪烁感。
给我分吧,thank you.
unit TcarUnit;
interface
uses
Windows,SysUtils,Classes,Graphics,dialogs,Controls,Forms,Extctrls;
Type
TCar=class(TBitmap)
private
FPos:TPoint;
FPortTime:integer;
Findex:integer;
//procedure cartimertimer(sender:Tobject);
published
property index:integer read findex write findex;
property Pos:Tpoint read Fpos write Fpos;
property PortTime:integer read FportTime write FPortTime;
Public
constructor Create;override;
Destructor Destroy;override;
procedure MoveTo( Form1:TForm;x,y:integer);
procedure SetPosition(Form1:Tform;x,y:integer);
end;
implementation
constructor TCar.Create ;
begin
inherited create;
pos:=point(10,100);
height:=20;
width:=20;
porttime:=100;
end;
destructor Tcar.Destroy ;
begin
inherited destroy;
end;
procedure TCar.MoveTo( Form1:Tform;x,y:integer);
var
m,n,i,dest:integer;
begin
dest:=trunc(sqrt(sqr(x-pos.x)+sqr(y-pos.y)));
sleep(20);
form1.canvas.draw(pos.x,pos.y,self);
for i:=1 to dest do
begin
m:=trunc(pos.x+i*(x-pos.x)/dest);
n:= trunc(pos.y+i*(y-pos.y)/dest);
sleep(5);
form1.canvas.draw(m,n,self);
form1.Canvas.Pen.Color :=form1.Color ;
with form1.canvas do
begin
if(pos.y<y)and(pos.x=x) then
begin
moveto(m,n-1);
lineto(m+width,n-1);
end;
if(pos.y>y)and(pos.x=x) then
begin
moveto(m,n+height+1);
lineto(m+width,n+height+1);
end;
if(pos.x<x)and (pos.y=y)then
begin
moveto(m-1,n);
lineto(m-1,n+height+1);
end;
if(pos.x>x)and(pos.y=y)then
begin
moveto(m+width,n);
lineto(m+width,n+height+1);
end;
if(pos.x>x)and(pos.y>y) then
begin
moveto(m,n+height);
lineto(m+width,n+height);
lineto(m+width,n);
end;
if(pos.x<x)and(pos.y<y) then
begin
moveto(m-1,n+height-1);
lineto(m-1,n-1);
lineto(m+width,n-1);
end;
if(pos.x<x)and(pos.y>y) then
begin
moveto(m,n);
lineto(m,n+height);
lineto(m+width,n+height);
end;
if(pos.x>x)and(pos.y<y) then
begin
moveto(m,n);
lineto(m+width,n);
lineto(m+width,n+height);
end;
end;
end;
form1.canvas.CopyMode :=cmsrccopy;
pos:=point(x,y);
end;
Procedure TCar.SetPosition (Form1:TForm;x,y:integer);
begin
form1.canvas.Brush.Color :=form1.color;
Form1.canvas.fillrec(rect(pos.x,pos.y,pos.x+width,pos.y+height));
pos:=point(x,y);
form1.canvas.draw(x,y,self);
end;
end.