?? tank.pas
字號:
begin
// 先將原來的子彈用黑色16*16驅除然后再進行子彈新的繪制
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);
//如果我方坦克發射的子彈標志向上 (0=右;1=左;2=下:3=上)
if MyBullet[0].Used=3 then
begin
Mybullet[0].Ypos:=MyBullet[0].Ypos-4;
//如果子彈向上飛出屏幕則 空格鍵允許標志才有效 能繼續按空格鍵發射子彈
//否則空格鍵無效
if Mybullet[0].Ypos<-16 then
begin
Mybullet[0].Used:=4;
end;
end;
// if Mybullet[0].Ypos>16 then begin MyBullet[0].Used:=4; end;
//如果我方坦克發射的子彈標志向下 (0=右;1=左;2=下:3=上)
if MyBullet[0].Used=2 then
begin
Mybullet[0].Ypos:=MyBullet[0].Ypos+4;
//如果子彈向下飛出屏幕則 空格鍵允許標志才有效 能繼續按空格鍵發射子彈
//否則空格鍵無效
if Mybullet[0].Ypos>DTate+16 then
begin
Mybullet[0].Used:=4;
end;
end;
//如果我方坦克發射的子彈標志向左 (0=右;1=左;2=下:3=上)
if MyBullet[0].Used=1 then
begin
Mybullet[0].Xpos:=MyBullet[0].Xpos-4;
//如果子彈向左飛出屏幕則空格鍵允許標志才有效 能繼續按空格鍵發射子彈
//否則空格鍵無效
if Mybullet[0].Xpos<-16 then
begin
Mybullet[0].Used:=4;
end;
end;
//如果我方坦克發射的子彈標志向右 (0=右;1=左;2=下:3=上)
if MyBullet[0].Used=0 then
begin
Mybullet[0].Xpos:=MyBullet[0].Xpos+4;
//如果子彈向右飛出屏幕則空格鍵允許標志才有效 能繼續按空格鍵發射子彈
//否則空格鍵無效
if Mybullet[0].Xpos>DYoko+16 then
begin
Mybullet[0].Used:=4;
end;
end;
GX:=(MyBullet[0].Sban mod 16)*16;
GY:=(MyBullet[0].Sban 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);
end;
Procedure TMainForm.EBullets;
var
Cn:Byte;
begin
//for Cn:=0 to 2 do
// begin
Randomize;
ChooseENum:=Random(3);
Cn:=ChooseENum;
//敵人坦克發射子彈幾率
//EBullet[Cn].Used:=random(5);
//如果該輛敵人坦克在屏幕中并且該輛坦克屏幕中無子彈并且Random(100)<3
if (Etank[Cn].Used=1)and (EBullet[Cn].Used=4)and (Random(100)<3)then
begin
//如果敵方坦克移動方向為右(0=右;1=左;2=下:3=上)
if Etank[Cn].Smov=0 then
begin
//這里Used使用有點特殊為子彈方向向右
EBullet[Cn].Used:=0;
EBullet[Cn].Xpos:=Etank[Cn].Xpos+32;
EBullet[Cn].Ypos:=Etank[Cn].Ypos+8;
EBullet[Cn].Sban:=14;
end;
//敵人坦克方向向左
if Etank[Cn].Smov=1 then
begin
EBullet[Cn].Used:=1;
EBullet[Cn].Xpos:=Etank[Cn].Xpos-16;
EBullet[Cn].Ypos:=Etank[Cn].Ypos+8;
EBullet[Cn].Sban:=15;
end;
if Etank[Cn].Smov=2 then
begin
EBullet[Cn].Used:=2;
EBullet[Cn].Xpos:=Etank[Cn].Xpos+8;
EBullet[Cn].Ypos:=Etank[Cn].Ypos+32;
EBullet[Cn].Sban:=12;
end;
if Etank[Cn].Smov=3 then
begin
EBullet[Cn].Used:=3;
EBullet[Cn].Xpos:=Etank[Cn].Xpos+8;
EBullet[Cn].Ypos:=Etank[Cn].Ypos-16;
EBullet[Cn].Sban:=13;
end;
end;
end;
Procedure TMainForm.DrawEBullets;
var
Cn:Byte;
begin
//for Cn:=0 to 2 do
// 先將原來的子彈用黑色16*16驅除然后再進行子彈新的繪制
// Randomize;
//ChooseENum:=Random(3);
//全局變量ChooseENum由EBullets函數中控制
Cn:= ChooseENum;
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);
//如果敵方坦克子彈移動方向為右(0=右;1=左;2=下:3=上)
//這里的Used是方向(0~3)
if EBullet[Cn].Used=0 then
begin
//子彈坐標向右移動4個單位
EBullet[Cn].Xpos:=EBullet[Cn].Xpos+4;
end;
//子彈移動出屏幕外,把允許再次發射子彈標志設為允許
if EBullet[Cn].Xpos> DYoko+16 then
begin
//這里的Used是子彈允許標志
EBullet[Cn].Used:=4;
end;
//如果敵方坦克子彈移動方向向左
if EBullet[Cn].Used=1 then
begin
EBullet[Cn].Xpos:=EBullet[Cn].Xpos-4;
end;
if EBullet[Cn].Xpos<-16 then
begin
EBullet[Cn].Used:=4;
end;
//如果敵方坦克子彈移動方向向下
if EBullet[Cn].Used=2 then
begin
EBullet[Cn].Ypos:=EBullet[Cn].Ypos+4;
end;
if EBullet[Cn].Ypos>DTate+16 then
begin
EBullet[Cn].Used:=4;
end;
//如果敵方坦克子彈移動方向向上
if EBullet[Cn].Used=3 then
begin
EBullet[Cn].Ypos:=EBullet[Cn].Ypos-4;
end;
if EBullet[Cn].Ypos<-16 then
begin
EBullet[Cn].Used:=4;
end;
GX:=(EBullet[Cn].Sban mod 16)*16;
GY:=(EBullet[Cn].Sban 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);
end;
procedure TMainForm.N2Click(Sender: TObject);
var
X,Y:Byte;
begin
//游戲開始把屏幕的畫面清理掉
for Y := 0 to (Tate - 1) do
for X := 0 to (Yoko - 1) do
begin
P := Ptmap2[X,Y];
//把地圖內容復制給中間數組
Grid[X,Y]:=P;
// MapGrid[X,Y]:= P;
//樣圖中一行中的的第幾個
PX := (P mod 8) * 32;
//樣圖中的第PY行
PY := (P div 8) * 32;
//畫背景地圖
Rect_L := Rect(PX, PY, PX + 32, PY + 32);
Rect_M := Rect(X * 32, Y * 32, X * 32 + 32, Y * 32 + 32);
Make_Bmap.Canvas.CopyRect(Rect_M, Load_Bmap.Canvas, Rect_L);
end;
MainForm.Canvas.CopyMode := cmSrcCopy;
MainForm.Canvas.Draw(0, 0, Make_Bmap);
sndPlaySound( 'Start.WAV', SND_ASYNC);
// 游戲開始狀態能進行鍵盤控制坦克
//并且敵方坦克也開始移動
//游戲開始把游戲開始標志設為ture
gsPlaying:=true;
//三輛敵方坦克最初出現的位置
Etank[0].Xpos:=0;
Etank[0].Ypos:=0;
Etank[0].Used:=1;
Etank[1].Xpos:=288;
Etank[1].Ypos:=0;
Etank[1].Used:=1;
Etank[2].Xpos:=544;
Etank[2].Ypos:=0 ;
Etank[2].Used:=1;
//我方坦克初始化
Mytank[0].Xpos:=224;
Mytank[0].Ypos:=416;
Mytank[0].Used:=1;
Mytank[0].Sban:=20;
Mytank[0].Smov:=3;
//先把我方坦克子彈使用設為可以發射子彈
Mybullet[0].Used:=4;
//把敵方坦克子彈使用設為可以發射子彈
Ebullet[0].Used:=4;
//子彈初始坐標設在屏幕外
Ebullet[0].Xpos:=-16;
Ebullet[0].Ypos:=-16;
Ebullet[1].Used:=4;
Ebullet[1].Xpos:=-16;
Ebullet[1].Ypos:=-16;
Ebullet[2].Used:=4;
Ebullet[2].Xpos:=-16;
Ebullet[2].Ypos:=-16;
// Count:=0;
//游戲剛開始把過關標志設為false
gsSuccess:=false;
//游戲剛開始把游戲失敗標志設為false
gsOver:=false;
end;
procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
//在響應按鍵命令之前先把原來我方坦克用黑色覆蓋掉
Rect_L:=Rect(0,0,32,32);
Rect_M:=Rect(Mytank[0].Xpos,Mytank[0].Ypos,Mytank[0].Xpos+32,Mytank[0].Ypos+32);
Make_Bmap.Canvas.CopyMode:=cmSrcCopy;
Make_Bmap.Canvas.CopyRect(Rect_M,Load_Bmap.Canvas,Rect_L);
//響應把新坦克畫在相應的畫面上
//移動方向(0=右;1=左;2=下:3=上)
//如果按鍵向左把大炮向左的坦克顯示并實現坦克向左移動4個單位
if (key = VK_Left)and (Mytank[0].Xpos>0)then
begin
//我方坦克方向向左
Mytank[0].Smov:=1;
////使我方坦克不能開過下方中心的有磚塊的地方
if (Mytank[0].Xpos>224 )and(Mytank[0].Xpos<=352)
and(Mytank[0].Ypos>352)then
begin
Mytank[0].Xpos:=Mytank[0].Xpos;
end
else begin
Mytank[0].Xpos:=Mytank[0].Xpos-4;
end;
end;
//如果按鍵向上把大炮向上的坦克顯示并實現坦克向上移動4個單位
if (key=VK_UP) and (Mytank[0].Ypos>0) then
begin
Mytank[0].Smov:=3;
if (Mytank[0].Xpos>224 )and(Mytank[0].Xpos<352)and(Mytank[0].Ypos>352)
then begin
Mytank[0].Ypos:=Mytank[0].Ypos;
end
else begin
Mytank[0].Ypos:=Mytank[0].Ypos-4;
end;
end ;
//如果按鍵向下把大炮向下的坦克顯示并實現坦克向下移動4個單位
if (key=VK_DOWN) and (Mytank[0].Ypos<DTate-32) then
begin
Mytank[0].Smov:=2;
if (Mytank[0].Xpos>224 )and(Mytank[0].Xpos<352)and(Mytank[0].Ypos>=352)
then begin
Mytank[0].Ypos:=Mytank[0].Ypos;
end
else begin
Mytank[0].Ypos:=Mytank[0].Ypos+4;
end;
end;
//如果按鍵向右把大炮向右的坦克顯示并實現坦克向右移動4個單位
if (key=VK_Right)and (Mytank[0].Xpos<DYoko-32) then begin
Mytank[0].Smov:=0;
if (Mytank[0].Xpos>=224 )and(Mytank[0].Xpos<352)and(Mytank[0].Ypos>352)
then begin
Mytank[0].Xpos:=Mytank[0].Xpos;
end
else begin
Mytank[0].Xpos:=Mytank[0].Xpos+4 ;
end;
end ;
//如果空格鍵被按下則我方坦克發射子彈
if MyBullet[0].Used=4 then
begin
if(key=VK_Space) then
begin
//如果子彈發射則播放發射子彈聲音 SND_ASYNC 為只播放一次
sndPlaySound( 'Fire.WAV', SND_ASYNC);
//移動方向(0=右;1=左;2=下:3=上)
//如果我方坦克移動方向向右則
if Mytank[0].Smov=0 then
begin
//我方子彈出現標志向左
MyBullet[0].Used:=0;
//如果我方坦克方向向右并且空格鍵被按下則子彈出現的出始位置為
MyBullet[0].Xpos:=Mytank[0].Xpos+32;
MyBullet[0].Ypos:=Mytank[0].Ypos+8;
//向右子彈編號為 說明:只有子彈編號采用16*16象素其他的都采用32*32象素
MyBullet[0].Sban:=14;
end;
//如果我方坦克方向向左
if Mytank[0].Smov=1 then
begin
//我方子彈出現標志
MyBullet[0].Used:=1;
//如果我方坦克方向向左并且空格鍵被按下則子彈出現的出始位置為
MyBullet[0].Xpos:=Mytank[0].Xpos-16;
MyBullet[0].Ypos:=Mytank[0].Ypos+8;
//向左子彈編號為 說明:只有子彈編號采用16*16象素其他的都采用32*32象素
MyBullet[0].Sban:=15;
end;
//如果我方坦克方向向下
if Mytank[0].Smov=2 then
begin
//我方子彈出現標志
MyBullet[0].Used:=2;
//如果我方坦克方向向下并且空格鍵被按下則子彈出現的出始位置為
MyBullet[0].Xpos:=Mytank[0].Xpos+8;
MyBullet[0].Ypos:=Mytank[0].Ypos+32;
//向右子彈編號為 說明:只有子彈編號采用16*16象素其他的都采用32*32象素
MyBullet[0].Sban:=12;
end;
//如果我方坦克方向向上
if Mytank[0].Smov=3 then
begin
//我方子彈出現標志
MyBullet[0].Used:=3;
//如果我方坦克方向向上并且空格鍵被按下則子彈出現的出始位置為
MyBullet[0].Xpos:=Mytank[0].Xpos+8;
MyBullet[0].Ypos:=Mytank[0].Ypos-16;
//向右子彈編號為 說明:只有子彈編號采用16*16象素其他的都采用32*32象素
MyBullet[0].Sban:=13;
end;
end;
end;
end;
procedure TMainForm.Timer2Timer(Sender: TObject);
begin
if(UseMap<6) then
begin
//調用爆炸函數
Explode(ExplodeMap[UseMap],X4,Y4);
//爆炸圖片序號加1
UseMap:=UseMap+1;
end;
if (UseMap>=6)then
begin
Timer2.enabled:=false;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -