该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
amy[i].fire.x=amy[i].x;
amy[i].fire.y=amy[i].y;
}
break;
}
}
if(lose)/*因为失败而跳出循环显示失败*/
{GameOver();break;}
if(GetKey(KEY_ESC))
break;
if(GetKey(KEY_UP))/*往上*/
{
if(Playone.direction==1&&map[Playone.x-1][Playone.y]!=1&&map[Playone.x-1][Playone.y]!=2)
{
if(map[Playone.x-1][Playone.y]==3)
continue;
DrawBlack(Playone.y,Playone.x);/*这个if是移动,前提是方向与按下的到向一致*/
Playone.x--;
Playone.direction=1;
DrawPlay(Playone.y,Playone.x);
}
else/*只调整炮头方向*/
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=1;
DrawPlay(Playone.y,Playone.x);
}
}
else if(GetKey(KEY_DOWN))/*往下*/
{
if(Playone.direction==3&&map[Playone.x+1][Playone.y]!=1&&map[Playone.x+1][Playone.y]!=2)
{
if(map[Playone.x+1][Playone.y]==3)
continue;
DrawBlack(Playone.y,Playone.x);
Playone.x++;
Playone.direction=3;
DrawPlay(Playone.y,Playone.x);
}
else
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=3;
DrawPlay(Playone.y,Playone.x);
}
}
if(GetKey(KEY_RIGHT))/*往右*/
{
if(Playone.direction==2&&map[Playone.x][Playone.y+1]!=1&&map[Playone.x][Playone.y+1]!=2)
{
if(map[Playone.x][Playone.y+1]==3)
continue;
DrawBlack(Playone.y,Playone.x);
Playone.y++;
Playone.direction=2;
DrawPlay(Playone.y,Playone.x);
}
else
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=2;
DrawPlay(Playone.y,Playone.x);
}
}
if(GetKey(KEY_LEFT))/*往左*/
{
if(Playone.direction==4&&map[Playone.x][Playone.y-1]!=1&&map[Playone.x][Playone.y-1]!=2)
{
if(map[Playone.x][Playone.y-1]==3)
continue;
DrawBlack(Playone.y,Playone.x);
Playone.y--;
Playone.direction=4;
DrawPlay(Playone.y,Playone.x);
}
else
{
DrawBlack(Playone.y,Playone.x);
Playone.direction=4;
DrawPlay(Playone.y,Playone.x);
}
}
if(GetKey(KEY_SPACE))/*发射子弹*/
{
for(i=0;i<5;i++)/*用循环来找是否有子弹可以用*/
if(Playone.fire[i].direction<0)
{
sound(300);
Playone.fire[i].direction=Playone.direction;/*子弹方向与坦克方向一致*/
Playone.fire[i].x=Playone.x;
Playone.fire[i].y=Playone.y;
break;/*找到后就跳出循环*/
}
}
if(map[Playone.x][Playone.y]==5)/*玩家自己撞到老家*/
lose=1;
for(i=0;i<5;i++)/*判断是否因自己控制撞到敌人*/
{
if(amy[i].direction<0)
continue;
if(amy[i].x==Playone.x&&amy[i].y==Playone.y)/*相撞*/
lose=1;
}
if(lose)/*因为失败而跳出循环显示失败*/
{GameOver();break;}
t++;/*加到一定的程序就出现新的敌人*/
if(t==30) /*到了增加敌人的时候*/
{t=0;
for(i=0;i<5;i++)
if(amy[i].direction<0)
{
amy[i].direction=amy[i].directiontwo=3;
amy[i].x=1;
amy[i].y=random(3);/*方向随机*/
if(amy[i].y==0)
amy[i].y=1;
else if(amy[i].y==1)
amy[i].y=9;
else/*这里和上面的两个判断是判断敌人的初始位置*/
amy[i].y=18;
amy[i].color=random(3)+12;/*颜色随机*/
DrawAmy(amy[i].y,amy[i].x,i);
break;/*找到一个后就出循环*/
}
}
}
}