procedure TForm1.FormDestroy(Sender: TObject); begin CardMap.Free ;//清除位图 end;
procedure TForm1.Timer1Timer(Sender: TObject); {var Bitmap:Tbitmap;} begin if (BmpP.Y<=Height) and down then begin BmpP.Y:=BmpP.Y+i; inc(i); end; if (BmpP.Y+77)>=Height-20 then //-20防止速度过快多增加20像素 begin down:=false; dec(i,5); //降低高度,出现负数可以反弹 end; if down=false then begin BmpP.Y:=BmpP.Y-i; dec(i) end;//每次高度才不一致 if i<=1 then down:=true;
if lft=1 then BmpP.X:=BmpP.X-j //左移 else BmpP.X:=BmpP.X+j; //右移
{Bitmap:=TBitmap.Create; Bitmap.Width:=57; Bitmap.Height:=77; Bitmap.Canvas.CopyRect();} Canvas.CopyRect(Rect(BmpP.X,BmpP.Y,BmpP.X+57,BmpP.Y+77),CardMap.Canvas,Rect(x,y,x+57,y+77)); //Image1.Picture.Bitmap:=TmpMap; if (BmpP.X>=Width) or (BmpP.X+57<0) then reset; //超出范围重置 end;
procedure TForm1.reset; var position:integer; begin randomize; position:=random(4); //任意四个位置 lft:=random(2); //任意移向 CardId:=random(54); //任意牌 x:=(CardId shr 2)*57; //该扑克牌在位图中横坐标的位置 y:=(CardId and 3)*77; //该扑克牌在位图中纵坐标的位置 i:=random(14)+2; j:=2+random(5); //横向速度 down:=False; BmpP.Y:=20; case position of 0: BmpP.X:=270; 1: BmpP.X:=358; 2: BmpP.X:=446; 3: BmpP.X:=554; end;