?? tank.pas
字號:
Canvas.Draw(176,128,BitmapGameover);
sleep(2000);
//調用游戲結束聲音
sndPlaySound( 'Gameover.wav', SND_ASYNC);
//Mainform.Font.Color:=clBlue;
//Mainform.Font.Size:=32;
//Mainform.Font.Name:='華文行楷';
//Canvas.TextOut(100,100,'坦克你真是個天才');
end;
end;
end;
end;
{Procedure TMainForm.SetValue(Etank:array of Byte);
begin
//管理新出現的敵方坦克
//如果檢測到游戲開始標志則進行賦值
// if gsPlaying:=true then
// Begin
// end;
end;
}
//此函數處理敵方坦克坐標和方向
Procedure TMainForm.Etanks(Var Etank:TPatDt);
// var
// Cn:Byte;
begin
//用黑色背景先把敵方坦克原來位置覆蓋掉,敵方坦克然后再改變坐標
Rect_L:=Rect(0,0,32,32);
Rect_M:=Rect(Etank.Xpos,Etank.Ypos,Etank.Xpos+32,Etank.Ypos+32);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
//把隨即數打亂
Randomize;
//定義敵人坦克改變方向行駛的概率
//Cn:=Random(100);
if Random(100)<5 then
begin
Etank.Smov := Random(4);
end;
//如果敵方坦克移動方向為右(0=右;1=左;2=下:3=上)
// if (Chpon.Xpos<220 )or(Chpon.Xpos>356)or(Chpon.Ypos<356)
//then begin
if Etank.Smov=0 then
begin
//把向右的敵方坦克對應的畫面顯示出來
Etank.Sban:=11;
Etank.Xpos := Etank.Xpos + 4;
//碰到軍旗周圍的磚頭
if (Etank.Xpos>224 )and(Etank.Xpos<352)and(Etank.Ypos>352)then
begin
//坦克掉頭
Etank.Smov:=1;
end;
end;
//如果敵方坦克移動方向向左
if Etank.Smov=1 then
begin
//把向左的坦克顯示出來
Etank.Sban:=10;
Etank.Xpos := Etank.Xpos - 4;
if (Etank.Xpos>224 )and(Etank.Xpos<356)and(Etank.Ypos>352)then
begin
Etank.Smov:=0;
end;
end;
//如果敵方坦克移動方向向下
if Etank.Smov=2 then
begin
//把向下的敵方坦克顯示出來
Etank.Sban:=9;
Etank.Ypos := Etank.Ypos + 4;
if (Etank.Xpos>224 )and(Etank.Xpos<356)and(Etank.Ypos>352)then
begin
Etank.Smov:=3;
end;
end;
if Etank.Smov=3 then
begin
Etank.Sban:=8;
Etank.Ypos := Etank.Ypos - 4;
if (Etank.Xpos>224 )and(Etank.Xpos<356)and(Etank.Ypos>352)then
begin
Etank.Smov:=2;
end;
end;
// end
// else
// Chpon.Xpos:=ChPon.Xpos;
// Chpon.Ypos:=Chpon.Ypos;
// end
{ case ChPon.Smov of
0: Chpon.Xpos := ChPon.Xpos + 4;
1: ChPon.Xpos := ChPon.Xpos - 4;
2: ChPon.Ypos := ChPon.Ypos + 4;
3: ChPon.Ypos := ChPon.Ypos - 4;
end;
}
//對于敵方坦克移動到屏幕外所做的處理
//(0=右;1=左;2=下:3=上)
if (Etank.Xpos < 0) then
begin
Etank.Smov:=0;
end
else if (Etank.Xpos >DYoko -32) then
begin
Etank.Smov:=1;
end
else if(Etank.Ypos<0)then
begin
Etank.Smov:=2;
end
else if (Etank.Ypos >DTate - 32 )then
begin
Etank.Smov := 3;
end;
end ;
Procedure TMainForm.Mytanks(Var Mytank:TPatDt);
begin
// Rect_L:=Rect(0,0,32,32);
// Rect_M:=Rect(Mytank.Xpos,Mytank.Ypos,Mytank.Xpos+32,Mytank.Ypos+32);
// Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
//Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
//移動方向(0=右;1=左;2=下:3=上)
if Mytank.Smov=0 then
begin
//把向右的我方坦克對應的圖畫的編號賦值
Mytank.Sban:=23;
end ;
//如果我方坦克移動方向向左
if Mytank.Smov=1 then
begin
//把向左的坦克顯示出來
Mytank.Sban:=22;
end;
//如果我方坦克移動方向向下
if Mytank.Smov=2 then
begin
//把向下的我方坦克顯示出來
Mytank.Sban:=21;
end;
if Mytank.Smov=3 then
begin
Mytank.Sban:=20;
end;
end;
//繪制敵人坦克函數
Procedure TMainForm.DrawEtank(Sban:Byte;X1,Y1:Integer);
begin
// 畫出敵人坦克
GX:=(Sban mod 8)*32;
GY:=(Sban div 8)*32;
Rect_L:=Rect(GX,GY,GX+32,GY+32);
Rect_M:=Rect(X1,Y1,X1+32,Y1+32);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
end;
//子彈碰撞檢測函數
Procedure TMainForm.HitCk;
var
X,Y,Cn:Byte;
begin
//我方子彈移動方向(0=右;1=左;2=下:3=上)
// 如果子彈向上出現中
// if MyBullet[0].Used=3 then
// begin
//碰撞判斷的計算式-30<=敵方坦克的坐標-子彈的坐標<=14
// Count:=0;
// for Cn:=0 to MaxETank-1 do
for Cn:=0 to 2 do
begin
if Etank[Cn].Used=1 then
begin
// Count:=Count+1;
// if Count>3 then begin
// Etank[4].Used:=1;
// end;
X2:=Etank[Cn].Xpos-MyBullet[0].Xpos;
Y2:=Etank[Cn].Ypos-MyBullet[0].Ypos;
if(X2>=-30)and(X2<=14)and(Y2>=-30)and(Y2<=14) then
begin
//爆炸標志設計為255
// Etank[Cn].FExplode:=255;
Etank[Cn].Used:=255;//當Used=255設定為爆炸標志
//我方子彈用黑色背景去除,敵人坦克產生爆炸效果
GX:=(0 mod 16)*16;
GY:=(0 div 16)*16;
Rect_L:=Rect(GX,GY,GX+16,GY+16);
Rect_M:=Rect(MyBullet[0].Xpos,MyBullet[0].Ypos,MyBullet[0].Xpos+16,MyBullet[0].Ypos+16);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
//我方子彈消失標志,使按鍵能夠再次發射子彈
MyBullet[0].Used:=4;
//把子彈的全局變量坐標設置到畫框外面
// 使敵人坦克不至于碰到原來子彈的位置而停止運動把它當作跟子彈 碰撞來處理
MyBullet[0].Xpos:=-16;
MyBullet[0].Ypos:=-16;
end;
end;
//我方坦克與敵方子彈碰撞
if Mytank[0].Used=1 then
begin
//Count:=Count+1;
// if Count>3 then begin
//Etank[4].Used:=1;
// end;
X3:=Mytank[0].Xpos-EBullet[Cn].Xpos;
Y3:=Mytank[0].Ypos-EBullet[Cn].Ypos;
if(X3>=-30)and(X3<=14)and(Y3>=-30)and(Y3<=14) then
begin
//爆炸標志設計為255
// Etank[Cn].FExplode:=255;
Mytank[0].Used:=255;//當Used=255設定為爆炸標志
//敵方子彈用黑色背景去除,我方坦克產生爆炸效果
GX:=(0 mod 16)*16;
GY:=(0 div 16)*16;
Rect_L:=Rect(GX,GY,GX+16,GY+16);
Rect_M:=Rect(EBullet[Cn].Xpos,EBullet[Cn].Ypos,EBullet[Cn].Xpos+16,EBullet[Cn].Ypos+16);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
//敵方對應坦克子彈消失標志
EBullet[Cn].Used:=4;
//把子彈的全局變量坐標設置到畫框外面
// 使敵人坦克不至于碰到原來子彈的位置而停止運動把它當作跟子彈 碰撞來處理
EBullet[Cn].Xpos:=-16;
EBullet[Cn].Ypos:=-16;
end;
end;
//敵我子彈與磚塊碰撞
for Y := 0 to (Tate - 1) do
for X := 0 to (Yoko - 1) do
begin
//與磚塊發生碰撞
if Grid[X,Y]=1 then
begin
MapGrid[X,Y].Xpos:=X*32;
MapGrid[X,Y].Ypos:=Y*32;
//敵方子彈與磚塊碰撞檢測
X5:= MapGrid[X,Y].Xpos-EBullet[Cn].Xpos;
Y5:= MapGrid[X,Y].Ypos-EBullet[Cn].Ypos;
//我方子彈與磚塊碰撞檢測
X6:=MapGrid[X,Y].Xpos-MyBullet[0].Xpos;
Y6:=MapGrid[X,Y].Ypos-MyBullet[0].Ypos;
if(X5>=-30)and(X5<=14)and(Y5>=-30)and(Y5<=14) then
begin
MapGrid[X,Y].Used:=255;//當Used=255設定為爆炸標志
//地圖磚塊不存在了
Grid[X,Y]:=0;
// 調用坦克爆炸聲音
sndPlaySound( 'bomb.wav', SND_ASYNC);
//敵方對應坦克子彈消失標志
EBullet[Cn].Used:=4;
GX:=(0 mod 16)*16;
GY:=(0 div 16)*16;
Rect_L:=Rect(GX,GY,GX+16,GY+16);
Rect_M:=Rect(EBullet[Cn].Xpos,EBullet[Cn].Ypos,EBullet[Cn].Xpos+16,EBullet[Cn].Ypos+16);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
//把敵人坦克與子彈碰撞時坦克的坐標賦值給全局變量
X4:=MapGrid[X,Y].Xpos;
Y4:=MapGrid[X,Y].Ypos;
//調用爆炸開始圖第一張爆炸圖
UseMap:=0;
//把定時器2開啟調用爆炸畫面
Timer2.Enabled:=true;
//把子彈的全局變量坐標設置到畫框外面
// 使敵人坦克不至于碰到原來子彈的位置而停止運動把它當作跟子彈 碰撞來處理
EBullet[Cn].Xpos:=-16;
EBullet[Cn].Ypos:=-16;
end;
if(X6>=-30)and(X6<=14)and(Y6>=-30)and(Y6<=14) then
begin
MapGrid[X,Y].Used:=255;//當Used=255設定為爆炸標志
//地圖磚塊不存在了
Grid[X,Y]:=0;
// 調用坦克爆炸聲音
sndPlaySound( 'bomb.wav', SND_ASYNC);
//敵方對應坦克子彈消失標志
MyBullet[0].Used:=4;
GX:=(0 mod 16)*16;
GY:=(0 div 16)*16;
Rect_L:=Rect(GX,GY,GX+16,GY+16);
Rect_M:=Rect(MyBullet[0].Xpos,MyBullet[0].Ypos,MyBullet[0].Xpos+16,MyBullet[0].Ypos+16);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
//把敵人坦克與子彈碰撞時坦克的坐標賦值給全局變量
X4:=MapGrid[X,Y].Xpos;
Y4:=MapGrid[X,Y].Ypos;
//調用爆炸開始圖第一張爆炸圖
UseMap:=0;
//把定時器2開啟調用爆炸畫面
Timer2.Enabled:=true;
//把子彈的全局變量坐標設置到畫框外面
// 使敵人坦克不至于碰到原來子彈的位置而停止運動把它當作跟子彈 碰撞來處理
MyBullet[0].Xpos:=-16;
MyBullet[0].Ypos:=-16;
end;
end;
//如果子彈碰到的是軍旗
if Grid[X,Y]=30 then
begin
MapGrid[X,Y].Xpos:=X*32;
MapGrid[X,Y].Ypos:=Y*32;
X5:= MapGrid[X,Y].Xpos-EBullet[Cn].Xpos;
Y5:= MapGrid[X,Y].Ypos-EBullet[Cn].Ypos;
//我方子彈與軍旗的碰撞
X6:=MapGrid[X,Y].Xpos-MyBullet[0].Xpos;
Y6:=MapGrid[X,Y].Ypos-MyBullet[0].Ypos;
if(X5>=-30)and(X5<=14)and(Y5>=-30)and(Y5<=14) then
begin
sndPlaySound( 'bomb.wav', SND_ASYNC);
EBullet[Cn].Used:=4;
GX:=(0 mod 16)*16;
GY:=(0 div 16)*16;
Rect_L:=Rect(GX,GY,GX+16,GY+16);
Rect_M:=Rect(EBullet[Cn].Xpos,EBullet[Cn].Ypos,EBullet[Cn].Xpos+16,EBullet[Cn].Ypos+16);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
Rect_1:=Rect(224,96,256,128);
Rect_2:=Rect(MapGrid[X,Y].Xpos,MapGrid[X,Y].Ypos,MapGrid[X,Y].Xpos+32,MapGrid[X,Y].Ypos+32);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_2,Load_Bmap.Canvas,Rect_1);
Mytank[0].used:=0;
//sleep(2000);
//BitmapGameover:=TBitmap.Create();
//BitmapGameover.LoadFromFile(GetcurrentDir+'\img\Gameover.bmp');
//Canvas.Draw(176,128,BitmapGameover);
//游戲結束 定時器不工作
//gsSuccess:=True;
//調用游戲結束聲音
//sndPlaySound( 'Gameover.wav', SND_ASYNC);
//end;
end;
if(X6>=-30)and(X6<=14)and(Y6>=-30)and(Y6<=14) then
begin
sndPlaySound( 'bomb.wav', SND_ASYNC);
MyBullet[0].Used:=4;
GX:=(0 mod 16)*16;
GY:=(0 div 16)*16;
Rect_L:=Rect(GX,GY,GX+16,GY+16);
Rect_M:=Rect(MyBullet[0].Xpos,MyBullet[0].Ypos,MyBullet[0].Xpos+16,MyBullet[0].Ypos+16);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
Rect_1:=Rect(224,96,256,128);
Rect_2:=Rect(MapGrid[X,Y].Xpos,MapGrid[X,Y].Ypos,MapGrid[X,Y].Xpos+32,MapGrid[X,Y].Ypos+32);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_2,Load_Bmap.Canvas,Rect_1);
Mytank[0].used:=0;
MyBullet[0].Xpos:=-16;
MyBullet[0].Ypos:=-16;
end;
end;
end;
end;
end ;
//子彈爆炸畫面函數
Procedure TMainForm.Explode(Sban:Byte;X1,Y1:Integer);
begin
GX:=(Sban mod 8)*32;
GY:=(Sban div 8)*32;
Rect_L:=Rect(GX,GY,GX+32,GY+32);
Rect_M:=Rect(X1,Y1,X1+32,Y1+32);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
// count:=0;
end;
//我方坦克子彈控制函數
Procedure TMainForm.MyBullets;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -