alestane

Neighbor iterator v0.2

Mar 5th, 2012
192
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 dX, dY
  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.     dX, dY = -dY, dX
  10.     newNeighbor = reference.parent[reference.yTile + dY][reference.xTile + dX]
  11.     if newNeighbor.isTraversable then
  12.         costToNeighbor = 1
  13.     else
  14.         costToNeighbor = math.huge
  15.     end
  16.     return newNeighbor, costToNeighbor
  17. end
Advertisement
Add Comment
Please, Sign In to add comment