基于51單片機的雙人對戰(zhàn)小游戲的實現(xiàn) 作者: 時間:2016-11-30 來源:網(wǎng)絡 加入技術交流群 掃碼加入和技術大咖面對面交流海量資料庫查詢 收藏 void action_fist1()//第1個人出拳{int i;i=5;fist_change_buff1();shed_blood2();while(i--){display_one_page();}i=5;change_buffer_to1(position1*16);change_buffer_to2(position2*16);}void action_fist2()//第2個人出拳{int i;i=10;fist_change_buff2();shed_blood1();while(i--){display_one_page();}change_buffer_to1(position1*16);change_buffer_to2(position2*16);}void action_leg1()//第1個人出腿{ int i;i=10;leg_change_buff1();shed_blood2();while(i--){//display_one_page1();display_one_page();}change_buffer_to1(position1*16);change_buffer_to2(position2*16);}void action_leg2()//第2個人出腿{int i;i=10;leg_change_buff2();shed_blood1();while(i--){display_one_page();}change_buffer_to1(position1*16);change_buffer_to2(position2*16);}void init_interrupt()//中斷位的設置{TMOD=0x11;//定時器T0 T1工作在1模式 16位方式下TH0=63536/256;//2ms一次定時器中斷TL0=63536%256;TH1=63536/256;//2ms一次定時器中斷TL1=63536%256;EA=1;//開總中斷ET0=1;//開定時計數(shù)器T0ET1=1;//開定時計數(shù)器T1}void scan_key(){while(1){if(blood1==0||blood2==0)break;while(S11&&S12&&S13&&S14&&S21&&S22&&S23&&S24)display_one_page();while(S11||S12||S13||S14||S21||S22||S23||S24){delay(1);if(S11&&S12&&S13&&S14&&S21&&S22&&S23&&S24)display_one_page();elsebreak;}if(S12==0){delay(1);if(S12==0)//1向后的動作{action_back1();}}if(S22==0){delay(1);if(S22==0)//2向后的動作{action_back2();}}else if(S11==0){delay(1);if(S11==0)//1向前的動作{action_forth1();}}else if(S21==0){delay(1);if(S21==0)//2向前的動作{action_forth2();}}else if(S13==0){delay(1);if(S13==0){TR0=1;while(TR0==1){display_one_page();if(S22==0){delay(1);if(S22==0){count_back2=1;}}else if(S21==0){delay(1);if(S21==0){count_forth2=1;}}}action_fist1();}}else if(S23==0){delay(1);if(S23==0){TR1=1;while(TR1==1){display_one_page();if(S12==0){delay(1);if(S12==0){count_back1=1;}}else if(S11==0){delay(1);if(S11==0){count_forth1=1;}}}action_fist2();}}else if(S13==0){delay(1);if(S13==0){TR0=1;while(TR0==1){display_one_page();if(S22==0){delay(1);if(S22==0){count_back2=1;}}else if(S21==0){delay(1);if(S21==0){count_forth2=1;}}}action_fist1();}}else if(S23==0){delay(1);if(S23==0){TR1=1;while(TR1==1){display_one_page();if(S12==0){delay(1);if(S12==0){count_back1=1;}}else if(S11==0){delay(1);if(S11==0){count_forth1=1;}}}action_fist2();}}else if(S14==0){delay(1);if(S14==0){TR0=1;while(TR0==1){display_one_page();if(S22==0){delay(1);if(S22==0){count_back2=1;}}else if(S21==0){delay(1);if(S21==0){count_forth2=1;}}}action_leg1();}}else if(S24==0){delay(1);if(S24==0){TR1=1;while(TR1==1){display_one_page();if(S12==0){delay(1);if(S12==0){count_back1=1;}}else if(S11==0){delay(1);if(S11==0){count_forth1=1;}}}action_leg2();}}}}void shed_blood1(){if(position2==1){if(position1==2){if(blood1>0)blood1--;}}else if(position2==2){if(position1>0){if(blood1>0)blood1--;}}}void shed_blood2(){if(position1==1){if(position2==2){if(blood2>0)blood2--;}}else if(position1==2){if(position2>0){if(blood2>0)blood2--;}}}void handle1() interrupt 1{EA=0;TH0=63536/256;//2ms一次定時器中斷TL0=63536%256;time0_count++;if(time0_count==200){time0_count=0;TR0=0;if(count_back2==1){count_back2=0;action_back2();}else if(count_forth2==1){count_forth2=0;action_forth2();}}EA=1;}void handle2() interrupt 3{EA=0;TH1=63536/256;//2ms一次定時器中斷TL1=63536%256;time1_count++;if(time1_count==200){time1_count=0;TR1=0;if(count_back1==1){count_back1=0;action_back1();}else if(count_forth1==1){count_forth1=0;action_forth1();}}EA=1; } 上一頁 1 2 3 下一頁
評論