抖音粉丝群1
『7x24小时有问必答』

AI浪潮下的计算机行业——从业者现状与未来展望

大多数人用手机iPad电脑玩游戏的时候,我们的工程师当大多数人在用触摸屏(HMI)严肃认真编程的时候,有一些人"不务正业"地在把触摸屏当游戏机编写了一个飞机大战游戏!

一、游戏演示

1.gif


二、程序界面及程序

1.程序界面
2.png
2.程序主函数
3.png
    //获取当前物件位置状态
    //当物件位置在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
    3.随机数
    4.png

      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+1
      SetData(number, "Local HMI", LW, 40, 1)

      end macro_command
      4.初始化

      5.png

        macro_command main()
        short pos[3]={0,0,0},stast[3]={1,1,1},score=0
        bool 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


        免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
        您需要登录后才可以回帖 登录 | 立即注册

        本版积分规则

        上一主题上一主题         下一主题下一主题
        QQ手机版小黑屋粤ICP备17165530号

        关于我们·投诉举报· 用户帮助· 联系我们 · 本站服务 · 版权声明· 隐私政策 · 投搞指南

        法律保护:PLC技术网,plcjs.com,plcjs.net等字样
        Copyright 2010-2030. All rights reserved. 


        微信公众号二维码 抖音二维码 百家号二维码 今日头条二维码哔哩哔哩二维码