; h:=image2.Height div 16;
BitMapB.Height :=h;
BitMapB.Width :=w;
k:=0;
l:=0;
while not stop do
for i:=0 to 15 do
for j:=0 to 3 do
begin
if (i=15) and (i>0) then break;//如果是空帧就不画了
//保存桌面上指定区域的位图
//注意,由于飞行是在不同位置完成的,所以要保存即将被绘图的桌面区域
savebackground(BitMapB.canvas,w,h,k,l);
tranbit(DeskTopDC ,k,l,w,h,image2.Canvas.Handle,j*w,i*h,w,h,RGB(208,2,178));
sleep(10);
bitblt(DeskTopDC,k,l,w,h,BitMapB.Canvas.handle,0,0,srccopy);
if(k<x)then k:=k+1;
if(l<y)then l:=l+1;
if timer1.Enabled =false then
if(k>x-10)then//到达目的地就停止飞行,并引爆炸弹
begin
stop:=true;
timer1.Enabled :=true;//炸弹引爆器
end;
end;
finally
BitMapB.Free;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
x,y:integer;
begin
if(expnum = 0) then
begin
Explode(screen.width div 2-20,screen.Height div 2-20);
sndPlaySound(''''explosion.wav'''',SND_NOSTOP);
expnum:=expnum+1;
end
else if expnum<10 then//爆炸最多10次
begin
//产生随机位置
x:=Random(screen.Width-100);
y:=Random(Screen.Height-100);
Explode(x,y);//爆炸
sndPlaySound(''''explosion.wav'''',SND_NOSTOP);//播放爆炸声音
expnum:=expnum+1;
end
else
begin
stop:=true;
timer1.Enabled :=false;
close();
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DeskTopDC:=GetDC(0);
chdir(ExtractFilePath(application.ExeName));
stop:=false;
expnum:=0;
//飞行器开始飞行,目的地为屏幕中央
self.shipmove(screen.width div 2,screen.Height div 2);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
stop:=true;
Timer1.Enabled :=false;
ReleaseDC(0, DeskTopDC);
end;
end.
4.结束语
正如我们所希望的那样:一个飞行器飞入桌面,慢慢向屏幕中央靠近,当它到达目的地时就爆炸了,并引出一连串的爆炸。程序顺利地完成了我们的希望,但是程序还有许多不足,最好用directx来完成动画,这样效果可能会更好。如谁对其感兴趣的话,发E_MAIL给我,我们一起探讨。(E_MAIL:CODEHUNTER@SOHU.COM)
上一页 [1] [2] [3] [4] [5] 下一页 没有相关教程
|