楼主最近还看过
sub short RAND_num(short para)
RAND(para)
return para
end sub
macro_command main()
bool button_flag[3],game_run,game_over,game_pause,game_init,eat_flag,bool_true = true,bool_false = false
bool display_snake[320],display_init[320]
short direction,pro_direction,get_dir,init_dir = 1
short snake_head_p,snake_cell_p,snake_body_p[318]
short snake_martix[320],snake_pre_martix[320]
short score,best_score,snake_length,speed
short start_rand,next_rand,next_point
short init_index,display_index,count_index,length_index
short temp_body,temp_next_body,temp_last_body
GetData(get_dir, "Local HMI", LW, 0, 1)
GetData(button_flag[0], "Local HMI", LB, 0, 3)
GetData(speed, "Local HMI", RW, 28, 1)
if get_dir==1 and pro_direction<>2 then
direction = 1
pro_direction = 1
else if get_dir==2 and pro_direction<>1 then
direction = 2
回复本条
回复内容:
对:IE5338 sub short RAND_num(short para)RAND(para)return paraend submacro_command main()bool button_flag[3],game_run,game_over,game_pause,game_init,eat_flag,bool_true = true,bool_false = falsebool display_snake[320],display_init[320]short direction,pro_direction,get_dir,init_dir = 1short snake_head_p,snake_cell_p,snake_body_p[318]short snake_martix[320],snake_pre_martix[320]short score,best_score,snake_length,speedshort start_rand,next_rand,next_pointshort init_index,display_index,count_index,length_indexshort temp_body,temp_next_body,temp_last_bodyGetData(get_dir, "Local HMI", LW, 0, 1)GetData(button_flag[0], "Local HMI", LB, 0, 3)GetData(speed, "Local HMI", RW, 28, 1)if get_dir==1 and pro_direction<>2 then direction = 1 pro_direction = 1else if get_dir==2 and pro_direction<>1 then direction = 2 pro_direction = 2else if get_dir==3 and pro_direction<>4 then direction = 3 pro_direction = 3else if get_dir==4 and pro_direction<>3 then direction = 4 pro_direction = 4end ifif button_flag[2] then score = 0 SetData(score, "Local HMI", RW, 20, 1) snake_length = 3 SetData(bool_false, "Local HMI", LB, 100, 1) FILL(display_snake[0],0,320) FILL(display_init[0],0,320) FILL(snake_martix[0],0,320) FILL(snake_pre_martix[0],0,320) eat_flag = false game_over = false game_pause = false game_init = trueend ifif game_init and not button_flag[2] then RAND(start_rand) if start_rand >= 32000 then RAND(start_rand) end if snake_head_p = start_rand/100 if snake_head_p%16 > 2 then snake_body_p[0] = snake_head_p - 1 snake_cell_p = snake_head_p - 2 init_dir = 4 SetData(init_dir, "Local HMI", LW, 0, 1) direction = 4 pro_direction = 4 else if snake_head_p%16 <= 2 then snake_body_p[0] = snake_head_p + 1 snake_cell_p = snake_head_p + 2 init_dir = 3 SetData(init_dir, "Local HMI", LW, 0, 1) direction = 3 pro_direction = 3 end if RAND(next_rand) next_point = next_rand/100 if next_point >= 320 or next_point == snake_head_p or next_point == snake_body_p[0] or next_point == snake_cell_p then RAND(next_rand) end if next_point = next_rand/100 display_init[next_point] = true for init_index = 0 to 319 step 1 if init_index == snake_head_p or init_index == snake_body_p[0] or init_index == snake_cell_p then snake_martix[init_index] = 1 display_snake[init_index] = true display_init[init_index] = true SetData(display_snake[0], "Local HMI", RW_Bit, 0.0, 320) SetData(display_init[0], "Local HMI", RW_Bit, 30.0, 320) end if snake_pre_martix[init_index] = snake_martix[init_index] next init_index game_run = true game_init = false DELAY(80) end ifif game_run then if direction == 1 then if snake_head_p > 15 then if not eat_flag then snake_pre_martix[snake_cell_p] = 0 snake_cell_p = snake_body_p[0] if snake_length>3 then for length_index = 0 to snake_length-4 step 1 //temp_last_body = length_index + 4 temp_next_body = length_index + 1 snake_body_p[length_index] = snake_body_p[temp_next_body] //if temp_next_body == 1 then // break //end if next length_index end if temp_body = snake_length-3 snake_body_p[temp_body] = snake_head_p snake_head_p = snake_head_p - 16 else if eat_flag then for length_index = 3 to 318 step 1 if length_index == snake_length then temp_body = snake_length-3 snake_body_p[temp_body] = snake_head_p snake_head_p = snake_head_p - 16 eat_flag = false TRACE("length_index=%d",length_index) TRACE("snake_body_p[0]=%d",snake_body_p[temp_body]) TRACE("snake_body_p[1]=%d",snake_body_p[temp_body]) TRACE("snake_body_p[0]=%d",snake_body_p[0]) break end if next length_index TRACE("snake_length=%d",snake_length) end if for count_index = 0 to 319 step 1 snake_martix[count_index] = snake_pre_martix[count_index] next count_index snake_martix[snake_head_p] = 1 else if snake_head_p <=15 then game_over = true end if else if direction == 2 then if snake_head_p <= 303 then if not eat_flag then snake_pre_martix[snake_cell_p] = 0 snake_cell_p = snake_body_p[0] if snake_length>3 then for length_index = 0 to snake_length-4 step 1 //temp_last_body = snake_length - 4 temp_next_body = length_index + 1 snake_body_p[length_index] = snake_body_p[temp_next_body] next length_index end if temp_body = snake_length-3 snake_body_p[temp_body] = snake_head_p snake_head_p = snake_head_p + 16 //snake_pre_martix[snake_cell_p] = 0 //for length_index = snake_length down 3 step 1 // temp_body = length_index-3 // snake_cell_p = snake_body_p[temp_body] // snake_body_p[temp_body] = snake_head_p //next length_index //snake_head_p = snake_head_p + 16 else if eat_flag then for length_index = 3 to 318 step 1 if length_index == snake_length then temp_body = snake_length-3 snake_body_p[temp_body] = snake_head_p snake_head_p = snake_head_p + 16 eat_flag = false TRACE("length_index=%d",length_index) TRACE("snake_body_p[0]=%d",snake_body_p[temp_body]) TRACE("snake_body_p[1]=%d",snake_body_p[temp_body]) TRACE("snake_body_p[0]=%d",snake_body_p[0]) break end if next length_index end if for count_index = 0 to 319 step 1 snake_martix[count_index] = snake_pre_martix[count_index] next count_index snake_martix[snake_head_p] = 1 else if snake_head_p > 303 then game_over = true end if else if direction == 3 then if snake_head_p<>0 and snake_head_p<>16 and snake_head_p<>32 and snake_head_p<>48 and snake_head_p<>64 and snake_head_p<>80 and snake_head_p<>96 and snake_head_p<>112 and snake_head_p<>128 and snake_head_p<>144 and snake_head_p<>160 and snake_head_p<>176 and snake_head_p<>192 and snake_head_p<>208 and snake_head_p<>224 and snake_head_p<>240 and snake_head_p<>256 and snake_head_p<>272 and snake_head_p<>288 and snake_head_p<>304 then if not eat_flag then snake_pre_martix[snake_cell_p] = 0 snake_cell_p = snake_body_p[0] if snake_length>3 then for length_index = 0 to snake_length-4 step 1 //temp_last_body = snake_length - 4 temp_next_body = length_index + 1 snake_body_p[length_index] = snake_body_p[temp_next_body] next length_index end if temp_body = snake_length-3 snake_body_p[temp_body] = snake_head_p snake_head_p = snake_head_p - 1 //snake_pre_martix[snake_cell_p] = 0 //for length_index = snake_length down 3 step 1 // temp_body = length_index-3 // snake_cell_p = snake_body_p[temp_body] // snake_body_p[temp_body] = snake_head_p //next length_index //snake_head_p = snake_head_p - 1 else if eat_flag then for length_index = 3 to 318 step 1 if length_index == snake_length then temp_body = snake_length-3 snake_body_p[temp_body] = snake_head_p snake_head_p = snake_head_p - 1 eat_flag = false TRACE("length_index=%d",length_index) TRACE("snake_body_p[0]=%d",snake_body_p[temp_body]) TRACE("snake_body_p[1]=%d",snake_body_p[temp_body]) TRACE("snake_body_p[0]=%d",snake_body_p[0]) break end if next length_index end if for count_index = 0 to 319 step 1 snake_martix[count_index] = snake_pre_martix[count_index] next count_index snake_martix[snake_head_p] = 1 else if snake_head_p==0 or snake_head_p==16 or snake_head_p==32 or snake_head_p==48 or snake_head_p==64 or snake_head_p==80 or snake_head_p==96 or snake_head_p==112 or snake_head_p==128 or snake_head_p==144 or snake_head_p==160 or snake_head_p==176 or snake_head_p==192 or snake_head_p==208 or snake_head_p==224 or snake_head_p==240 or snake_head_p==256 or snake_head_p==272 or snake_head_p==288 or snake_head_p==304 then game_over = true end if else if direction == 4 then if snake_head_p<>15 and snake_head_p<>31 and snake_head_p<>47 and snake_head_p<>63 and snake_head_p<>79 and snake_head_p<>95 and snake_head_p<>111 and snake_head_p<>127 and snake_head_p<>143 and snake_head_p<>159 and snake_head_p<>175 and snake_head_p<>191 and snake_head_p<>207 and snake_head_p<>223 and snake_head_p<>239 and snake_head_p<>255 and snake_head_p<>271 and snake_head_p<>287 and snake_head_p<>303 and snake_head_p<>319 then if not eat_flag then snake_pre_martix[snake_cell_p] = 0 snake_cell_p = snake_body_p[0] if snake_length>3 then for length_index = 0 to snake_length-4 step 1 //temp_last_body = snake_length - 4 temp_next_body = length_index + 1 snake_body_p[length_index] = snake_body_p[temp_next_body] next length_index end if temp_body = snake_length-3 snake_body_p[temp_body] = snake_head_p snake_head_p = snake_head_p + 1 //snake_pre_martix[snake_cell_p] = 0 //for length_index = snake_length down 3 step 1 // temp_body = length_index-3 // snake_cell_p = snake_body_p[temp_body] // snake_body_p[temp_body] = snake_head_p //next length_index //snake_head_p = snake_head_p + 1 else if eat_flag then for length_index = 3 to 318 step 1 if length_index == snake_length then temp_body = snake_length-3 snake_body_p[temp_body] = snake_head_p snake_head_p = snake_head_p + 1 eat_flag = false TRACE("length_index=%d",length_index) TRACE("snake_body_p[0]=%d",snake_body_p[temp_body]) TRACE("snake_body_p[1]=%d",snake_body_p[temp_body]) TRACE("snake_body_p[0]=%d",snake_body_p[0]) break end if next length_index end if for count_index = 0 to 319 step 1 snake_martix[count_index] = snake_pre_martix[count_index] next count_index snake_martix[snake_head_p] = 1 else if snake_head_p==15 or snake_head_p==31 or snake_head_p==47 or snake_head_p==63 or snake_head_p==79 or snake_head_p==95 or snake_head_p==111 or snake_head_p==127 or snake_head_p==143 or snake_head_p==159 or snake_head_p==175 or snake_head_p==191 or snake_head_p==207 or snake_head_p==223 or snake_head_p==239 or snake_head_p==255 or snake_head_p==271 or snake_head_p==287 or snake_head_p==303 or snake_head_p==319 then game_over = true end if end if for display_index = 0 to 319 step 1 //if display_index == snake_head_p or display_index == snake_body_p[0] or display_index == snake_cell_p then if snake_martix[display_index] == 1 then display_snake[display_index] = true display_init[display_index] = true //TRACE("snake_martix[display_index]=%d",snake_martix[display_index]) //TRACE("display_index=%d",display_index) else if snake_martix[display_index] <> 1 then display_snake[display_index] = false display_init[display_index] = false end if snake_pre_martix[display_index] = snake_martix[display_index] next display_index if next_point == snake_head_p then RAND(next_rand) next_point = next_rand/100 if next_point >= 320 or next_point == snake_head_p or next_point == snake_body_p[0] or next_point == snake_cell_p then RAND(next_rand) end if next_point = next_rand/100 snake_length = snake_length + 1 eat_flag = true score = score + 1 SetData(score, "Local HMI", RW, 20, 1) end if display_init[next_point] = true SetData(display_snake[0], "Local HMI", RW_Bit, 0.0, 320) SetData(display_init[0], "Local HMI", RW_Bit, 30.0, 320) if score>best_score then best_score = score SetData(score, "Local HMI", RW, 21, 1) end if DELAY(speed)end ifif game_over then game_run = false SetData(bool_true, "Local HMI", LB, 100, 1) game_over = falseend ifif button_flag[0] then game_run = trueend ifif button_flag[1] then game_run = falseend ifend macro_command 内容的回复:感谢分享,周立齐,现代著名 思想家,教育家,哲学家,文学家;代表作有《窃·格瓦拉大年三十不回家》、《不打工的秘密》、《电瓶终结者》《苦命的电瓶车啊,名震江湖的窃格瓦拉为你撑起一片天》《浮生六窃》《我为什么拒绝打工》《别人避之不及的看守所,我的安身之地》《南宁,今夜请将我遗忘》
回复本条