#includeunsigned char position1=1;//position一共有3種狀態(tài),0代表最邊上,1代表初始位置,2代表最前的位置unsigned char position2=1;//position一共有3種狀態(tài),0代表最邊上,1代表初始位置,2代表最前的位置unsigned char fist1=0;//1沒有出拳unsigned char fist2=0;//2沒有出拳unsigned char leg1=0;//1沒有出腳unsigned char leg2=0;//2沒有出腳unsigned char count_back1=0;unsigned char count_back2=0;unsigned char count_forth1=0;unsigned char count_forth2=0;unsigned char time0_count=0;unsigned char time1_count=0;unsigned char blood1=7;unsigned char blood2=7;unsigned char buff1[16]={0x00,0x18,0x24,0x24,0x18,0x18,0x7E,0x66,//右邊小人的初始形態(tài)0x66,0x24,0x3C,0x24,0x24,0x24,0x24,0x00};unsigned char buff2[16]={0x00,0x18,0x24,0x24,0x18,0x18,0x7E,0x66,//右邊小人的初始形態(tài)0x66,0x24,0x3C,0x24,0x24,0x24,0x24,0x00};//定義兩名選手的操作鍵//選手1#define S11 P1_0//向前#define S12 P1_1//后退#define S13 P1_2//出拳#define S14 P1_3//出腿//選手2#define S21 P1_4//向前#define S22 P1_5//向后#define S23 P1_6//出出#define S24 P1_7//腿拳//兩個選手的led點陣行掃描使能端#define A_1 P0_0#define B_1 P0_1#define C_1 P0_2#define D_1 P0_3//兩個選手的2個595使能端#define SCLK P2_0#define SI P2_1#define RCLK P2_2//當按下S1時 開始游戲,游戲結(jié)束時顯示哪方獲勝,然后按下S2鍵后重新開始新一輪游戲#define S1 P2_6#define S2 P2_7//第一個人的74HC154區(qū)域行選#define NUMLED1OPEN(); {D_1=0;C_1=0;B_1=0;A_1=0;};#define NUMLED2OPEN(); {D_1=0;C_1=0;B_1=0;A_1=1;};#define NUMLED3OPEN(); {D_1=0;C_1=0;B_1=1;A_1=0;};#define NUMLED4OPEN(); {D_1=0;C_1=0;B_1=1;A_1=1;};#define NUMLED5OPEN(); {D_1=0;C_1=1;B_1=0;A_1=0;};#define NUMLED6OPEN(); {D_1=0;C_1=1;B_1=0;A_1=1;};#define NUMLED7OPEN(); {D_1=0;C_1=1;B_1=1;A_1=0;};#define NUMLED8OPEN(); {D_1=0;C_1=1;B_1=1;A_1=1;};#define NUMLED9OPEN(); {D_1=1;C_1=0;B_1=0;A_1=0;};#define NUMLED10OPEN(); {D_1=1;C_1=0;B_1=0;A_1=1;};#define NUMLED11OPEN(); {D_1=1;C_1=0;B_1=1;A_1=0;};#define NUMLED12OPEN(); {D_1=1;C_1=0;B_1=1;A_1=1;};#define NUMLED13OPEN(); {D_1=1;C_1=1;B_1=0;A_1=0;};#define NUMLED14OPEN(); {D_1=1;C_1=1;B_1=0;A_1=1;};#define NUMLED15OPEN(); {D_1=1;C_1=1;B_1=1;A_1=0;};#define NUMLED16OPEN(); {D_1=1;C_1=1;B_1=1;A_1=1;};//0是第一個選手的索引表的開始 80是第二個選手開始在表中的位置#define START1 0#define START2 80#define INIT 16//第一個選手從的初始狀態(tài)在中間 為16#define JUMP_UP_AND_BACK1 48//向后跳起的緩沖動作的位置#define JUMP_UP_AND_BACK2 64//向后跳起的緩沖動作的位置#define BACK 0//在最邊后面的狀態(tài)的位置#define FORTH 32//在最前面的狀態(tài)的位置#define GO 0//游戲的開始畫面 然后按S1開始游戲//#define KO 32#define P1_WIN 64//顯示P1勝利在索引表中的位置#define P2_WIN 96//顯示P2勝利在索引表中的位置//圖像表//人物的各種形態(tài)和位置unsigned char code role_action[]={0x00,0x0C,0x12,0x12,0x0C,0x0C,0x3F,0x33,//左邊小人后退一步的狀態(tài)00x33,0x12,0x1E,0x12,0x12,0x12,0x12,0x00,0x00,0x18,0x24,0x24,0x18,0x18,0x7E,0x66,//左邊小人的初始形態(tài)160x66,0x24,0x3C,0x24,0x24,0x24,0x24,0x00,0x00,0x30,0x48,0x48,0x30,0x30,0xFC,0xCC,//左邊小人前進一步的狀態(tài)320xCC,0x48,0x78,0x48,0x48,0x48,0x48,0x00,0x18,0x24,0x24,0x18,0x18,0x66,0x66,0x65,//左邊小人向右后方向跳起的動作1 480x24,0x3C,0x24,0x12,0x12,0x12,0x00,0x00,0x0C,0x12,0x12,0x0C,0x0C,0x33,0x33,0x53,//左邊小人向右后方向跳起的動作2 640x12,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,//左邊小人的初始形態(tài)960x66,0x24,0x3C,0x24,0x24,0x24,0x24,0x00,0x00,0x0C,0x12,0x12,0x0C,0x0C,0x33,0x33,//右邊小人前進一步的狀態(tài)1120x33,0x12,0x1E,0x12,0x12,0x12,0x12,0x00,0x18,0x24,0x24,0x18,0x18,0x66,0x66,0xA6,//右邊小人向左后方向跳起的動作1 1280x24,0x3C,0x24,0x48,0x48,0x48,0x00,0x00,0x30,0x48,0x48,0x30,0x30,0xCC,0xCC,0xCA,//右邊小人向左后方向跳起的動作2 1440x48,0x78,0x48,0x24,0x24,0x24,0x00,0x00};//開機畫面和結(jié)束時顯示哪方勝利的索引表unsigned char code welecome_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,//KO 320x00,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,//P1 WIN 640x00,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//P2 WIN 96};void delayu(unsigned int time);//延時函數(shù) 延時0.1msvoid delay(unsigned int time);//延時函數(shù) 延時1msvoid NUMLEDOPEN(int i);//74HC154進行行選擇,第i行void dat_in(unsigned char dat);//將8為數(shù)據(jù)從597傳送過去void display_one_page();//先加載各方“血”的狀態(tài),并顯示一張圖片,顯示人的狀態(tài)和血的狀態(tài)void display_scene(int scene);//顯示開機畫面和勝負畫面的函數(shù)void change_buffer_to1(int position);//修改1的圖像狀態(tài)緩沖 從人物索引表的第position個8位數(shù)個開始顯示void change_buffer_to2(int position);//修改2的圖像狀態(tài)緩沖 從人物索引表的第position個8位數(shù)個開始顯示void action_back1();//第1個人向后一步 并將position減1 直到它不能后退void action_back2();//第2個人向后一步 并將position減1 直到它不能后退void action_forth1();//第1個人向前一步 并將position加1 直到它不能后退void action_forth2();//第2個人向前一步 并將position加1 直到它不能后退void fist_change_buff1();//由于1出拳對畫面的改動 要調(diào)用change_buff1_to_bit(int pos)和change_buff1_to_bit_low(int pos)函數(shù)void leg_change_buff1();//由于1出腿對畫面的改動 要調(diào)用change_buff1_to_bit(int pos)和change_buff1_to_bit_low(int pos)函數(shù)void fist_change_buff2();//由于2出拳對畫面的改動 要調(diào)用change_buff1_to_bit(int pos)和change_buff1_to_bit_low(int pos)函數(shù)void leg_change_buff2();//由于2出腿對畫面的改動 要調(diào)用change_buff1_to_bit(int pos)和change_buff1_to_bit_low(int pos)函數(shù)void change_buff1_to_bit(int pos); //將特定某一位置一void change_buff2_to_bit(int pos);//將特定某一位置一void change_buff1_to_bit_low(int pos);//將特定某一位置0void change_buff2_to_bit_low(int pos);//將特定某一位置0void action_fist1();//第1個人出拳 并處理減血情況void action_fist2();//第2個人出拳 并處理減血情況void action_leg1();//第1個人出腿 并處理減血情況void action_leg2();//第2個人出腿 并處理減血情況void scan_key();//這個是函數(shù)的主體部分 分別掃描并處理向后退 向前走 出拳 出腿的動作 當出拳和出腿的時候 開啟定時器//這300ms內(nèi)記錄是否有對方出拳出腿的動作 并按照先掃描向后退 后掃描向前進的順序 掃描一遍 并處理 如果沒有這兩個動作 直接返回調(diào)用出拳//否則處理后再出拳 出腳的道理一致void init_interrupt();//中斷位的設(shè)置//開啟定兩個時器中斷 16位模式void shed_blood1();//記錄流血的數(shù)字void shed_blood2();void main(){int i;while(1){if(S1==0){delay(1);if(S1==0){for(i=0;i
評論