//获取当前物件位置状态
//当物件位置在720-900之间,返回TRUE,否则返回FALSE
sub position_state()
bool position[3]={0,0,0}short pos[3]={0,0,0}GetData(pos[0], "Local HMI", LW, 1, 1)
GetData(pos[1], "Local HMI", LW, 11, 1)
GetData(pos[2], "Local HMI", LW, 21, 1)
if pos[0]>=720 and pos[0]<=900 then
position[0]=true
else
position[0]=false
end if
if pos[1]>=720 and pos[1]<=900 then
position[1]=true
else
position[1]=false
end if
if pos[2]>=720 and pos[2]<=900 then
position[2]=true
else
position[2]=false
end if
SetData(position[0], "Local HMI", LB, 10, 3)
end sub
//判断游戏结束标志位
//获取position_state()函数状态
//当position为TRUE,且plane与物件在同一个赛道上,返回FALSE
sub bool endgame()
bool position[3],over=false,restart=true
short plane=0
GetData(position[0], "Local HMI", LB, 10, 3)
GetData(plane, "Local HMI", LW, 31, 1)
if position[0]==true and plane == 0 then
SetData(restart, "Local HMI", LB, 2, 1)
SetData(over, "Local HMI", LB, 0, 1)
return false
else if position[1]==true and plane == 200 then
SetData(restart, "Local HMI", LB, 2, 1)
SetData(over, "Local HMI", LB, 0, 1)
return false
else if position[2]==true and plane == 400 then
SetData(restart, "Local HMI", LB, 2, 1)
SetData(over, "Local HMI", LB, 0, 1)
return false
end if
end sub
//设定游戏运动速度
sub unsigned short speed()
short setting=0
GetData(setting, "Local HMI", LW, 3, 1)
select case setting
case 0
return 15
break
case 1
return 20
break
case 2
return 25
break
end select
end sub
macro_command main()
short pos[3],state[3],plane=0
bool start=0,over=1,ready_mov[3],ready_mov_delay[3],restart=0,position[3]
unsigned short startgame=0,ready_number=0,numbermax=100,movepoint=0,score
//周期获取开始状态,用于启动游戏主函数
GetData(start, "Local HMI", LB, 0, 1)
movepoint=speed()
if start == true then
GetData(score, "Local HMI", LW, 5, 1)
GetData(ready_mov[0], "Local HMI", LB, 20, 3)
//判断游戏继续还是结束
GetData(pos[0], "Local HMI", LW, 1, 1)
GetData(pos[1], "Local HMI", LW, 11, 1)
GetData(pos[2], "Local HMI", LW, 21, 1)
position_state()
//判断哪个点位开始执行运动
GetData(ready_number, "Local HMI", LW, 40, 1)
if ready_number==1 and pos[0]==0 then
ready_mov[0]=true
else if ready_number==2 and pos[1]==0 then
ready_mov[1]=true
else if ready_number==3 and pos[2]==0 then
ready_mov[2]=true
end if
SetData(ready_mov[0], "Local HMI", LB, 20, 3)
//允许运动后,每一步移动movepoint个单位
GetData(ready_mov_delay[0], "Local HMI", LB, 40, 3)
if ready_mov_delay[0]==true and pos[0] < 1000 then
state[0]=0
pos[0]=pos[0]+movepoint
SetData(state[0], "Local HMI", LW, 0, 1)
SetData(pos[0], "Local HMI", LW, 1, 1)
else if ready_mov_delay[0]==true and pos[0] >= 1000 then
ready_mov[0]=false
ready_mov_delay[0]=false
pos[0]=0
state[0]=1
score=score+1
SetData(state[0], "Local HMI", LW, 0, 1)
SetData(pos[0], "Local HMI", LW, 1, 1)
SetData(ready_mov_delay[0], "Local HMI", LB, 20, 1)
SetData(ready_mov_delay[0], "Local HMI", LB, 40, 1)
else
end if
if ready_mov_delay[1]==true and pos[1] < 1000 then
state[1]=0
pos[1]=pos[1]+movepoint
SetData(state[1], "Local HMI", LW, 10, 1)
SetData(pos[1], "Local HMI", LW, 11, 1)
else if ready_mov_delay[1]==true and pos[1] >= 1000 then
ready_mov[1]=false
ready_mov_delay[1]=false
pos[1]=0
state[1]=1
score=score+1
SetData(state[1], "Local HMI", LW, 10, 1)
SetData(pos[1], "Local HMI", LW, 11, 1)
SetData(ready_mov_delay[1], "Local HMI", LB, 21, 1)
SetData(ready_mov_delay[1], "Local HMI", LB, 41, 1)
else
end if
if ready_mov_delay[2]==true and pos[2] < 1000 then
state[2]=0
pos[2]=pos[2]+movepoint
SetData(state[2], "Local HMI", LW, 20, 1)
SetData(pos[2], "Local HMI", LW, 21, 1)
else if ready_mov_delay[2]==true and pos[2] >= 1000 then
ready_mov[2]=false
ready_mov_delay[2]=false
pos[2]=0
state[2]=1
score=score+1
SetData(state[2], "Local HMI", LW, 20, 1)
SetData(pos[2], "Local HMI", LW, 21, 1)
SetData(ready_mov_delay[2], "Local HMI", LB, 22, 1)
SetData(ready_mov_delay[2], "Local HMI", LB, 42, 1)
else
end if
SetData(score, "Local HMI", LW, 5, 1)
start=endgame()
end if
end macro_command
macro_command main()
short pos[3]={0,0,0},stast[3]={1,1,1},score=0bool off[3]={0,0,0}SetData(off[0], "Local HMI", LB, 20, 3)
SetData(stast[0], "Local HMI", LW, 0, 1)
SetData(pos[0], "Local HMI", LW, 1, 1)
SetData(stast[1], "Local HMI", LW, 10, 1)
SetData(pos[1], "Local HMI", LW, 11, 1)
SetData(stast[2], "Local HMI", LW, 20, 1)
SetData(pos[2], "Local HMI", LW, 21, 1)
SetData(score, "Local HMI", LW, 5, 1)
end macro_command