找出地圖四角巡邏點和自動巡邏

分享用連結:https://goo.gl/hnI4PR
Corner_X,Corner_Y = {},{}

repeat Corner_X [5],Corner_Y [5] = math.random(5,game.map.size.x - 5),math.random(5,game.map.size.y - 5)until game.map.isStandable(Corner_X [5],Corner_Y [5]) for x = 0 ,game.map.size.x - 1 do
for y = 0,game.map.size.y - 1 do if game.map.isStandable(x, y) then Corner_X [1],Corner_Y [1] = x,y break end end if Corner_X [1] ~= nil then break endend for x = game.map.size.x - 1, 0, -1 do for y = 0,game.map.size.y - 1 do if game.map.isStandable(x, y) then Corner_X [2],Corner_Y [2] = x,y break end end if Corner_X [2] ~= nil then break endend for x = 0 ,game.map.size.x - 1 do for y = game.map.size.y - 1, 0, -1 do if game.map.isStandable(x, y) then Corner_X [3],Corner_Y [3] = x,y break end end if Corner_X [3] ~= nil then break endend for x = game.map.size.x - 1, 0, -1 do for y = game.map.size.y - 1, 0, -1 do if game.map.isStandable(x, y) then Corner_X [4],Corner_Y [4] = x,y break end end if Corner_X [4] ~= nil then break endend




程度十分簡單,採用一維陣列(array)和迴圈的方法,

Corner_X [1] 是左上的巡邏點,Corner_X [2] 是右上的巡邏點,

Corner_X [3] 是左下的巡邏點,Corner_X [4] 是右下的巡邏點,

首4個for..do..end是分別用作找出地圖四角巡邏點(左上 右上 左下 右下),

以下用其中一個作說明: