Advertisement
alestane

Neighbor iterator v0.4

Mar 5th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function neighborInSequence(reference, lastNeighbor)
  2.     local newNeighbor, costToNeighbor
  3.     local x, y
  4.     if not lastNeighbor then
  5.         dX, dY = -1, 0
  6.     else
  7.         dX, dY = lastNeighbor.xTile - reference.xTile, lastNeighbor.yTile - reference.yTile
  8.     end
  9.     repeat
  10.         dX, dY = -dY, dX
  11.         if dY = -1 and lastNeighbor then
  12.             return
  13.         end
  14.         newNeighbor = reference.parent[reference.yTile + dY][reference.xTile + dX]
  15.     until newNeighbor
  16.     if newNeighbor.isTraversable then
  17.         costToNeighbor = 1
  18.     else
  19.         costToNeighbor = math.huge
  20.     end
  21.     return newNeighbor, costToNeighbor
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement