怎么样在威纶通触摸屏上玩飞机大战?

[复制链接]
查看30276 | 回复0 | 2024-5-29 08:41:48 | 显示全部楼层 |阅读模式
大多数人用手机iPad电脑玩游戏的时候,我们的工程师当大多数人在用触摸屏(HMI)严肃认真编程的时候,有一些人"不务正业"地在把触摸屏当游戏机编写了一个飞机大战游戏!

一、游戏演示



二、程序界面及程序
1.程序界面

2.程序主函数

//获取当前物件位置状态//当物件位置在720-900之间,返回TRUE,否则返回FALSEsub 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 thenposition[0]=trueelseposition[0]=falseend ifif pos[1]>=720 and pos[1]<=900 thenposition[1]=trueelseposition[1]=falseend ifif pos[2]>=720 and pos[2]<=900 thenposition[2]=trueelseposition[2]=falseend ifSetData(position[0], "Local HMI", LB, 10, 3)end sub//判断游戏结束标志位//获取position_state()函数状态//当position为TRUE,且plane与物件在同一个赛道上,返回FALSEsub boolendgame()bool position[3],over=false,restart=trueshort plane=0GetData(position[0], "Local HMI", LB, 10, 3)GetData(plane, "Local HMI", LW, 31, 1)if position[0]==true and plane == 0thenSetData(restart, "Local HMI", LB, 2, 1)SetData(over, "Local HMI", LB, 0, 1)return falseelse if position[1]==true and plane == 200thenSetData(restart, "Local HMI", LB, 2, 1)SetData(over, "Local HMI", LB, 0, 1)return falseelse if position[2]==true and plane == 400thenSetData(restart, "Local HMI", LB, 2, 1)SetData(over, "Local HMI", LB, 0, 1)return falseend ifend sub//设定游戏运动速度sub unsigned shortspeed()short setting=0GetData(setting, "Local HMI", LW, 3, 1)selectcase settingcase0return15breakcase1return20breakcase2return25breakend selectend sub
macro_command main()short pos[3],state[3],plane=0bool 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 thenGetData(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 thenready_mov[0]=trueelseif ready_number==2 and pos[1]==0 thenready_mov[1]=trueelseif ready_number==3 and pos[2]==0 thenready_mov[2]=trueend ifSetData(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 thenstate[0]=0pos[0]=pos[0]+movepointSetData(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 thenready_mov[0]=falseready_mov_delay[0]=falsepos[0]=0state[0]=1score=score+1SetData(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)elseend if
if ready_mov_delay[1]==true and pos[1] < 1000 thenstate[1]=0pos[1]=pos[1]+movepointSetData(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 thenready_mov[1]=falseready_mov_delay[1]=falsepos[1]=0state[1]=1score=score+1SetData(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)elseend if
if ready_mov_delay[2]==true and pos[2] < 1000 thenstate[2]=0pos[2]=pos[2]+movepointSetData(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 thenready_mov[2]=falseready_mov_delay[2]=falsepos[2]=0state[2]=1score=score+1SetData(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)elseend ifSetData(score, "Local HMI", LW, 5, 1)start=endgame()end if
end macro_command3.随机数



macro_command main()
unsigned short number=0,a=0,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)RAND(number)number=number%3+1SetData(number, "Local HMI", LW, 40, 1)
end macro_command4.初始化


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

案例下载地址:https://www.weinview.cn/Admin/Others/DownloadsPage.aspx?nid=3&id=40542&tag=0&ref=download&t=ce728729acd7b9fb

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册哦

x
您需要登录后才可以回帖 登录 | 注册哦

本版积分规则