📄 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 + -