qq240559043
干就完了
級別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 191 個(gè)
工控威望: 332 點(diǎn)
下載積分: 4111 分
在線時(shí)間: 144(小時(shí))
注冊時(shí)間: 2012-06-06
最后登錄: 2024-12-19
查看qq240559043的 主題 / 回貼
樓主  發(fā)表于: 2022-06-16 16:09
圖片:
圖片:
圖片:
//**********************************************************開始游戲
if start == true and snake_len == 0 then
   snake_pos_x[0] = 9
   snake_pos_y[0] = 9
   snake_len = 1
   //繪制小蛇
   for index = 0 to snake_len - 1
       snake_index = snake_pos_y[index] * 20 + snake_pos_x[index]
       SetData(ON, "Local HMI", LB, snake_index, 1)
   next
   SetData(ON, "Local HMI", LB, 2000, 1)
end if
//**********************************************************暫停游戲
if stop then
   SetData(OFF, "Local HMI", LB, 1001, 1)
   SetData(OFF, "Local HMI", LB, 1002, 1)
   start = false
end if
if snake_len > 0 and start == true then

   ////**********************************************************
   ////**********************************************小蛇向上移動
   ////**********************************************************
   if snake_UP == true and snake_DOWN == false then
      //清除小蛇
      for index = 0 to snake_len-1
          snake_index = snake_pos_y[index] * 20 + snake_pos_x[index]
          SetData(OFF, "Local HMI", LB, snake_index, 1)
      next
      
      //蛇頭撞墻
      if snake_pos_y[0] == 0 then
         game_over = true
         SetData(ON, "Local HMI", LB, 2010, 1)
      else
         snake_len1  = snake_len-1
         snake_tail_pos_x = snake_pos_x[snake_len1]
         snake_tail_pos_y = snake_pos_y[snake_len1]
         snake_head_pos_x = snake_pos_x[0]
         snake_head_pos_y = snake_pos_y[0] - 1