双人小游戏基于51单片机的双人对战小游戏的实现
unsignedcharposition1=1;//position一共有3种状态,0代表最边上,1代表初始,2代表最前的unsignedcharposition2=1;//position一共有3种状态,0代表最边上,1代表初始,2代表最前的unsignedcharfist1=0;//1没有出拳unsignedcharfist2=0;//2没有出拳unsignedcharleg1=0;//1没有出脚unsignedcharleg2=0;//2没有出脚unsignedcharcount_back1=0;unsignedcharcount_back2=0;unsignedcharcount_forth1=0;unsignedcharcount_forth2=0;unsignedchartime0_count=0;unsignedchartime1_count=0;unsignedcharblood1=7;unsignedcharblood2=7;unsignedcharbuff1[16]={0x00,0x18,0x24,0x24,0x18,0x18,0x7E,0x66,//右边的初始形态0x66,0x24,0x3C,0x24,0x24,0x24,0x24,0x00};unsignedcharbuff2[16]={0x00,0x18,0x24,0x24,0x18,0x18,0x7E,0x66,//右边的初始形态0x66,0x24,0x3C,0x24,0x24,0x24,0x24,0x00};//定义两名选手的操作键//选手1#defineS11P1_0//向前#defineS12P1_1//后退#defineS13P1_2//出拳#defineS14P1_3//出腿//选手2#defineS21P1_4//向前#defineS22P1_5//向后#defineS23P1_6//出出#defineS24P1_7//腿拳//两个选手的led点阵行扫描使能端#defineA_1P0_0#defineB_1P0_1#defineC_1P0_2#defineD_1P0_3//两个选手的2个595使能端#defineSCLKP2_0#defineSIP2_1#defineRCLKP2_2//当按下S1时开始游戏,游戏结束时显示哪方获胜,然后按下S2键后重新开始新一轮游戏#defineS1P2_6#defineS2P2_7//第一个人的74HC154区域行选#defineNUMLED1OPEN();{D_1=0;C_1=0;B_1=0;A_1=0;};#defineNUMLED2OPEN();{D_1=0;C_1=0;B_1=0;A_1=1;};#defineNUMLED3OPEN();{D_1=0;C_1=0;B_1=1;A_1=0;};#defineNUMLED4OPEN();{D_1=0;C_1=0;B_1=1;A_1=1;};#defineNUMLED5OPEN();{D_1=0;C_1=1;B_1=0;A_1=0;};#defineNUMLED6OPEN();{D_1=0;C_1=1;B_1=0;A_1=1;};#defineNUMLED7OPEN();{D_1=0;C_1=1;B_1=1;A_1=0;};#defineNUMLED8OPEN();{D_1=0;C_1=1;B_1=1;A_1=1;};#defineNUMLED9OPEN();{D_1=1;C_1=0;B_1=0;A_1=0;};#defineNUMLED10OPEN();{D_1=1;C_1=0;B_1=0;A_1=1;};#defineNUMLED11OPEN();{D_1=1;C_1=0;B_1=1;A_1=0;};#defineNUMLED12OPEN();{D_1=1;C_1=0;B_1=1;A_1=1;};#defineNUMLED13OPEN();{D_1=1;C_1=1;B_1=0;A_1=0;};#defineNUMLED14OPEN();{D_1=1;C_1=1;B_1=0;A_1=1;};#defineNUMLED15OPEN();{D_1=1;C_1=1;B_1=1;A_1=0;};#defineNUMLED16OPEN();{D_1=1;C_1=1;B_1=1;A_1=1;};//0是第一个选手的索引表的开始80是第二个选手开始在表中的#defineSTART10#defineSTART280#defineINIT16//第一个选手从的初始状态在中间为16#defineJUMP_UP_AND_BACK148//向后跳起的缓冲动作的#defineJUMP_UP_AND_BACK264//向后跳起的缓冲动作的#defineBACK0//在最边后面的状态的#defineFORTH32//在最前面的状态的#defineGO0//游戏的开始画面然后按S1开始游戏//#defineKO32#defineP1_WIN64//显示P1胜利在索引表中的#defineP2_WIN96//显示P2胜利在索引表中的//图像表//人物的各种形态和unsignedcharcoderole_action[]={0x00,0x0C,0x12,0x12,0x0C,0x0C,0x3F,0x33,//左边后退一步的状态00x33,0x12,0x1E,0x12,0x12,0x12,0x12,0x00,0x00,0x18,0x24,0x24,0x18,0x18,0x7E,0x66,//左边的初始形态160x66,0x24,0x3C,0x24,0x24,0x24,0x24,0x00,0x00,0x30,0x48,0x48,0x30,0x30,0xFC,0xCC,//左边前进一步的状态320xCC,0x48,0x78,0x48,0x48,0x48,0x48,0x00,0x18,0x24,0x24,0x18,0x18,0x66,0x66,0x65,//左边向右后方向跳起的动作1480x24,0x3C,0x24,0x12,0x12,0x12,0x00,0x00,0x0C,0x12,0x12,0x0C,0x0C,0x33,0x33,0x53,//左边向右后方向跳起的动作2640x12,0x1E,0x12,0x24,0x24,0x24,0x00,0x00,0x00,0x30,0x48,0x48,0x30,0x30,0xCC,0xCC,//右边后退一步的动作800xCC,0x48,0x78,0x48,0x48,0x48,0x48,0x00,0x00,0x18,0x24,0x24,0x18,0x18,0x7E,0x66,//左边的初始形态960x66,0x24,0x3C,0x24,0x24,0x24,0x24,0x00,0x00,0x0C,0x12,0x12,0x0C,0x0C,0x33,0x33,//右边前进一步的状态1120x33,0x12,0x1E,0x12,0x12,0x12,0x12,0x00,0x18,0x24,0x24,0x18,0x18,0x66,0x66,0xA6,//右边向左后方向跳起的动作11280x24,0x3C,0x24,0x48,0x48,0x48,0x00,0x00,0x30,0x48,0x48,0x30,0x30,0xCC,0xCC,0xCA,//右边向左后方向跳起的动作21440x48,0x78,0x48,0x24,0x24,0x24,0x00,0x00};//开机画面和结束时显示哪方胜利的索引表unsignedcharcodewelecome_and_end[]={0x00,0x00,0x00,0x04,0xF9,0xF4,0xF9,0xF4,0x00,0x04,0xF9,0xF4,0xF9,0xF4,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//GO!!!00x00,0x00,0x22,0x38,0x24,0x44,0x28,0x44,0x30,0x44,0x28,0x44,0x24,0x44,0x22,0x44,0x22,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x92,0x49,0x45,0x14,0x28,0xA2,0x92,0x49,//KO320x00,0x00,0x00,0x00,0x00,0x00,0x25,0x12,0x51,0x13,0x55,0x12,0x55,0x52,0x54,0xA7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//P1WIN640x00,0x00,0x00,0x00,0x00,0x00,0x4A,0x24,0xA2,0x2A,0xAA,0x24,0xAA,0xA2,0xA9,0x4E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00//P2WIN96};voiddelayu(unsignedinttime);//延时函数延时0.1msvoiddelay(unsignedinttime);//延时函数延时1msvoidNUMLEDOPEN(inti);//74HC154进行行选择,第i行voiddat_in(unsignedchardat);//将8为数据从597传送过去voiddisplay_one_page();//先加载各方“血”的状态,并显示一张图片,显示人的状态和血的状态voiddisplay_scene(intscene);//显示开机画面和胜负画面的函数voidchange_buffer_to1(intposition);//修改1的图像状态缓冲从人物索引表的第position个8位数个开始显示voidchange_buffer_to2(intposition);//修改2的图像状态缓冲从人物索引表的第position个8位数个开始显示voidaction_back1();//第1个人向后一步并将position减1直到它不能后退voidaction_back2();//第2个人向后一步并将position减1直到它不能后退voidaction_forth1();//第1个人向前一步并将position加1直到它不能后退voidaction_forth2();//第2个人向前一步并将position加1直到它不能后退voidfist_change_buff1();//由于1出拳对画面的改动要调用change_buff1_to_bit(intpos)和change_buff1_to_bit_low(intpos)函数voidleg_change_buff1();//由于1出腿对画面的改动要调用change_buff1_to_bit(intpos)和change_buff1_to_bit_low(intpos)函数voidfist_change_buff2();//由于2出拳对画面的改动要调用change_buff1_to_bit(intpos)和change_buff1_to_bit_low(intpos)函数voidleg_change_buff2();//由于2出腿对画面的改动要调用change_buff1_to_bit(intpos)和change_buff1_to_bit_low(intpos)函数voidchange_buff1_to_bit(intpos);//将特定某一一voidchange_buff2_to_bit(intpos);//将特定某一一voidchange_buff1_to_bit_low(intpos);//将特定某一0voidchange_buff2_to_bit_low(intpos);//将特定某一0voidaction_fist1();//第1个人出拳并处理减血情况voidaction_fist2();//第2个人出拳并处理减血情况voidaction_leg1();//第1个人出腿并处理减血情况voidaction_leg2();//第2个人出腿并处理减血情况voidscan_key();//这个是函数的主体部分分别扫描并处理向后退向前走出拳出腿的动作当出拳和出腿的时候定时器//这300ms内记录是否有对方出拳出腿的动作并按照先扫描向后退后扫描向前进的顺序扫描一遍并处理如果没有这两个动作直接返回调用出拳//否则处理后再出拳出脚的道理一致voidinit_interrupt();//中断位的设置//定两个时器中断16位模式voidshed_blood1();//记录流血的数字voidshed_blood2();voidmain(){inti;while(1){if(S1==0){delay(1);if(S1==0){for(i=0;i