#include "reg51.h"
#include"lcd12864.h"
#include <stdlib.h>
sbit P1_row1 = P1 ^ 0;
sbit P1_row2 = P1 ^ 1;
sbit P1_col1 = P1 ^ 2;
sbit P1_col2 = P1 ^ 3;
sbit P2_row1 = P1 ^ 4;
sbit P2_row2 = P1 ^ 5;
sbit P2_col1 = P1 ^ 6;
sbit P2_col2 = P1 ^ 7;
#define Up 1 //定义上下左右方向
#define Right 2
#define Down 3
#define Left 4
#define Up_Left 1 //定义炮弹炸毁效果4个方向(但是由于炮弹的非对称性,导致比如"上左"与"左上"坐标计算有区别)
#define Up_Right 2
#define Down_Left 3
#define Down_Right 4
#define Left_Up 5
#define Left_Down 6
#define Right_Up 7
#define Right_Down 8
#define Steel 1 //定义障碍物属性
#define Brick 2
#define Prefect 1 //定义基地状态
#define Destroy 2
#define Tank_Count 2 //坦克数量
#define Barrier_Count 8 //障碍物数量
#define Computer 1 //坦克的阵营
#define Human 2
uint8 code Human_Tank1_Up[8] ={0xFF,0xFF,0x7C,0x7F,0x7F,0x7C,0xFF,0xFF}; //玩家模型1的上下左右的贴图
uint8 code Human_Tank1_Right[8] ={0xC3,0xFF,0xFF,0xFF,0xFF,0xFF,0xDB,0xDB};
uint8 code Human_Tank1_Down[8] ={0xFF,0xFF,0x3E,0xFE,0xFE,0x3E,0xFF,0xFF};
uint8 code Human_Tank1_Left[8] ={0xDB,0xDB,0xFF,0xFF,0xFF,0xFF,0xFF,0xC3};
uint8 code Human_Tank2_Up[8] ={0xFF,0xCC,0x78,0x3F,0x3F,0x78,0xCC,0xFF}; //玩家模型2的上下左右的贴图
uint8 code Human_Tank2_Right[8] ={0xC3,0xE7,0xBD,0xBD,0xFF,0xDB,0x99,0x99};
uint8 code Human_Tank2_Down[8] ={0xFF,0x33,0x1E,0xFC,0xFC,0x1E,0x33,0xFF};
uint8 code Human_Tank2_Left[8] ={0x99,0x99,0xDB,0xFF,0xBD,0xBD,0xE7,0xC3};
uint8 code Human_Tank3_Up[8] ={0xFF,0xFC,0x70,0x7F,0x7F,0x70,0xFC,0xFF}; //玩家模型3的上下左右的贴图
uint8 code Human_Tank3_Right[8] ={0xC3,0xFF,0xFF,0xFF,0xDB,0xDB,0x99,0x99};
uint8 code Human_Tank3_Down[8] ={0xFF,0x3F,0x0E,0xFE,0xFE,0x0E,0x3F,0xFF};
uint8 code Human_Tank3_Left[8] ={0x99,0x99,0xDB,0xDB,0xFF,0xFF,0xFF,0xC3};
uint8 code Computer_Tank1_Up[8] ={0xFF,0xFC,0xF8,0x43,0x43,0xF8,0xFC,0xFF}; //电脑模型1的上下左右的贴图
uint8 code Computer_Tank1_Right[8] ={0xE7,0xFF,0xE7,0xE7,0xE7,0xC3,0x99,0x99};
uint8 code Computer_Tank1_Down[8] ={0xFF,0x3F,0x1F,0xC2,0xC2,0x1F,0x3F,0xFF};
uint8 code Computer_Tank1_Left[8] ={0x99,0x99,0xC3,0xE7,0xE7,0xE7,0xFF,0xE7};
uint8 code Computer_Tank2_Up[8] ={0xFF,0x62,0x30,0xDF,0xDF,0x30,0x62,0xFF}; //电脑模型2的上下左右的贴图
uint8 code Computer_Tank2_Right[8] ={0x99,0xDB,0xE7,0xBD,0x99,0x99,0xDB,0x99};
uint8 code Computer_Tank2_Down[8] ={0xFF,0x46,0x0C,0xFB,0xFB,0x0C,0x46,0xFF};
uint8 code Computer_Tank2_Left[8] ={0x99,0xDB,0x99,0x99,0xBD,0xE7,0xDB,0x99};
uint8 code Computer_Tank3_Up[8] ={0xE7,0x3C,0xC6,0xF3,0xF3,0xC6,0x3C,0xE7}; //电脑模型3的上下左右的贴图
uint8 code Computer_Tank3_Right[8] ={0xBD,0xBD,0xDB,0x5A,0x42,0xE7,0xBD,0x99};
uint8 code Computer_Tank3_Down[8] ={0xE7,0x3C,0x63,0xCF,0xCF,0x63,0x3C,0xE7};
uint8 code Computer_Tank3_Left[8] ={0x99,0xBD,0xE7,0x42,0x5A,0xDB,0xBD,0xBD};
uint8 code Prefect_Home[8]={0xE7,0xFF,0x99,0x81,0xC3,0x66,0x3C,0x18}; //正常基地的贴图
uint8 code Destroy_Home[8]={0xE7,0xF7,0x05,0xB1,0xCF,0xE7,0xBC,0x3A}; //被摧毁基地的贴图
struct TANK
{
uint8 Exist; //玩家坦克是否存在,1为存在,0为不存在
uint8 Life; //剩余坦克的数量
uint8 Level; //坦克的级别
uint8 Camp; //玩家阵营
uint8 Position[2]; //坦克的坐标
uint8 Direction; //坦克的方向
uint8 Tank_Bounce_Wall_Flg; //坦克碰壁标志位
uint8 Tank_Bounce_Tank_Flg; //坦克碰其他坦克标志位
uint8 Tank_Bounce_Home_Flg;
uint8 Shot_Position[2]; //炮弹的位置
uint8 Shot_Direction; //炮弹的方向
uint8 Send_Shot_Flg; //发射炮弹标志位
uint8 Shot_Bounce_Wall_Flg; //炮弹碰壁标志位
uint8 Shot_Bounce_Tank_Flg; //炮弹碰其他坦克标志位
uint8 Button__Down_Flg; //是否有按键按下的标志位
}Tank1,Tank2;
struct Barrier
{
uint8 Position[2]; //障碍物的坐标
uint8 Length; //障碍物的长度
uint8 Width; //障碍物的宽度
uint8 Property; //障碍物的材质(砖瓦还是钢铁)
uint8 Exist; //障碍物的破坏程度(位保存,一个字节可以存储8块)
}Barrier1,Barrier2,Barrier3,Barrier4,Barrier5,Barrier6,Barrier7,Barrier8;
uint8 Time_Flg=0; //用于时间调整
uint8 xdata Temp_tank1[16]; //存放显示塔克1的数据
uint8 xdata Temp_tank2[16]; //存放显示塔克2的数据
uint8 xdata Temp_data[16]; //显示一些临时数据,比如基地贴图
void Init_Total(void); //初始化(包括LCD,中断寄存器,计时器,背景等)
void Ar_Intel_Tank(struct TANK *t); //电脑随机控制坦克函数
void Tank_Wall_Check(struct TANK *t); //坦克碰壁检测
void Tank_Tank_Check(struct TANK *t); //坦克碰坦克检测
void Tank_Home_Check(struct TANK *t); //坦克碰基地检测
void Tank_Advance(struct TANK *t); //坦克行进函数
void Display_Tank(struct TANK *t,uint8 *temp); //显示坦克
void Delete_Tank_Tail(struct TANK *t,uint8 *temp); //去除坦克残像
void Replace_Tank(uint8 num); //根据编号重置坦克位置数据
void Replace_Shot(struct TANK *t); //重置炮弹数据
void Shot_Wall_Check(struct TANK *t); //炮弹碰壁检测函数
void Shot_Tank_Check(struct TANK *t); //炮弹碰坦克检测函数
void Shot_Shot_Check(struct TANK *t); //炮弹碰炮弹检测并处理函数
void Shot_Home_Check(struct TANK *t); //炮弹碰基地检测并处理函数
void Display_Shot(struct TANK *t); //显示炮弹
void Delete_Shot_Tail(struct TANK *t); //去除炮弹残像
void Delete_Shot(uint8 shot_direction,uint8 *shot_position); //无视条件去除炮弹残像
void Shot_Bounce_Wall_Effect(struct TANK *t); //炮弹碰壁影响函数
void Shot_Bounce_Tank_Effect(struct TANK *t); //炮弹碰坦克影响函数
void Shot_Disappear(uint8 direction,uint8 *shot_position,uint8 *tank_position);//炮弹碰撞物体消失函数
void Shot_Break(uint8 *Shot_Position,uint8 direction ); //炮弹破坏障碍物的效果函数
void Draw_Blackground(void); //绘制背景
void Draw_Barrier(struct Barrier *b); //绘制障碍物
void Draw_Home(uint8 state); //绘制基地
void Draw_Piece_Steel(uint8 x,uint8 y); //指定坐标处画铁的贴图
void Draw_Piece_Brick(uint8 x,uint8 y); //指定坐标处画砖的贴图
void Copy_Array(uint8 *Desition,uint8 *original,uint8 length); //复制数组函数
void Change_Picture(uint8 Position,uint8 *Desition); //贴图转化函数(转化的贴图字节存在*Destion中)
void Get_Nearest_Barrier(uint8 *position,uint8 direction,uint8 object_length,uint8 object_width,uint8 *num);//查找离被查物最近的障碍物,以障碍物的后边沿为准
uint8 Get_Nearest_Tank(uint8 *position,uint8 direction,uint8 object_length,uint8 object_width); //查找离被查物最近的坦克,以坦克的前边沿为准
void Get_Barrier_Quality (uint8 number,uint8 *position,uint8 *length,uint8 *width); //获得指定障碍物的坐标值,长度,宽度
void Get_Tank_Position (uint8 number,uint8 *position); //获得指定坦克的坐标值
void Change_Tank_Exist (uint8 number,uint8 *exist); //更改指定坦克是否存在
void Get_Tank_Camp (uint8 number,uint8 *camp); //获得指定坦克的阵营
void Get_Tank_Life (uint8 number,uint8 *life); //获得指定坦克的生命
void Change_Tank_Life (uint8 number,uint8 *life); //更改指定坦克的生命
void Get_Tank_Level (uint8 number,uint8 *level); //获得指定坦克的级别
void Change_Tank_Level (uint8 number,uint8 *level); //更改指定坦克的级别
void Get_Tank_Shot_Quality (uint8 number,uint8 *position,uint8 *direction); //获得指定坦克炮弹的坐标值,方向
void Read_Barrier_Exist (uint8 number,uint8 *exist); //读取障碍物的破坏程度
void Write_Barrier_Exist (uint8 number,uint8 *exist); //写入障碍物的破坏程度
void Get_Barrier_Property (uint8 number,uint8 *property); //获得障碍物的组成物质
void main()
{
Init_Total();
while(1)
{
P1_row1=0;P1_row2=0;
P2_row1=0;P2_row2=0;
EX0=1;EX1=1;
if(Time_Flg%12==10) //操作坦克1
{
//Ar_Intel_Tank(&Tank1);
if(Tank1.Button__Down_Flg==1&&Tank1.Exist==1)
{
Delete_Tank_Tail(&Tank1,Temp_tank1);
Tank1.Tank_Bounce_Wall_Flg=0;
Tank1.Tank_Bounce_Tank_Flg=0;
Tank1.Tank_Bounce_Home_Flg=0;
Tank_Wall_Check(&Tank1);
Tank_Tank_Check(&Tank1);
Tank_Home_Check(&Tank1);
if(Tank1.Tank_Bounce_Wall_Flg==0&&Tank1.Tank_Bounce_Tank_Flg==0&&Tank1.Tank_Bounce_Home_Flg==0)
{
Tank_Advance(&Tank1);
}
Display_Tank(&Tank1,Temp_tank1);
if(Tank1.Position[0]%2==0&&Tank1.Position[1]%2==0)
{
Tank1.Button__Down_Flg=0;
}
}
}
if(Time_Flg%12==1) //操作坦克2
{
Ar_Intel_Tank(&Tank2);
if(Tank2.Button__Down_Flg==1&&Tank2.Exist==1)
{
Delete_Tank_Tail(&Tank2,Temp_tank2);
Tank2.Tank_Bounce_Wall_Flg=0;
Tank2.Tank_Bounce_Tank_Flg=0;
Tank2.Tank_Bounce_Home_Flg=0;
Tank_Wall_Check(&Tank2);
Tank_Tank_Check(&Tank2);
Tank_Home_Check(&Tank2);
if(Tank2.Tank_Bounce_Wall_Flg==0&&Tank2.Tank_Bounce_Tank_Flg==0&&Tank2.Tank_Bounce_Home_Flg==0)
{
Tank_Advance(&Tank2);
}
Display_Tank(&Tank2,Temp_tank2);
if(Tank2.Position[0]%2==0&&Tank2.Position[1]%2==0)
{
Tank2.Button__Down_Flg=0;
}
}
}
if(Time_Flg%3==1) //操作坦克1的炮弹
{
if(Tank1.Exist==1)
{
if(Tank1.Send_Shot_Flg!=0)
{
Shot_Shot_Check(&Tank1);
Shot_Home_Check(&Tank1);
}
if(Tank1.Shot_Bounce_Wall_Flg==1)
{
Shot_Bounce_Wall_Effect(&Tank1);
Tank1.Shot_Bounce_Wall_Flg=0;
}
if(Tank1.Shot_Bounce_Tank_Flg==1)
{
Shot_Bounce_Tank_Effect(&Tank1);
Tank1.Shot_Bounce_Tank_Flg=0;
}
if(Tank1.Send_Shot_Flg==0)
{
Replace_Shot(&Tank1);
}
if(Tank1.Send_Shot_Flg!=0)
{
Shot_Wall_Check(&Tank1);
Shot_Tank_Check(&Tank1);
Display_Shot(&Tank1);
Delete_Shot_Tail(&Tank1);
}
}
}
if(Time_Flg%3==2) //操作坦克2的炮弹
{
if(Tank2.Exist==1)
{
if(Tank2.Send_Shot_Flg!=0)
{
Shot_Shot_Check(&Tank2);
Shot_Home_Check(&Tank2);
}
if(Tank2.Shot_Bounce_Wall_Flg==1)
{
Shot_Bounce_Wall_Effect(&Tank2);
Tank2.Shot_Bounce_Wall_Flg=0;
}
if(Tank2.Shot_Bounce_Tank_Flg==1)
{
Shot_Bounce_Tank_Effect(&Tank2);
Tank2.Shot_Bounce_Tank_Flg=0;
}
if(Tank2.Send_Shot_Flg==0)
{
Replace_Shot(&Tank2);
}
if(Tank2.Send_Shot_Flg!=0)
{
Shot_Wall_Check(&Tank2);
Shot_Tank_Check(&Tank2);
Display_Shot(&Tank2);
Delete_Shot_Tail(&Tank2);
}
}
}
}
}
/* *************************************************************************************************
* Function Name : Init_Total *
* Description : 初始化(包括LCD,中断寄存器,计时器,背景,我方与敌方坦克数据等) *
* Date : 09/09/19 *
* Parameter :无 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Init_Total(void)
{
LCD12864_Init(); //lcd初始化
CleanAll();
EA=1; //中断初始化
EX0=1;EX1=1;
IT0=1;IT1=1;
TMOD=0X51; //定时器初始化
TL0=0XFE; TL1=0XFF;
TH0=0XFD; TH1=0XFF;
ET0=1; ET1=1;
Tank1.Exist=1;
Replace_Tank(1); //坦克数据1初始化
Tank1.Camp=Human;
Tank1.Life=50;
Tank2.Exist=1;
Replace_Tank(2); //坦克数据2初始化
Tank2.Camp=Computer;
Tank2.Life=50;
Barrier1.Position[0]=12; //障碍物数据初始化
Barrier1.Position[1]=20;
Barrier1.Length=8;
Barrier1.Width=4;
Barrier1.Property=Brick;
Barrier1.Exist=0X1F;
Barrier2.Position[0]=12;
Barrier2.Position[1]=28;
Barrier2.Length=8;
Barrier2.Width=4;
Barrier2.Property=Brick;
Barrier2.Exist=0X0F;
Barrier3.Position[0]=12;
Barrier3.Position[1]=36;
Barrier3.Length=8;
Barrier3.Width=4;
Barrier3.Property=Brick;
Barrier3.Exist=0X8F;
Barrier4.Position[0]=16;
Barrier4.Position[1]=20;
Barrier4.Length=8;
Barrier4.Width=4;
Barrier4.Property=Brick;
Barrier4.Exist=0XF1;
Barrier5.Position[0]=16;
Barrier5.Position[1]=28;
Barrier5.Length=8;
Barrier5.Width=4;
Barrier5.Property=Brick;
Barrier5.Exist=0XF0;
Barrier6.Position[0]=16;
Barrier6.Position[1]=36;
Barrier6.Length=8;
Barrier6.Width=4;
Barrier6.Property=Brick;
Barrier6.Exist=0XF8;
Barrier7.Position[0]=12; //7号与8号障碍物为基地周围的保护建筑
Barrier7.Position[1]=56;
Barrier7.Length=8;
Barrier7.Width=4;
Barrier7.Property=Brick;
Barrier7.Exist=0X2E;
Barrier8.Position[0]=16;
Barrier8.Position[1]=56;
Barrier8.Length=8;
Barrier8.Width=4;
Barrier8.Property=Brick;
Barrier8.Exist=0XE2;
Draw_Blackground();
TR0=1;TR1=1;
}
/* *************************************************************************************************
* Function Name :Replace_Tank *
* Description :根据编号重置坦克位置数据 *
* Date :09/09/20 *
* Parameter :坦克编号 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Replace_Tank(uint8 num)
{
switch(num)
{
case 1:
Tank1.Position[0]=20; //坦克数据1初始化
Tank1.Position[1]=60;
Tank1.Direction=Left;
Tank1.Button__Down_Flg=0;
Tank1.Send_Shot_Flg=0;
Tank1.Shot_Bounce_Wall_Flg=0;
Tank1.Level=3;
break;
case 2:
Tank2.Position[0]=14; //坦克数据2初始化
Tank2.Position[1]=0;
Tank2.Direction=Right;
Tank2.Button__Down_Flg=0;
Tank2.Send_Shot_Flg=0;
Tank2.Shot_Bounce_Wall_Flg=0;
Tank2.Level=3;
break;
}
}
/* *************************************************************************************************
* Function Name :Draw_Blackground *
* Description :绘制背景 *
* Date :09/09/20 *
* Parameter :无 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Draw_Blackground(void)
{
Display_Tank(&Tank1,Temp_tank1);
Display_Tank(&Tank2,Temp_tank2);
Draw_Barrier(&Barrier1);
Draw_Barrier(&Barrier2);
Draw_Barrier(&Barrier3);
Draw_Barrier(&Barrier4);
Draw_Barrier(&Barrier5);
Draw_Barrier(&Barrier6);
Draw_Barrier(&Barrier7);
Draw_Barrier(&Barrier8);
Draw_Home(Prefect);
}
/* *************************************************************************************************
* Function Name : Draw_Home *
* Description :绘制基地 *
* Date : 09/09/19 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Draw_Home(uint8 state)
{
uint8 i,j;
switch(state)
{
case Prefect:Copy_Array(Temp_data,Prefect_Home,8);break;
case Destroy:Copy_Array(Temp_data,Destroy_Home,8);break;
}
Change_Picture(2,Temp_data);
for(i=0;i<2;i++)
{
for(j=0;j<8;j++)
{
Add_Points(3+i,60*2+j,Temp_data[i*8+j]);
}
}
}
/* *************************************************************************************************
* Function Name : Ar_Intel_Tank *
* Description : 电脑随机控制坦克函数 *
* Date : 09/09/19 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Ar_Intel_Tank(struct TANK *t)
{
uint8 i;
i=rand()%256;
if(i>64)
{
t->Button__Down_Flg=1;
}
if(i>240)
{
t->Send_Shot_Flg=1;
}
if(i<40)
{
if(t->Position[0]%2==0&&t->Position[1]%2==0)
{
i=rand()%256;
if(t->Position[0]==0) //随机控制坦克方向概率-坦克游戏横坐标为0时,各种方向概率
{
if(i<=4)
{
t->Direction=Up;
}
if(i>4&&i<=192)
{
t->Direction=Down;
}
if(i>192&&i<=224)
{
t->Direction=Left;
}
if(i>224)
{
t->Direction=Right;
}
}
if(t->Position[0]==28) //随机控制坦克方向概率-坦克游戏横坐标为28时,各种方向概率
{
if(i<=188)
{
t->Direction=Up;
}
if(i>188&&i<=192)
{
t->Direction=Down;
}
if(i>192&&i<=224)
{
t->Direction=Left;
}
if(i>224)
{
t->Direction=Right;
}
}
if(t->Position[1]==0) //随机控制坦克方向概率-坦克游戏纵坐标为0时,各种方向概率
{
if(i<=32)
{
t->Direction=Up;
}
if(i>32&&i<=64)
{
t->Direction=Down;
}
if(i>64&&i<=68)
{
t->Direction=Left;
}
if(i>68)
{
t->Direction=Right;
}
}
if(t->Position[1]==60) //随机控制坦克方向概率-坦克游戏纵坐标为60时,各种方向概率
{
if(i<=32)
{
t->Direction=Up;
}
if(i>32&&i<=64)
{
t->Direction=Down;
}
if(i>64&&i<=252)
{
t->Direction=Left;
}
if(i>252)
{
t->Direction=Right;
}
}
else //随机控制坦克方向概率-坦克位于中间区域时,各种方向概率
{
if(i<=64)
{
t->Direction=Up;
}
if(i>64&&i<=128)
{
t->Direction=Down;
}
if(i>128&&i<=192)
{
t->Direction=Left;
}
if(i>192)
{
t->Direction=Right;
}
}
}
}
}
/* *************************************************************************************************
* Function Name : Tank_Wall_Check *
* Description : 坦克碰壁检测 *
* Date : 09/09/19 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Tank_Wall_Check(struct TANK *t)
{
uint8 barrier_number[2]=0;
uint8 barrier_position[2];
uint8 barrier_length=0;
uint8 barrier_width=0;
uint8 barrier_exist[2];
uint8 i,j;
Get_Nearest_Barrier(t->Position,t->Direction,4,4,barrier_number);
switch(t->Direction)
{
case Up:
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
if(t->Position[0]==0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
if(barrier_number[1]==0)
{
if(t->Position[0]<=barrier_position[0]+barrier_width)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<2;j++)
{
if(t->Position[1]==barrier_position[1]+barrier_length*j-2&&t->Position[0]==barrier_position[0]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j*(barrier_length/2-1)))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
if(barrier_length<4)
{
return;
}
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<1+(barrier_length-4)/2;j++)
{
if(t->Position[1]==barrier_position[1]+j*2&&t->Position[0]==barrier_position[0]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j))!=0||(barrier_exist[0]&1<<((barrier_length/2)*i+j+1))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Position[0]<=barrier_position[0]+barrier_width)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
for(i=0;i<barrier_width/2;i++)
{
if(t->Position[0]==barrier_position[0]+2+i*2)
{
if(t->Position[1]>barrier_position[1])
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0||(barrier_exist[1]&1<<((barrier_length/2)*i))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}else
{
if((barrier_exist[1]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0||(barrier_exist[0]&1<<((barrier_length/2)*i))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
}
}
break;
case Down:
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
if(t->Position[0]==28)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
if(barrier_number[1]==0)
{
if(t->Position[0]>=barrier_position[0]-4)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<2;j++)
{
if(t->Position[1]==barrier_position[1]+barrier_length*j-2&&t->Position[0]==barrier_position[0]-4+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j*(barrier_length/2-1)))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
if(barrier_length<4)
{
return;
}
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<1+(barrier_length-4)/2;j++)
{
if(t->Position[1]==barrier_position[1]+j*2&&t->Position[0]==barrier_position[0]-4+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j))!=0||(barrier_exist[0]&1<<((barrier_length/2)*i+j+1))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Position[0]>=barrier_position[0]-4)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
for(i=0;i<barrier_width/2;i++)
{
if(t->Position[0]==barrier_position[0]-4+i*2)
{
if(t->Position[1]>barrier_position[1])
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0||(barrier_exist[1]&1<<((barrier_length/2)*i))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}else
{
if((barrier_exist[1]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0||(barrier_exist[0]&1<<((barrier_length/2)*i))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
}
}
break;
case Left:
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
if(t->Position[1]==0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
if(barrier_number[1]==0)
{
if(t->Position[1]<=barrier_position[1]+barrier_length)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<2;j++)
{
if(t->Position[0]==barrier_position[0]+barrier_width*j-2&&t->Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[0]&1<<(j*(barrier_length/2)*(barrier_width/2-1)+i))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
if(barrier_width<4)
{
return;
}
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<1+(barrier_width-4)/2;j++)
{
if(t->Position[0]==barrier_position[0]+j*2&&t->Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*j+i))!=0||(barrier_exist[0]&1<<((barrier_length/2)*(j+1)+i))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Position[1]<=barrier_position[1]+barrier_length)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
for(i=0;i<barrier_length/2;i++)
{
if(t->Position[1]==barrier_position[1]+2+i*2)
{
if(t->Position[0]<barrier_position[0])
{
if((barrier_exist[0]&1<<i)!=0||(barrier_exist[1]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}else
{
if((barrier_exist[1]&1<<i)!=0||(barrier_exist[0]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
}
}
break;
case Right:
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
if(t->Position[1]==60)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
if(barrier_number[1]==0)
{
if(t->Position[1]>=barrier_position[1]-4)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<2;j++)
{
if(t->Position[0]==barrier_position[0]+barrier_width*j-2&&t->Position[1]==barrier_position[1]-4+i*2)
{
if((barrier_exist[0]&1<<(j*(barrier_length/2)*(barrier_width/2-1)+i))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
if(barrier_width<4)
{
return;
}
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<1+(barrier_width-4)/2;j++)
{
if(t->Position[0]==barrier_position[0]+j*2&&t->Position[1]==barrier_position[1]-4+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*j+i))!=0||(barrier_exist[0]&1<<((barrier_length/2)*(j+1)+i))!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Position[1]>=barrier_position[1]-4)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
for(i=0;i<barrier_length/2;i++)
{
if(t->Position[1]==barrier_position[1]-4+i*2)
{
if(t->Position[0]<barrier_position[0])
{
if((barrier_exist[0]&1<<i)!=0||(barrier_exist[1]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}else
{
if((barrier_exist[1]&1<<i)!=0||(barrier_exist[0]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
t->Tank_Bounce_Wall_Flg=1;
return;
}
}
}
}
}
}
break;
}
}
/* ************************************************************************************************
* Function Name : Tank_Tank_Check *
* Description : 坦克碰坦克检测 *
* Date : 09/10/1 *
* Parameter : 指向坦克结构体的指针 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void Tank_Tank_Check(struct TANK *t)
{
uint8 tank_number=0;
uint8 tank_position[2];
switch(t->Direction)
{
case Up:
tank_number=Get_Nearest_Tank(t->Position,t->Direction,4,4);
Get_Tank_Position(tank_number,tank_position);
if(tank_number!=0&&t->Position[0]==tank_position[0]+4)
{
t->Tank_Bounce_Tank_Flg=1;
return;
}
break;
case Down:
tank_number=Get_Nearest_Tank(t->Position,t->Direction,4,4);
Get_Tank_Position(tank_number,tank_position);
if(tank_number!=0&&t->Position[0]+4==tank_position[0])
{
t->Tank_Bounce_Tank_Flg=1;
return;
}
break;
case Left:
tank_number=Get_Nearest_Tank(t->Position,t->Direction,4,4);
Get_Tank_Position(tank_number,tank_position);
if(tank_number!=0&&t->Position[1]==tank_position[1]+4)
{
t->Tank_Bounce_Tank_Flg=1;
return;
}
break;
case Right:
tank_number=Get_Nearest_Tank(t->Position,t->Direction,4,4);
Get_Tank_Position(tank_number,tank_position);
if(tank_number!=0&&t->Position[1]+4==tank_position[1])
{
t->Tank_Bounce_Tank_Flg=1;
return;
}
break;
}
}
/* ************************************************************************************************
* Function Name : Tank_Home_Check *
* Description : 坦克碰基地检测 *
* Date : 09/10/2 *
* Parameter : 指向坦克结构体的指针 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void Tank_Home_Check(struct TANK *t)
{
switch(t->Direction)
{
case Up:
if(t->Position[1]+4>60&&t->Position[0]==18)
{
t->Tank_Bounce_Home_Flg=1;
}
break;
case Down:
if(t->Position[1]+4>60&&t->Position[0]+4==14)
{
t->Tank_Bounce_Home_Flg=1;
}
break;
case Right:
if(t->Position[0]+4>14&&t->Position[0]<18&&t->Position[1]+4==60)
{
t->Tank_Bounce_Home_Flg=1;
}
break;
}
}
/* ************************************************************************************************
* Function Name : Tank_Advance *
* Description : 坦克行进函数 *
* Date : 09/10/1 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Tank_Advance(struct TANK *t)
{
switch(t->Direction)
{
case Up: t->Position[0]--;break;
case Down: t->Position[0]++;break;
case Left: t->Position[1]--;break;
case Right: t->Position[1]++;break;
}
}
/* ************************************************************************************************
* Function Name : Display_Tank *
* Description : 显示坦克 *
* Date : 09/09/19 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Display_Tank(struct TANK *t,uint8 *temp)
{
uint8 i=0;
uint8 j=0;
if(t->Level==1&&t->Camp==Human)
{
switch(t->Direction)
{
case Up: Copy_Array(temp,Human_Tank1_Up,8);break;
case Left: Copy_Array(temp,Human_Tank1_Left,8);break;
case Down: Copy_Array(temp,Human_Tank1_Down,8);break;
case Right:Copy_Array(temp,Human_Tank1_Right,8);break;
}
}
if(t->Level==2&&t->Camp==Human)
{
switch(t->Direction)
{
case Up: Copy_Array(temp,Human_Tank2_Up,8);break;
case Left: Copy_Array(temp,Human_Tank2_Left,8);break;
case Down: Copy_Array(temp,Human_Tank2_Down,8);break;
case Right:Copy_Array(temp,Human_Tank2_Right,8);break;
}
}
if(t->Level==3&&t->Camp==Human)
{
switch(t->Direction)
{
case Up: Copy_Array(temp,Human_Tank3_Up,8);break;
case Left: Copy_Array(temp,Human_Tank3_Left,8);break;
case Down: Copy_Array(temp,Human_Tank3_Down,8);break;
case Right:Copy_Array(temp,Human_Tank3_Right,8);break;
}
}
if(t->Level==1&&t->Camp==Computer)
{
switch(t->Direction)
{
case Up: Copy_Array(temp,Computer_Tank1_Up,8);break;
case Left: Copy_Array(temp,Computer_Tank1_Left,8);break;
case Down: Copy_Array(temp,Computer_Tank1_Down,8);break;
case Right:Copy_Array(temp,Computer_Tank1_Right,8);break;
}
}
if(t->Level==2&&t->Camp==Computer)
{
switch(t->Direction)
{
case Up: Copy_Array(temp,Computer_Tank2_Up,8);break;
case Left: Copy_Array(temp,Computer_Tank2_Left,8);break;
case Down: Copy_Array(temp,Computer_Tank2_Down,8);break;
case Right:Copy_Array(temp,Computer_Tank2_Right,8);break;
}
}
if(t->Level==3&&t->Camp==Computer)
{
switch(t->Direction)
{
case Up: Copy_Array(temp,Computer_Tank3_Up,8);break;
case Left: Copy_Array(temp,Computer_Tank3_Left,8);break;
case Down: Copy_Array(temp,Computer_Tank3_Down,8);break;
case Right:Copy_Array(temp,Computer_Tank3_Right,8);break;
}
}
Change_Picture(t->Position[0]%4,temp);
if(t->Position[0]!=28||t->Position[0]%4!=0)
{
for(i=0;i<2;i++)
{
for(j=0;j<8;j++)
{
Add_Points(t->Position[0]/4+i,t->Position[1]*2+j,temp[i*8+j]);
}
}
}else
for(j=0;j<8;j++)
{
Add_Points(t->Position[0]/4,t->Position[1]*2+j,temp[j]);
}
}
/* *************************************************************************************************
* Function Name :Delete_Tank_Tail *
* Description :去除坦克残像 *
* Date : 09/09/19 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Delete_Tank_Tail(struct TANK *t,uint8 *temp)
{
uint8 i=0;
uint8 j=0;
if(t->Position[0]!=28||t->Position[0]%4!=0)
{
for(i=0;i<2;i++)
{
for(j=0;j<8;j++)
{
Reduce_Points(t->Position[0]/4+i,t->Position[1]*2+j,temp[i*8+j]);
}
}
}else
for(j=0;j<8;j++)
{
Reduce_Points(t->Position[0]/4,t->Position[1]*2+j,temp[j]);
}
}
/* *************************************************************************************************
* Function Name :Replace_Shot *
* Description :初始化炮弹数据 *
* Date : 09/09/25 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Replace_Shot(struct TANK *t)
{
switch(t->Direction)
{
case Up:
t->Shot_Position[0]=t->Position[0]+1;
t->Shot_Position[1]=t->Position[1]+1;
break;
case Down:
t->Shot_Position[0]=t->Position[0]+2;
t->Shot_Position[1]=t->Position[1]+1;
break;
case Left:
t->Shot_Position[0]=t->Position[0]+1;
t->Shot_Position[1]=t->Position[1]+1;
break;
case Right:
t->Shot_Position[0]=t->Position[0]+1;
t->Shot_Position[1]=t->Position[1]+2;
break;
}
t->Shot_Direction=t->Direction;
}
/* *************************************************************************************************
* Function Name :Shot_Wall_Check *
* Description :炮弹碰壁检测函数 *
* Date : 09/09/22.23 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Shot_Wall_Check(struct TANK *t)
{
uint8 barrier_number[2]=0;
uint8 barrier_exist[2]=0xff;
uint8 barrier_position[2];
uint8 barrier_length=0;
uint8 barrier_width=0;
uint8 i,j;
switch(t->Shot_Direction)
{
case Up:
if(t->Shot_Position[0]==0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
Get_Nearest_Barrier(t->Shot_Position,t->Shot_Direction,2,1,barrier_number);
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
if(barrier_number[1]==0)
{
if(t->Shot_Position[0]<=barrier_position[0]+barrier_width)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<2;j++)
{
if(t->Shot_Position[1]==barrier_position[1]+barrier_length*j-1&&t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j*(barrier_length/2-1)))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
if(barrier_length<4)
{
t->Shot_Position[0]--;
return;
}
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<1+(barrier_length-4)/2;j++)
{
if(t->Shot_Position[1]==barrier_position[1]+j*2+1&&t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j))!=0||(barrier_exist[0]&1<<((barrier_length/2)*i+j+1))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Shot_Position[0]<=barrier_position[0]+barrier_width)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
if(t->Shot_Position[1]>barrier_position[1])
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0||(barrier_exist[1]&1<<((barrier_length/2)*i))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}else
{
if((barrier_exist[1]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0||(barrier_exist[0]&1<<((barrier_length/2)*i))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
}
}t->Shot_Position[0]--;
break;
case Left:
if(t->Shot_Position[1]==0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
Get_Nearest_Barrier(t->Shot_Position,t->Shot_Direction,1,2,barrier_number);
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
if(barrier_number[1]==0)
{
if(t->Shot_Position[1]<=barrier_position[1]+barrier_length)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<2;j++)
{
if(t->Shot_Position[0]==barrier_position[0]+barrier_width*j-1&&t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[0]&1<<(j*(barrier_length/2)*(barrier_width/2-1)+i))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
if(barrier_width<4)
{
t->Shot_Position[1]--;
return;
}
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<1+(barrier_width-4)/2;j++)
{
if(t->Shot_Position[0]==barrier_position[0]+j*2+1&&t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*j+i))!=0||(barrier_exist[0]&1<<((barrier_length/2)*(j+1)+i))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Shot_Position[1]<=barrier_position[1]+barrier_length)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
if(t->Shot_Position[0]<barrier_position[0])
{
if((barrier_exist[0]&1<<i)!=0||(barrier_exist[1]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}else
{
if((barrier_exist[1]&1<<i)!=0||(barrier_exist[0]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
}
}t->Shot_Position[1]--;
break;
case Right:
if(t->Shot_Position[1]==63)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
Get_Nearest_Barrier(t->Shot_Position,t->Shot_Direction,1,2,barrier_number);
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
if(barrier_number[1]==0)
{
if(t->Shot_Position[1]>=barrier_position[1]-1)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<2;j++)
{
if(t->Shot_Position[0]==barrier_position[0]+barrier_width*j-1&&t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
if((barrier_exist[0]&1<<(j*(barrier_length/2)*(barrier_width/2-1)+i))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
if(barrier_width<4)
{
t->Shot_Position[1]++;
return;
}
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<1+(barrier_width-4)/2;j++)
{
if(t->Shot_Position[0]==barrier_position[0]+j*2+1&&t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*j+i))!=0||(barrier_exist[0]&1<<((barrier_length/2)*(j+1)+i))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Shot_Position[1]>=barrier_position[1]-1)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
if(t->Shot_Position[0]<barrier_position[0])
{
if((barrier_exist[0]&1<<i)!=0||(barrier_exist[1]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}else
{
if((barrier_exist[1]&1<<i)!=0||(barrier_exist[0]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
}
}t->Shot_Position[1]++;
break;
case Down:
if(t->Shot_Position[0]==31)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
Get_Nearest_Barrier(t->Shot_Position,t->Shot_Direction,2,1,barrier_number);
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
if(barrier_number[1]==0)
{
if(t->Shot_Position[0]>=barrier_position[0]-1)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<2;j++)
{
if(t->Shot_Position[1]==barrier_position[1]+barrier_length*j-1&&t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j*(barrier_length/2-1)))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
if(barrier_length<4)
{
t->Shot_Position[0]++;
return;
}
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<1+(barrier_length-4)/2;j++)
{
if(t->Shot_Position[1]==barrier_position[1]+j*2+1&&t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j))!=0||(barrier_exist[0]&1<<((barrier_length/2)*i+j+1))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Shot_Position[0]>=barrier_position[0]-1)
{
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
if(t->Shot_Position[1]>barrier_position[1])
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0||(barrier_exist[1]&1<<((barrier_length/2)*i))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}else
{
if((barrier_exist[1]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0||(barrier_exist[0]&1<<((barrier_length/2)*i))!=0)
{
t->Shot_Bounce_Wall_Flg=1;
t->Send_Shot_Flg=0;
return;
}
}
}
}
}
}t->Shot_Position[0]++;
break;
}
}
/* *************************************************************************************************
* Function Name :Shot_Tank_Check *
* Description :炮弹碰坦克检测函数 *
* Date : 09/09/30 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Shot_Tank_Check(struct TANK *t)
{
uint8 tank_number=0;
uint8 tank_position[2];
switch(t->Shot_Direction)
{
case Up:
tank_number=Get_Nearest_Tank(t->Shot_Position,t->Shot_Direction,2,1);
Get_Tank_Position(tank_number,tank_position);
if(tank_number!=0&&t->Shot_Position[0]==tank_position[0]+4)
{
t->Shot_Bounce_Tank_Flg=1;
t->Send_Shot_Flg=0;
return;
}
break;
case Down:
tank_number=Get_Nearest_Tank(t->Shot_Position,t->Shot_Direction,2,1);
Get_Tank_Position(tank_number,tank_position);
if(tank_number!=0&&t->Shot_Position[0]==tank_position[0]-1)
{
t->Shot_Bounce_Tank_Flg=1;
t->Send_Shot_Flg=0;
return;
}
break;
case Left:
tank_number=Get_Nearest_Tank(t->Shot_Position,t->Shot_Direction,1,2);
Get_Tank_Position(tank_number,tank_position);
if(tank_number!=0&&t->Shot_Position[1]==tank_position[1]+4)
{
t->Shot_Bounce_Tank_Flg=1;
t->Send_Shot_Flg=0;
return;
}
break;
case Right:
tank_number=Get_Nearest_Tank(t->Shot_Position,t->Shot_Direction,1,2);
Get_Tank_Position(tank_number,tank_position);
if(tank_number!=0&&t->Shot_Position[1]==tank_position[1]-1)
{
t->Shot_Bounce_Tank_Flg=1;
t->Send_Shot_Flg=0;
return;
}
break;
}
}
/* *************************************************************************************************
* Function Name :Shot_Shot_Check *
* Description :炮弹碰炮弹检测并处理函数 *
* Date : 09/10/1 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Shot_Shot_Check(struct TANK *t)
{
uint8 shot_position[2];
uint8 shot_direction;
uint8 i;
uint8 j=0;
uint8 tank_number=0;
for(i=1;i<Tank_Count+1;i++)
{
if( (i==1&&Tank1.Exist==1) ||(i==2&&Tank2.Exist==1) )
{
Get_Tank_Shot_Quality (i,shot_position,&shot_direction);
switch(t->Shot_Direction)
{
case Up:
if(shot_direction==Down)
{
if(t->Shot_Position[1]==shot_position[1]&&t->Shot_Position[0]==shot_position[0]+1)
{
j=1;tank_number=i;
}
}
if(shot_direction==Left||shot_direction==Right)
{
if((t->Shot_Position[1]==shot_position[1]-1||t->Shot_Position[1]==shot_position[1])&&t->Shot_Position[0]==shot_position[0]+1)
{
j=1;tank_number=i;
}
}
break;
case Down:
if(shot_direction==Up)
{
if(t->Shot_Position[1]==shot_position[1]&&t->Shot_Position[0]==shot_position[0]-1)
{
j=1;tank_number=i;
}
}
if(shot_direction==Left||shot_direction==Right)
{
if((t->Shot_Position[1]==shot_position[1]-1||t->Shot_Position[1]==shot_position[1])&&t->Shot_Position[0]==shot_position[0])
{
j=1;tank_number=i;
}
}
case Left:
if(shot_direction==Right)
{
if(t->Shot_Position[1]==shot_position[1]+1&&t->Shot_Position[0]==shot_position[0])
{
j=1;tank_number=i;
}
}
if(shot_direction==Up||shot_direction==Down)
{
if(t->Shot_Position[1]==shot_position[1]+1&&(t->Shot_Position[0]==shot_position[0]||t->Shot_Position[0]==shot_position[0]-1))
{
j=1;tank_number=i;
}
}
break;
case Right:
if(shot_direction==Left)
{
if(t->Shot_Position[1]==shot_position[1]-1&&t->Shot_Position[0]==shot_position[0])
{
j=1;tank_number=i;
}
}
if(shot_direction==Up||shot_direction==Down)
{
if(t->Shot_Position[1]==shot_position[1]&&(t->Shot_Position[0]==shot_position[0]||t->Shot_Position[0]==shot_position[0]-1))
{
j=1;tank_number=i;
}
}
break;
}
if(j==1)
{
t->Send_Shot_Flg=0;
Delete_Shot(t->Shot_Direction,t->Shot_Position);
switch(tank_number)
{
case 1:Delete_Shot(Tank1.Shot_Direction,Tank1.Shot_Position);Tank1.Send_Shot_Flg=0;break;
case 2:Delete_Shot(Tank2.Shot_Direction,Tank2.Shot_Position);Tank2.Send_Shot_Flg=0;break;
}
}
}
}
}
/* *************************************************************************************************
* Function Name :Shot_Home_Check *
* Description :炮弹碰基地检测并处理函数 *
* Date : 09/10/2 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Shot_Home_Check(struct TANK *t)
{
uint8 j=0;
switch(t->Shot_Direction)
{
case Up:
if(t->Shot_Position[1]>58-1&&t->Shot_Position[0]==18)
{
j=1;
}
break;
case Down:
if(t->Shot_Position[1]>58-1&&t->Shot_Position[0]==13)
{
j=1;
}
break;
case Right:
if(t->Shot_Position[0]>=13&&t->Shot_Position[0]<=18&&t->Shot_Position[1]==59)
{
j=1;
}
break;
}
if(j==1)
{
t->Send_Shot_Flg=0;
Delete_Shot(t->Shot_Direction,t->Shot_Position);
}
}
/* *************************************************************************************************
* Function Name :Display_Shot *
* Description :显示炮弹 *
* Date : 09/09/24 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Display_Shot(struct TANK *t)
{
if(t->Shot_Direction==Left||t->Shot_Direction==Right)
{
Creat_Point((t->Shot_Position[0]*2)+1,t->Shot_Position[1]*2);
Creat_Point((t->Shot_Position[0]*2)+1,t->Shot_Position[1]*2+1);
Creat_Point((t->Shot_Position[0]*2)+2,t->Shot_Position[1]*2);
Creat_Point((t->Shot_Position[0]*2)+2,t->Shot_Position[1]*2+1);
}
if(t->Shot_Direction==Up||t->Shot_Direction==Down)
{
Creat_Point((t->Shot_Position[0]*2),t->Shot_Position[1]*2+1);
Creat_Point((t->Shot_Position[0]*2),t->Shot_Position[1]*2+2);
Creat_Point((t->Shot_Position[0]*2)+1,t->Shot_Position[1]*2+1);
Creat_Point((t->Shot_Position[0]*2)+1,t->Shot_Position[1]*2+2);
}
}
/* *************************************************************************************************
* Function Name :Delete_Shot_Tail *
* Description :去除炮弹残像 *
* Date : 09/09/24 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Delete_Shot_Tail(struct TANK *t)
{
switch(t->Shot_Direction)
{
case Right:
if(t->Shot_Position[1]>t->Position[1]+4)
{
Delete_Point((t->Shot_Position[0]*2)+1,t->Shot_Position[1]*2-2);
Delete_Point((t->Shot_Position[0]*2)+1,t->Shot_Position[1]*2-1);
Delete_Point((t->Shot_Position[0]*2)+2,t->Shot_Position[1]*2-2);
Delete_Point((t->Shot_Position[0]*2)+2,t->Shot_Position[1]*2-1);
}
break;
case Down:
if(t->Shot_Position[0]>t->Position[0]+4)
{
Delete_Point((t->Shot_Position[0]*2)-2,t->Shot_Position[1]*2+1);
Delete_Point((t->Shot_Position[0]*2)-2,t->Shot_Position[1]*2+2);
Delete_Point((t->Shot_Position[0]*2)-1,t->Shot_Position[1]*2+1);
Delete_Point((t->Shot_Position[0]*2)-1,t->Shot_Position[1]*2+2);
}
break;
case Up:
if(t->Shot_Position[0]<t->Position[0]-1)
{
if(t->Position[0]!=0)
{
Delete_Point((t->Shot_Position[0]*2)+3,t->Shot_Position[1]*2+1);
Delete_Point((t->Shot_Position[0]*2)+3,t->Shot_Position[1]*2+2);
Delete_Point((t->Shot_Position[0]*2)+2,t->Shot_Position[1]*2+1);
Delete_Point((t->Shot_Position[0]*2)+2,t->Shot_Position[1]*2+2);
}
}
break;
case Left:
if(t->Shot_Position[1]<t->Position[1]-1)
{
if(t->Position[1]!=0)
{
Delete_Point((t->Shot_Position[0]*2)+1,t->Shot_Position[1]*2+2);
Delete_Point((t->Shot_Position[0]*2)+1,t->Shot_Position[1]*2+3);
Delete_Point((t->Shot_Position[0]*2)+2,t->Shot_Position[1]*2+2);
Delete_Point((t->Shot_Position[0]*2)+2,t->Shot_Position[1]*2+3);
}
}
break;
}
}
/* *************************************************************************************************
* Function Name :Delete_Shot *
* Description :无视条件去除炮弹残像 *
* Date : 09/09/30 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Delete_Shot(uint8 shot_direction,uint8 *shot_position)
{
if(shot_direction==Left||shot_direction==Right)
{
Delete_Point(((*shot_position)*2)+1,(*(shot_position+1))*2);
Delete_Point(((*shot_position)*2)+1,(*(shot_position+1))*2+1);
Delete_Point(((*shot_position)*2)+2,(*(shot_position+1))*2);
Delete_Point(((*shot_position)*2)+2,(*(shot_position+1))*2+1);
}
if(shot_direction==Up||shot_direction==Down)
{
Delete_Point(((*shot_position)*2),(*(shot_position+1))*2+1);
Delete_Point(((*shot_position)*2),(*(shot_position+1))*2+2);
Delete_Point(((*shot_position)*2)+1,(*(shot_position+1))*2+1);
Delete_Point(((*shot_position)*2)+1,(*(shot_position+1))*2+2);
}
}
/** *************************************************************************************************
* Function Name :Shot_Effect *
* Description :炮弹碰壁影响函数 *
* Date : 09/09/25 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Shot_Bounce_Wall_Effect(struct TANK *t)
{
uint8 barrier_number[2]=0;
uint8 barrier_exist[2];
uint8 barrier_position[2];
uint8 barrier_length=0;
uint8 barrier_width=0;
uint8 barrier_property=0;
uint8 xdata i, xdata j;
Shot_Disappear(t->Shot_Direction,t->Shot_Position,t->Position);
switch(t->Shot_Direction)
{
case Up:
if(t->Position[0]>0)
{
Get_Nearest_Barrier(t->Shot_Position,t->Shot_Direction,2,1,barrier_number);
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[0],&barrier_property);
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
if(barrier_number[1]==0&&barrier_property==Brick)
{
if(t->Shot_Position[1]<barrier_position[1])
{
Shot_Break(t->Shot_Position,Up_Right);
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
barrier_exist[0]=~(~barrier_exist[0]|1<<(barrier_length/2)*i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}else if(t->Shot_Position[1]==barrier_position[1]+barrier_length-1)
{
Shot_Break(t->Shot_Position,Up_Left);
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
barrier_exist[0]=~(~barrier_exist[0]|1<<(barrier_length/2)*i+(barrier_length/2)-1);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}else
{
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<1+(barrier_length-4)/2;j++)
{
if(t->Shot_Position[1]==barrier_position[1]+j*2+1&&t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j))!=0)
{
Shot_Break(t->Shot_Position,Up_Left);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*i+j));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
if((barrier_exist[0]&1<<((barrier_length/2)*i+j+1))!=0)
{
Shot_Break(t->Shot_Position,Up_Right);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*i+j+1));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Shot_Position[1]>barrier_position[1])
{
if(barrier_property==Brick)
{
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0)
{
Shot_Break(t->Shot_Position,Up_Left);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*i+(barrier_length/2-1)));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
Get_Barrier_Quality(barrier_number[1],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[1],&barrier_property);
if(barrier_property==Brick)
{
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
if((barrier_exist[1]&1<<((barrier_length/2)*i))!=0)
{
Shot_Break(t->Shot_Position,Up_Right);
barrier_exist[1]=~(~barrier_exist[1]|1<<((barrier_length/2)*i));
Write_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
}
}
}
}
}
else
{
if(barrier_property==Brick)
{
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i))!=0)
{
Shot_Break(t->Shot_Position,Up_Right);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*i));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
Get_Barrier_Quality(barrier_number[1],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[1],&barrier_property);
if(barrier_property==Brick)
{
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]+2+i*2)
{ if((barrier_exist[1]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0)
{
Shot_Break(t->Shot_Position,Up_Left);
barrier_exist[1]=~(~barrier_exist[1]|1<<((barrier_length/2)*i+(barrier_length/2-1)));
Write_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
}
}
}
}
}
}
}break;
case Down:
if(t->Position[0]<31)
{
Get_Nearest_Barrier(t->Shot_Position,t->Shot_Direction,2,1,barrier_number);
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[0],&barrier_property);
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
if(barrier_number[1]==0&&barrier_property==Brick)
{
if(t->Shot_Position[1]<barrier_position[1])
{
Shot_Break(t->Shot_Position,Down_Right);
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
barrier_exist[0]=~(~barrier_exist[0]|1<<(barrier_length/2)*i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}else if(t->Shot_Position[1]==barrier_position[1]+barrier_length-1)
{
Shot_Break(t->Shot_Position,Down_Left);
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
barrier_exist[0]=~(~barrier_exist[0]|1<<(barrier_length/2)*i+(barrier_length/2)-1);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}else
{
for(i=0;i<barrier_width/2;i++)
{
for(j=0;j<1+(barrier_length-4)/2;j++)
{
if(t->Shot_Position[1]==barrier_position[1]+j*2+1&&t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+j))!=0)
{
Shot_Break(t->Shot_Position,Down_Left);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*i+j));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
if((barrier_exist[0]&1<<((barrier_length/2)*i+j+1))!=0)
{
Shot_Break(t->Shot_Position,Down_Right);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*i+j+1));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Shot_Position[1]>barrier_position[1])
{
if(barrier_property==Brick)
{
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0)
{
Shot_Break(t->Shot_Position,Down_Left);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*i+(barrier_length/2-1)));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
Get_Barrier_Quality(barrier_number[1],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[1],&barrier_property);
if(barrier_property==Brick)
{
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
if((barrier_exist[1]&1<<((barrier_length/2)*i))!=0)
{
Shot_Break(t->Shot_Position,Down_Right);
barrier_exist[1]=~(~barrier_exist[1]|1<<((barrier_length/2)*i));
Write_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
}
}
}
}
}
else
{
if(barrier_property==Brick)
{
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*i))!=0)
{
Shot_Break(t->Shot_Position,Down_Right);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*i));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
Get_Barrier_Quality(barrier_number[1],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[1],&barrier_property);
if(barrier_property==Brick)
{
for(i=0;i<barrier_width/2;i++)
{
if(t->Shot_Position[0]==barrier_position[0]-1+i*2)
{
if((barrier_exist[1]&1<<((barrier_length/2)*i+(barrier_length/2-1)))!=0)
{
Shot_Break(t->Shot_Position,Down_Left);
barrier_exist[1]=~(~barrier_exist[1]|1<<((barrier_length/2)*i+(barrier_length/2-1)));
Write_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
}
}
}
}
}
}
}break;
case Left:
if(t->Position[1]>0)
{
Get_Nearest_Barrier(t->Shot_Position,t->Shot_Direction,1,2,barrier_number);
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[0],&barrier_property);
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
if(barrier_number[1]==0&&barrier_property==Brick)
{
if(t->Shot_Position[0]<barrier_position[0])
{
Shot_Break(t->Shot_Position,Left_Down);
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
barrier_exist[0]=~(~barrier_exist[0]|1<<i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}else if(t->Shot_Position[0]==barrier_position[0]+barrier_width-1)
{
Shot_Break(t->Shot_Position,Left_Up);
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_width/2)-1)*(barrier_length/2)+i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}else
{
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<1+(barrier_width-4)/2;j++)
{
if(t->Shot_Position[0]==barrier_position[0]+j*2+1&&t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*(j+1)+i))!=0)
{
Shot_Break(t->Shot_Position,Left_Down);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*(j+1)+i));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
if((barrier_exist[0]&1<<((barrier_length/2)*j+i))!=0)
{
Shot_Break(t->Shot_Position,Left_Up);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*j+i));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Shot_Position[0]<barrier_position[0])
{
if(barrier_property==Brick)
{
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[0]&1<<i)!=0)
{
Shot_Break(t->Shot_Position,Left_Down);
barrier_exist[0]=~(~barrier_exist[0]|1<<i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
Get_Barrier_Quality(barrier_number[1],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[1],&barrier_property);
if(barrier_property==Brick)
{
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[1]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
Shot_Break(t->Shot_Position,Left_Up);
barrier_exist[1]=~(~barrier_exist[1]|1<<((barrier_width/2)-1)*(barrier_length/2)+i);
Write_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
}
}
}
}
}
else
{
if(barrier_property==Brick)
{
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[0]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
Shot_Break(t->Shot_Position,Left_Up);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_width/2)-1)*(barrier_length/2)+i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
Get_Barrier_Quality(barrier_number[1],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[1],&barrier_property);
if(barrier_property==Brick)
{
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]+2+i*2)
{
if((barrier_exist[1]&1<<i)!=0)
{
Shot_Break(t->Shot_Position,Left_Down);
barrier_exist[1]=~(~barrier_exist[1]|1<<i);
Write_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
}
}
}
}
}
}
}break;
case Right:
if(t->Position[1]<63)
{
Get_Nearest_Barrier(t->Shot_Position,t->Shot_Direction,1,2,barrier_number);
Get_Barrier_Quality(barrier_number[0],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[0],&barrier_property);
Read_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
Read_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
if(barrier_number[1]==0&&barrier_property==Brick)
{
if(t->Shot_Position[0]<barrier_position[0])
{
Shot_Break(t->Shot_Position,Right_Down);
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
barrier_exist[0]=~(~barrier_exist[0]|1<<i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}else if(t->Shot_Position[0]==barrier_position[0]+barrier_width-1)
{
Shot_Break(t->Shot_Position,Right_Up);
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_width/2)-1)*(barrier_length/2)+i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}else
{
for(i=0;i<barrier_length/2;i++)
{
for(j=0;j<1+(barrier_width-4)/2;j++)
{
if(t->Shot_Position[0]==barrier_position[0]+j*2+1&&t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
if((barrier_exist[0]&1<<((barrier_length/2)*(j+1)+i))!=0)
{
Shot_Break(t->Shot_Position,Right_Down);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*(j+1)+i));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
if((barrier_exist[0]&1<<((barrier_length/2)*j+i))!=0)
{
Shot_Break(t->Shot_Position,Right_Up);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_length/2)*j+i));
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
}
}
if(barrier_number[1]!=0)
{
if(t->Shot_Position[0]<barrier_position[0])
{
if(barrier_property==Brick)
{
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
if((barrier_exist[0]&1<<i)!=0)
{
Shot_Break(t->Shot_Position,Right_Down);
barrier_exist[0]=~(~barrier_exist[0]|1<<i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
Get_Barrier_Quality(barrier_number[1],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[1],&barrier_property);
if(barrier_property==Brick)
{
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
if((barrier_exist[1]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
Shot_Break(t->Shot_Position,Right_Up);
barrier_exist[1]=~(~barrier_exist[1]|1<<((barrier_width/2)-1)*(barrier_length/2)+i);
Write_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
}
}
}
}
}
else
{
if(barrier_property==Brick)
{
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
if((barrier_exist[0]&1<<((barrier_width/2)-1)*(barrier_length/2)+i)!=0)
{
Shot_Break(t->Shot_Position,Right_Up);
barrier_exist[0]=~(~barrier_exist[0]|1<<((barrier_width/2)-1)*(barrier_length/2)+i);
Write_Barrier_Exist(barrier_number[0],&barrier_exist[0]);
}
}
}
}
Get_Barrier_Quality(barrier_number[1],barrier_position,&barrier_length,&barrier_width);
Get_Barrier_Property(barrier_number[1],&barrier_property);
if(barrier_property==Brick)
{
for(i=0;i<barrier_length/2;i++)
{
if(t->Shot_Position[1]==barrier_position[1]-1+i*2)
{
if((barrier_exist[1]&1<<i)!=0)
{
Shot_Break(t->Shot_Position,Right_Down);
barrier_exist[1]=~(~barrier_exist[1]|1<<i);
Write_Barrier_Exist(barrier_number[1],&barrier_exist[1]);
}
}
}
}
}
}
}break;
}
}
/****************************************************************************************************
* Function Name :Shot_Bounce_Tank_Effect *
* Description :炮弹碰坦克影响函数 *
* Date : 09/09/30 *
* Parameter :指向坦克结构体的指针 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Shot_Bounce_Tank_Effect(struct TANK *t)
{
uint8 tank_number;
uint8 camp;
uint8 level;
uint8 life;
uint8 exist=0;
Shot_Disappear(t->Shot_Direction,t->Shot_Position,t->Position);
switch(t->Shot_Direction)
{
case Up: tank_number=Get_Nearest_Tank(t->Shot_Position,t->Shot_Direction,2,1);break;
case Down: tank_number=Get_Nearest_Tank(t->Shot_Position,t->Shot_Direction,2,1);break;
case Left: tank_number=Get_Nearest_Tank(t->Shot_Position,t->Shot_Direction,1,2);break;
case Right: tank_number=Get_Nearest_Tank(t->Shot_Position,t->Shot_Direction,1,2);break;
}
Get_Tank_Camp(tank_number,&camp);
Get_Tank_Level(tank_number,&level);
Get_Tank_Life(tank_number,&life);
if(t->Camp==camp)
{
return;
}
if(level>1)
{
level--;
Change_Tank_Level(tank_number,&level);
switch(tank_number)
{
case 1:Delete_Tank_Tail(&Tank1,Temp_tank1);Display_Tank(&Tank1,Temp_tank1);break;
case 2:Delete_Tank_Tail(&Tank2,Temp_tank2);Display_Tank(&Tank2,Temp_tank2);break;
}
return;
}
if(level==1&&life!=0)
{
life--;
Change_Tank_Life(tank_number,&life);
switch(tank_number)
{
case 1:Delete_Tank_Tail(&Tank1,Temp_tank1);Delete_Shot(Tank1.Shot_Direction,Tank1.Shot_Position);break;
case 2:Delete_Tank_Tail(&Tank2,Temp_tank2);Delete_Shot(Tank2.Shot_Direction,Tank2.Shot_Position);break;
}
Replace_Tank(tank_number);
switch(tank_number)
{
case 1:Display_Tank(&Tank1,Temp_tank1);break;
case 2:Display_Tank(&Tank2,Temp_tank2);break;
}
return;
}
if(level==1&&life==0)
{
Change_Tank_Exist(tank_number,&exist);
switch(tank_number)
{
case 1:Delete_Tank_Tail(&Tank1,Temp_tank1);Delete_Shot(Tank1.Shot_Direction,Tank1.Shot_Position);break;
case 2:Delete_Tank_Tail(&Tank2,Temp_tank2);Delete_Shot(Tank2.Shot_Direction,Tank2.Shot_Position);break;
}
return;
}
}
/****************************************************************************************************
* Function Name :Shot_Disappear *
* Description :炮弹碰撞物体消失函数 *
* Date : 09/09/25 *
* Parameter :炮弹的方向,炮弹坐标的指针,坦克坐标的指针 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Shot_Disappear(uint8 direction,uint8 *shot_position,uint8 *tank_position)
{
if(direction==Left&&( *(shot_position+1) )<*(tank_position+1))
{
Delete_Point( ( (*shot_position) *2)+1,( *(shot_position+1) )*2 );
Delete_Point( ( (*shot_position) *2)+1,( *(shot_position+1) )*2+1);
Delete_Point( ( (*shot_position) *2)+2,( *(shot_position+1) )*2);
Delete_Point( ( (*shot_position) *2)+2,( *(shot_position+1) )*2+1);
}
if(direction==Right&&( *(shot_position+1) )>*(tank_position+1)+4)
{
Delete_Point(( (*shot_position) *2)+1,( *(shot_position+1) )*2);
Delete_Point(( (*shot_position) *2)+1,( *(shot_position+1) )*2+1);
Delete_Point(( (*shot_position) *2)+2,( *(shot_position+1) )*2);
Delete_Point(( (*shot_position) *2)+2,( *(shot_position+1) )*2+1);
}
if(direction==Up&& (*shot_position) <*tank_position)
{
Delete_Point(( (*shot_position) *2),( *(shot_position+1) )*2+1);
Delete_Point(( (*shot_position) *2),( *(shot_position+1) )*2+2);
Delete_Point(( (*shot_position) *2)+1,( *(shot_position+1) )*2+1);
Delete_Point(( (*shot_position) *2)+1,( *(shot_position+1) )*2+2);
}
if(direction==Down&& (*shot_position) >*tank_position+4)
{
Delete_Point(( (*shot_position) *2),( *(shot_position+1) )*2+1);
Delete_Point(( (*shot_position) *2),( *(shot_position+1) )*2+2);
Delete_Point(( (*shot_position) *2)+1,( *(shot_position+1) )*2+1);
Delete_Point(( (*shot_position) *2)+1,( *(shot_position+1) )*2+2);
}
}
/****************************************************************************************************
* Function Name :Shot_Effect *
* Description :炮弹碰壁或敌方坦克的效果函数 *
* Date : 09/09/25 *
* Parameter :指向坦克结构体的指针,要炸毁的方向 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Shot_Break(uint8 *Shot_Position,uint8 direction )
{
uint8 i;
uint8 j;
switch(direction)
{
case Up_Left:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Delete_Point((Shot_Position[0]-2)*2+i,(Shot_Position[1]-1)*2+j);
}
}break;
case Up_Right:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Delete_Point((Shot_Position[0]-2)*2+i,(Shot_Position[1]+1)*2+j);
}
}break;
case Down_Left:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Delete_Point((Shot_Position[0]+1)*2+i,(Shot_Position[1]-1)*2+j);
}
}break;
case Down_Right:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Delete_Point((Shot_Position[0]+1)*2+i,(Shot_Position[1]+1)*2+j);
}
}break;
case Left_Up:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Delete_Point((Shot_Position[0]-1)*2+i,(Shot_Position[1]-2)*2+j);
}
}break;
case Left_Down:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Delete_Point((Shot_Position[0]+1)*2+i,(Shot_Position[1]-2)*2+j);
}
}break;
case Right_Up:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Delete_Point((Shot_Position[0]-1)*2+i,(Shot_Position[1]+1)*2+j);
}
}break;
case Right_Down:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Delete_Point((Shot_Position[0]+1)*2+i,(Shot_Position[1]+1)*2+j);
}
}break;
}
}
/* *************************************************************************************************
* Function Name :Draw_Barrier *
* Description :绘制障碍物 *
* Date : 09/09/27 *
* Parameter :指向障碍物结构体的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Draw_Barrier(struct Barrier *b)
{
uint8 i,j;
//uint8 num=Get_Barrier_Number(b->Position);
//Read_Barrier_Exist(num,&barrier_exist);
for(i=0;i<b->Length/2;i++)
{
for(j=0;j<b->Width/2;j++)
{
if((b->Exist&1<<j*(b->Length/2)+i)!=0)
{
switch(b->Property)
{
case Steel:Draw_Piece_Steel(b->Position[0]+j*2,b->Position[1]+i*2);break;
case Brick:Draw_Piece_Brick(b->Position[0]+j*2,b->Position[1]+i*2);break;
}
}
}
}
}
/* *************************************************************************************************
* Function Name :Draw_Piece_Steel *
* Description :指定坐标处画铁的贴图 *
* Date : 09/09/27 *
* Parameter :要绘制贴图的游戏横坐标与纵坐标 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Draw_Piece_Steel(uint8 x,uint8 y)
{
uint8 i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
Creat_Point(x*2+i,y*2+j);
}
}
}
/* *************************************************************************************************
* Function Name :Draw_Piece_Brick *
* Description :指定坐标处画砖的贴图 *
* Date : 09/09/27 *
* Parameter :要绘制贴图的游戏横坐标与纵坐标 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Draw_Piece_Brick(uint8 x,uint8 y)
{
uint8 i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if((x*2+i)%2==0&&(y*2+j)%2==0||(x*2+i)%2==1&&(y*2+j)%2==1)
{
Creat_Point(x*2+i,y*2+j);
}
}
}
}
/* *************************************************************************************************
* Function Name :Copy_Array *
* Description :复制数组函数 *
* Date : 09/09/19 *
* Parameter :指向目的数组的指针,指向原数组指针,复制变量的个数 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Copy_Array(uint8 *Desition,uint8 *original,uint8 length)
{
uint8 i;
for(i=0;i<length;i++)
{
*(Desition+i)=*(original+i);
}
}
/* *************************************************************************************************
* Function Name :Change_Picture *
* Description :贴图转化函数(转化的贴图字节存在*Destion中) *
* Date : 09/09/20 *
* Parameter :贴图所在页的游戏坐标,转化后用于存储的地址指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Change_Picture(uint8 position,uint8 *Desition)
{
uint8 i;
switch(position)
{
case 0:for(i=0;i<8;i++)
{
*(Desition+8+i)=0;
}
break;
case 1:for(i=0;i<8;i++)
{
*(Desition+8+i)=*(Desition+i);
*(Desition+8+i)=*(Desition+8+i)>>6&0X03;
*(Desition+i)=*(Desition+i)<<2&0XFC;
}
break;
case 2:for(i=0;i<8;i++)
{
*(Desition+8+i)=*(Desition+i);
*(Desition+8+i)=*(Desition+8+i)>>4&0X0F;
*(Desition+i)=*(Desition+i)<<4&0XF0;
}
break;
case 3:for(i=0;i<8;i++)
{
*(Desition+8+i)=*(Desition+i);
*(Desition+8+i)=*(Desition+8+i)>>2&0X3F;
*(Desition+i)=*(Desition+i)<<6&0XC0;
}
break;
}
}
/* *************************************************************************************************
* Function Name :Get_Nearest_Barrier *
* Description :查找离被查物最近的障碍物,以障碍物的后边沿为准 *
* Date : 09/09/21.22 *
* Parameter :指向坦克的坐标的指针,指定方向 *
* Return Code :障碍物编号(返回0表示坦克前进方向没有障碍物) *
* Author : *
************************************************************************************************* */
void Get_Nearest_Barrier(uint8 *position,uint8 direction,uint8 object_length,uint8 object_width,uint8 *num)
{
uint8 xdata i;
uint8 xdata barrier1=0; //用于返回的障碍物编号
uint8 xdata barrier2=0; //用于返回的障碍物编号
uint8 xdata barrier_poisition[2];
uint8 xdata barrier_length;
uint8 xdata barrier_width;
uint8 xdata distance1=200; //坦克和位于坦克同排或同列的障碍物的距离
uint8 xdata distance2=0; //坦克和位于坦克同排或同列的障碍物的距离
switch(direction)
{
case Up:
for(i=1;i<Barrier_Count+1;i++)
{
Get_Barrier_Quality(i,barrier_poisition,&barrier_length,&barrier_width);
if(*(position+1)<=barrier_poisition[1]+barrier_length-1&&*position>barrier_poisition[0])
{
if((barrier_poisition[1]>=2&&*(position+1)+(object_length-1)>=barrier_poisition[1])||(barrier_poisition[1]<=2&&*(position+1)>=barrier_poisition[1]))
{
if(distance1==200)
{
distance1=*position-barrier_poisition[0];
barrier1=i;
}
else if((*position-barrier_poisition[0])==distance1)
{
barrier2=i;
distance2=*position-barrier_poisition[0];
}
else if((*position-barrier_poisition[0])<distance1)
{
distance1=*position-barrier_poisition[0];
barrier1=i;
}
}
}
}break;
case Down:
for(i=1;i<Barrier_Count+1;i++)
{
Get_Barrier_Quality(i,barrier_poisition,&barrier_length,&barrier_width);
if(*(position+1)<=barrier_poisition[1]+barrier_length-1&&barrier_poisition[0]+barrier_width>*position+object_width)
{
if((barrier_poisition[1]>=2&&*(position+1)+(object_length-1>=barrier_poisition[1]))||(barrier_poisition[1]<=2&&*(position+1)>=barrier_poisition[1]))
{
if(distance1==200)
{
distance1=barrier_poisition[0]+barrier_width-(*position+object_width);
barrier1=i;
}
else if((barrier_poisition[0]+barrier_width-(*position+object_width))==distance1)
{
distance2=barrier_poisition[0]+barrier_width-(*position+object_width);
barrier2=i;
}
else if((barrier_poisition[0]+barrier_width-(*position+object_width))<distance1)
{
distance1=barrier_poisition[0]+barrier_width-(*position+object_width);
barrier1=i;
}
}
}
}break;
case Left:
for(i=1;i<Barrier_Count+1;i++)
{
Get_Barrier_Quality(i,barrier_poisition,&barrier_length,&barrier_width);
if(*position<=barrier_poisition[0]+barrier_width-1&&barrier_poisition[1]<*(position+1))
{
if((barrier_poisition[0]>=2&&*position+(object_width-1)>=barrier_poisition[0])||(barrier_poisition[0]<=2&&*position>=barrier_poisition[0]))
{
if(distance1==200)
{
distance1=*(position+1)-barrier_poisition[1];
barrier1=i;
}
else if((*(position+1)-barrier_poisition[1])==distance1)
{
distance2=*(position+1)-barrier_poisition[1];
barrier2=i;
}
else if((*(position+1)-barrier_poisition[1])<distance1)
{
distance1=*(position+1)-barrier_poisition[1];
barrier1=i;
}
}
}
}break;
case Right:
for(i=1;i<Barrier_Count+1;i++)
{
Get_Barrier_Quality(i,barrier_poisition,&barrier_length,&barrier_width);
if(*position<=barrier_poisition[0]+barrier_width-1&&barrier_poisition[1]+barrier_length>(*(position+1)+object_length))
{
if((barrier_poisition[0]>=2&&*position+(object_width-1)>=barrier_poisition[0])||(barrier_poisition[0]<=2&&*position>=barrier_poisition[0]))
{
if(distance1==200)
{
distance1=barrier_poisition[1]+barrier_length-(*(position+1)+object_length);
barrier1=i;
}
else if((barrier_poisition[1]+barrier_length-(*(position+1)+object_length))==distance1)
{
distance2=barrier_poisition[1]+barrier_length-(*(position+1)+object_length);
barrier2=i;
}
else if((barrier_poisition[1]+barrier_length-(*(position+1)+object_length))<distance1)
{
distance1=barrier_poisition[1]+barrier_length-(*(position+1)+object_length);
barrier1=i;
}
}
}
}break;
}
if(distance1!=distance2)
{
barrier2=0;
}
*num=barrier1;
*(num+1)=barrier2;
}
/* *************************************************************************************************
* Function Name :Get_Nearest_Tank *
* Description :查找离被查物最近的坦克,以坦克的前边沿为准 *
* Date : 09/09/21.22 *
* Parameter :指向坦克的坐标的指针,指定方向 *
* Return Code :障碍物编号(返回0表示坦克前进方向没有障碍物) *
* Author : *
************************************************************************************************* */
uint8 Get_Nearest_Tank(uint8 *position,uint8 direction,uint8 object_length,uint8 object_width)
{
uint8 i;
uint8 tank_number=0; //用于返回坦克的编号
uint8 tank_poisition[2];
uint8 distance=200; //初始化距离
switch(direction)
{
case Up:
for(i=1;i<Tank_Count+1;i++)
{
if( (i==1&&Tank1.Exist==1) ||(i==2&&Tank2.Exist==1) )
{
Get_Tank_Position(i,tank_poisition);
if(*(position+1)<=tank_poisition[1]+4-1&&*position>=tank_poisition[0]+4)
{
if((tank_poisition[1]>=2&&*(position+1)+(object_length-1)>=tank_poisition[1])||(tank_poisition[1]<=2&&*(position+1)>=tank_poisition[1]))
{
if(distance==200)
{
distance=*position-tank_poisition[0]-4;
tank_number=i;
}
else if((*position-tank_poisition[0]-4)<distance)
{
distance=*position-tank_poisition[0]-4;
tank_number=i;
}
}
}
}
}break;
case Down:
for(i=1;i<Tank_Count+1;i++)
{
if( (i==1&&Tank1.Exist==1) ||(i==2&&Tank2.Exist==1) )
{
Get_Tank_Position(i,tank_poisition);
if(*(position+1)<=tank_poisition[1]+4-1&&tank_poisition[0]>=*position+object_width)
{
if((tank_poisition[1]>=2&&*(position+1)+(object_length-1)>=tank_poisition[1])||(tank_poisition[1]<=2&&*(position+1)>=tank_poisition[1]))
{
if(distance==200)
{
distance=tank_poisition[0]-(*position+object_width);
tank_number=i;
}
else if((tank_poisition[0]-(*position+object_width))<distance)
{
distance=tank_poisition[0]-(*position+object_width);
tank_number=i;
}
}
}
}
}break;
case Left:
for(i=1;i<Tank_Count+1;i++)
{
if( (i==1&&Tank1.Exist==1) ||(i==2&&Tank2.Exist==1) )
{
Get_Tank_Position(i,tank_poisition);
if(*position<=tank_poisition[0]+4-1&&tank_poisition[1]+4<=*(position+1))
{
if((tank_poisition[0]>=2&&*position+(object_width-1)>=tank_poisition[0])||(tank_poisition[0]<=2&&*position>=tank_poisition[0]))
{
if(distance==200)
{
distance=*(position+1)-tank_poisition[1]-4;
tank_number=i;
}
else if((*(position+1)-tank_poisition[1])-4<distance)
{
distance=*(position+1)-tank_poisition[1]-4;
tank_number=i;
}
}
}
}
}break;
case Right:
for(i=1;i<Tank_Count+1;i++)
{
if( (i==1&&Tank1.Exist==1) ||(i==2&&Tank2.Exist==1) )
{
Get_Tank_Position(i,tank_poisition);
if(*position<=tank_poisition[0]+4-1&&tank_poisition[1]>=(*(position+1)+object_length))
{
if((tank_poisition[0]>=2&&*position+(object_width-1)>=tank_poisition[0])||(tank_poisition[0]<=2&&*position>=tank_poisition[0]))
{
if(distance==200)
{
distance=tank_poisition[1]-(*(position+1)+object_length);
tank_number=i;
}
else if((tank_poisition[1]-(*(position+1)+object_length))<distance)
{
distance=tank_poisition[1]-(*(position+1)+object_length);
tank_number=i;
}
}
}
}
}break;
}
return tank_number;
}
/* *************************************************************************************************
* Function Name :Get_Barrier_Quality *
* Description :获得指定障碍物的坐标值,长度 ,宽度 *
* Date : 09/09/20 *
* Parameter :障碍物编号,指向障碍物坐标的指针,指向障碍物长度的指针,指向障碍物宽度的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Get_Barrier_Quality (uint8 number,uint8 *position,uint8 *length,uint8 *width)
{
switch(number)
{
case 1: *position=Barrier1.Position[0]; *(position+1)=Barrier1.Position[1]; *length=Barrier1.Length; *width=Barrier1.Width;break;
case 2: *position=Barrier2.Position[0]; *(position+1)=Barrier2.Position[1]; *length=Barrier2.Length; *width=Barrier2.Width;break;
case 3: *position=Barrier3.Position[0]; *(position+1)=Barrier3.Position[1]; *length=Barrier3.Length; *width=Barrier3.Width;break;
case 4: *position=Barrier4.Position[0]; *(position+1)=Barrier4.Position[1]; *length=Barrier4.Length; *width=Barrier4.Width;break;
case 5: *position=Barrier5.Position[0]; *(position+1)=Barrier5.Position[1]; *length=Barrier5.Length; *width=Barrier5.Width;break;
case 6: *position=Barrier6.Position[0]; *(position+1)=Barrier6.Position[1]; *length=Barrier6.Length; *width=Barrier6.Width;break;
case 7: *position=Barrier7.Position[0]; *(position+1)=Barrier7.Position[1]; *length=Barrier7.Length; *width=Barrier7.Width;break;
case 8: *position=Barrier8.Position[0]; *(position+1)=Barrier8.Position[1]; *length=Barrier8.Length; *width=Barrier8.Width;break;
case 0: break;
}
}
/* *************************************************************************************************
* Function Name :Read_Barrier_Exist *
* Description :读取指定障碍物的破坏程度 *
* Date : 09/09/25 *
* Parameter :障碍物编号,指向障碍物破坏程度的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Read_Barrier_Exist (uint8 number,uint8 *exist)
{
switch(number)
{
case 1: *exist=Barrier1.Exist;break;
case 2: *exist=Barrier2.Exist;break;
case 3: *exist=Barrier3.Exist;break;
case 4: *exist=Barrier4.Exist;break;
case 5: *exist=Barrier5.Exist;break;
case 6: *exist=Barrier6.Exist;break;
case 7: *exist=Barrier7.Exist;break;
case 8: *exist=Barrier8.Exist;break;
}
}
/* *************************************************************************************************
* Function Name :Write_Barrier_Exist *
* Description :改变指定障碍物的破坏程度 *
* Date : 09/09/25 *
* Parameter :障碍物编号,指向障碍物破坏程度的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Write_Barrier_Exist (uint8 number,uint8 *exist)
{
switch(number)
{
case 1: Barrier1.Exist=*exist;break;
case 2: Barrier2.Exist=*exist;break;
case 3: Barrier3.Exist=*exist;break;
case 4: Barrier4.Exist=*exist;break;
case 5: Barrier5.Exist=*exist;break;
case 6: Barrier6.Exist=*exist;break;
case 7: Barrier7.Exist=*exist;break;
case 8: Barrier8.Exist=*exist;break;
}
}
/* *************************************************************************************************
* Function Name :Get_Barrier_Property *
* Description :获得障碍物的组成物质 *
* Date : 09/09/25 *
* Parameter :障碍物编号,指向障碍物组成物质的指针 *
* Return Code :无 *
* Author : *
************************************************************************************************* */
void Get_Barrier_Property (uint8 number,uint8 *property)
{
switch(number)
{
case 1: *property=Barrier1.Property;break;
case 2: *property=Barrier2.Property;break;
case 3: *property=Barrier3.Property;break;
case 4: *property=Barrier4.Property;break;
case 5: *property=Barrier5.Property;break;
case 6: *property=Barrier6.Property;break;
case 7: *property=Barrier7.Property;break;
case 8: *property=Barrier8.Property;break;
}
}
/* *************************************************************************************************
* Function Name :Change_Tank_Exist *
* Description :更改指定坦克是否存在 *
* Date : 09/09/30 *
* Parameter :坦克编号,指向坦克存在性的指针 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Change_Tank_Exist (uint8 number,uint8 *exist)
{
switch(number)
{
case 1: Tank1.Exist=*exist; break;
case 2: Tank2.Exist=*exist; break;
}
}
/* *************************************************************************************************
* Function Name :Get_Tank_Position *
* Description :获得指定坦克的坐标值 *
* Date : 09/09/29 *
* Parameter :坦克编号,指向坦克坐标的指针 *
* Return Code :无 *
* Author : *
*************************************************************************************************** */
void Get_Tank_Position (uint8 number,uint8 *position)
{
switch(number)
{
case 1: *position=Tank1.Position[0]; *(position+1)=Tank1.Position[1];break;
case 2: *position=Tank2.Position[0]; *(position+1)=Tank2.Position[1];break;
}
}
/* *************************************************************************************************
* Function Name :Get_Tank_Camp *
* Description :获得指定坦克的阵营 *
* Date : 09/09/30 *
* Parameter :坦克编号,指向坦克阵营的指针 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Get_Tank_Camp (uint8 number,uint8 *camp)
{
switch(number)
{
case 1: *camp=Tank1.Camp; break;
case 2: *camp=Tank2.Camp; break;
}
}
/* *************************************************************************************************
* Function Name :Get_Tank_Life *
* Description :获得指定坦克的生命 *
* Date : 09/09/30 *
* Parameter :坦克编号,指向坦克生命的指针 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Get_Tank_Life (uint8 number,uint8 *life)
{
switch(number)
{
case 1: *life=Tank1.Life; break;
case 2: *life=Tank2.Life; break;
}
}
/* *************************************************************************************************
* Function Name :Change_Tank_Life *
* Description :更改指定坦克的生命 *
* Date : 09/09/30 *
* Parameter :坦克编号,指向坦克生命的指针 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Change_Tank_Life (uint8 number,uint8 *life)
{
switch(number)
{
case 1: Tank1.Life=*life; break;
case 2: Tank2.Life=*life; break;
}
}
/* *************************************************************************************************
* Function Name :Get_Tank_Level *
* Description :获得指定坦克的级别 *
* Date : 09/09/30 *
* Parameter :坦克编号,指向坦克生命的指针 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Get_Tank_Level (uint8 number,uint8 *level)
{
switch(number)
{
case 1: *level=Tank1.Level; break;
case 2: *level=Tank2.Level; break;
}
}
/* *************************************************************************************************
* Function Name :Change_Tank_Level *
* Description :更改指定坦克的级别 *
* Date : 09/09/30 *
* Parameter :坦克编号,指向坦克生命的指针 *
* Return Code :无 *
* Author : *
****************************************************************************************************/
void Change_Tank_Level (uint8 number,uint8 *level)
{
switch(number)
{
case 1: Tank1.Level=*level; break;
case 2: Tank2.Level=*level; break;
}
}
/* *************************************************************************************************
* Function Name :Get_Tank_Shot_Quality *
* Description :获得指定坦克炮弹的坐标值,方向 *
* Date : 09/09/25 *
* Parameter :坦克编号,指向炮弹坐标的指针,指向炮弹方向的指针 *
* Return Code :无 *
* Author : *
*************************************************************************************************** */
void Get_Tank_Shot_Quality (uint8 number,uint8 *position,uint8 *direction)
{
switch(number)
{
case 1: *position=Tank1.Shot_Position[0]; *(position+1)=Tank1.Shot_Position[1];*direction=Tank1.Shot_Direction;break;
case 2: *position=Tank2.Shot_Position[0]; *(position+1)=Tank2.Shot_Position[1];*direction=Tank2.Shot_Direction;break;
}
}
void Keyboard_P1_ISR(void) interrupt 0 //中断键盘函数(控制坦克1)
{
P1_col1=P1_col2=1; //列线
P1_row1=0; P1_row2=1; // 将行线1置低,其他行线置高
if (P1_col1==0)
{
if(Tank1.Position[0]%2==0&&Tank1.Position[1]%2==0)
{
Tank1.Direction=Up;
}
}
if(Tank1.Position[0]%2==0&&Tank1.Position[1]%2==0)
{
if (P1_col2==0)
{
Tank1.Direction=Left;
}
}
P1_row1=1; P1_row2=0; // 将行线2置低,其他行线置高
if(Tank1.Position[0]%2==0&&Tank1.Position[1]%2==0)
{
if (P1_col1==0)
{
Tank1.Direction=Right;
}
}
if(Tank1.Position[0]%2==0&&Tank1.Position[1]%2==0)
{
if (P1_col2==0)
{
Tank1.Direction=Down;
}
}
Tank1.Button__Down_Flg=1;
EX0=0;
}
void Keyboard_P2_ISR(void) interrupt 2 //中断键盘函数(控制坦克2)
{
P2_col1=P2_col2=1; //列线
P2_row1=0; P2_row2=1; // 将行线1置低,其他行线置高
if (P2_col1==0)
{
if(Tank2.Position[0]%2==0&&Tank2.Position[1]%2==0)
{
Tank2.Direction=Up;
}
}
if(Tank2.Position[0]%2==0&&Tank2.Position[1]%2==0)
{
if (P2_col2==0)
{
Tank2.Direction=Left;
}
}
P2_row1=1; P2_row2=0; // 将行线2置低,其他行线置高
if(Tank2.Position[0]%2==0&&Tank2.Position[1]%2==0)
{
if (P2_col1==0)
{
Tank2.Direction=Right;
}
}
if(Tank2.Position[0]%2==0&&Tank2.Position[1]%2==0)
{
if (P2_col2==0)
{
Tank2.Direction=Down;
}
}
Tank2.Button__Down_Flg=1;
EX1=0;
}
void INT0_ISR(void) interrupt 1 //中断定时器函数,基本定时5ms
{
TL0=0X78;
TH0=0XEC;
Time_Flg++;
}
void INT1_ISR(void) interrupt 3 //T1用于计数器,当来一个低电平是发生中断,用于发射炮弹
{
TL1=0XFF;
TH1=0XFF;
Tank1.Send_Shot_Flg=1;
}
/* *************************************************************************************************
* Function Name : LCD12864_Init *
* Description : 主屏模块初始化 *
* Date : 09/04/1 *
* Parameter : 无 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void LCD12864_Init(void)
{
LCD12864_EN = 0; //LCD12864始能位清0
WriteCmd(SET_ON); //将LCD12864设置为ON
WriteCmd(SET_COL); //设置开始的列
WriteCmd(SET_PAGE); //设置开始的行
WriteCmd(0xC0);
}
//****************************************************************************
//* 名称:CleanAll
//* 功能:清屏
//****************************************************************************
void CleanAll(void)
{
uint8 ucPage,ucCol;
LCD12864_CSA = 0; //左右两屏都选中
LCD12864_CSB = 0;
for(ucPage=0;ucPage<8;ucPage++)
{
WriteCmd(SET_PAGE+ucPage); //页
WriteCmd(SET_COL); //列
for(ucCol=0;ucCol<64;ucCol++)
WriteData(0x00);
}
}
/* *************************************************************************************************
* Function Name : DisplayByte *
* Description : 显示一个字节,即纵向8个像素 *
* Date : 09/04/1 *
* Parameter : ucPage 显示的页 (屏幕一共8页) *
* ucCol 要显示的列 (屏幕一共128列) *
* ucData 要显示的数据 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void DisplayByte(uint8 ucPage,uint8 ucCol,uint8 ucData)
{
uint8 i=SET_PAGE+ucPage;
uint8 j=SET_COL+ucCol%SINGLE_SCREEN_COL;
if(ucPage<0||ucPage>=8||ucCol<0||ucCol>=128)
{
while(1);
}
if(ucCol/SINGLE_SCREEN_COL==0)
{
LCD12864_CSA=0; //选择A屏
LCD12864_CSB=1;
}
else{
LCD12864_CSB=0; //选择B屏
LCD12864_CSA=1;
}
//WriteCmd(SET_COL); //设置开始的列
//WriteCmd(SET_PAGE); //设置开始的行
WriteCmd(i);
WriteCmd(j);
WriteData(ucData);
}
/* *************************************************************************************************
* Function Name : WriteCmd *
* Description : *
* Date : 09/04/1 *
* Parameter : ucCmd 要写的命令 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void WriteCmd(uint8 ucCmd)
{
LCD12864_RS = 0;
LCD12864_RW = 0;
LCD12864_DATA = ucCmd;
LCD12864_EN = 1;
LCD12864_EN = 0;
}
/* *************************************************************************************************
* Function Name : MWriteData *
* Description : 显示游戏地图 *
* Date : 09/04/1 *
* Parameter : ucData要写的数据 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void WriteData(uint8 ucData)
{
LCD12864_RS = 1;
LCD12864_RW = 0;
LCD12864_DATA = ucData;
LCD12864_EN = 1;
LCD12864_EN = 0;
}
/* *************************************************************************************************
* Function Name : ReadByte *
* Description : *
* Date : 09/04/1 *
* Parameter : ucPage 要读的页数 *
* ucCol 要读的列数 *
* ucData 将读的内容存放在某个变量中 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void ReadByte(uint8 ucPage,uint8 ucCol,uint8 *ucData)
{
uint8 ucTemp;
if(ucPage<0||ucPage>=8||ucCol<0||ucCol>=128)
{
while(1);
}
if(ucCol/SINGLE_SCREEN_COL==0)
{
LCD12864_CSA=0; //选择A屏
LCD12864_CSB=1;
}
else{
LCD12864_CSB=0; //选择B屏
LCD12864_CSA=1;
}
WriteCmd(SET_COL); //设置开始的列
WriteCmd(SET_PAGE); //设置开始的行
//空读
WriteCmd(SET_PAGE+ucPage);
WriteCmd(SET_COL+ucCol%SINGLE_SCREEN_COL);
LCD12864_DATA=0xFF;
LCD12864_RS = 1;
LCD12864_RW = 1;
LCD12864_EN = 1;
ucTemp = P0;
LCD12864_EN = 0;
//读到ucTemp中
WriteCmd(SET_PAGE+ucPage);
WriteCmd(SET_COL+ucCol%SINGLE_SCREEN_COL);
LCD12864_DATA=0xFF;
LCD12864_RS = 1;
LCD12864_RW = 1;
LCD12864_EN = 1;
ucTemp = P0;
LCD12864_EN = 0;
*ucData=ucTemp;
}
/* *************************************************************************************************
* Function Name : Creat_Point *
* Description : lcd12864指定坐标产生一个点 *
* Date : 09/09/24 *
* Parameter : 指定横坐标x,指定纵坐标y *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void Creat_Point(uint8 x,uint8 y)
{
uint8 ucTemp;
if(x<0||x>=64||y<0||y>=128)
{
while(1);
}
ReadByte(x/8,y,&ucTemp);
ucTemp=ucTemp|1<<(x%8);
DisplayByte(x/8,y,ucTemp);
}
/* *************************************************************************************************
* Function Name : Delete_Point *
* Description : lcd12864指定坐标删去一个点 *
* Date : 09/09/24 *
* Parameter : 指定横坐标x,指定纵坐标y *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void Delete_Point(uint8 x,uint8 y)
{
uint8 ucTemp;
if(x<0||x>=64||y<0||y>=128)
{
while(1);
}
ReadByte(x/8,y,&ucTemp);
ucTemp=~(~ucTemp|1<<(x%8));
DisplayByte(x/8,y,ucTemp);
}
/* *************************************************************************************************
* Function Name : Add_Points *
* Description : lcd12864指定页和列上添加数据(增加点) *
* Date : 09/09/24 *
* Parameter : ucPage 显示的页 (屏幕一共8页) *
* ucCol 要显示的列 (屏幕一共128列) *
* ucData 要添加的数据 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void Add_Points(uint8 ucPage,uint8 ucCol,uint8 ucdata)
{
uint8 ucTemp;
if(ucPage<0||ucPage>=8||ucCol<0||ucCol>=128)
{
while(1);
}
ReadByte(ucPage,ucCol,&ucTemp);
ucdata=ucTemp|ucdata;
DisplayByte(ucPage,ucCol,ucdata);
}
/* *************************************************************************************************
* Function Name : Reduce_Points *
* Description : lcd12864指定页和列上减少数据(删除点) *
* Date : 09/09/24 *
* Parameter : ucPage 显示的页 (屏幕一共8页) *
* ucCol 要显示的列 (屏幕一共128列) *
* ucData 要删除的数据 *
* Return Code : 无 *
* Author : *
************************************************************************************************* */
void Reduce_Points(uint8 ucPage,uint8 ucCol,uint8 ucdata)
{
uint8 ucTemp;
if(ucPage<0||ucPage>=8||ucCol<0||ucCol>=128)
{
while(1);
}
ReadByte(ucPage,ucCol,&ucTemp);
ucdata=ucTemp&~ucdata;
DisplayByte(ucPage,ucCol,ucdata);
}
AT89C51单片机 C语言实现坦克大战游戏代码
最新推荐文章于 2023-08-12 18:16:21 发布