View difference between Paste ID: hhRZdSDb and 9DJVSNd3
SHOW: | | - or go back to the newest paste.
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
	if dY = -1 and lastNeighbor then
11
		return
12
	end
13
	newNeighbor = reference.parent[reference.yTile + dY][reference.xTile + dX]
14
	if newNeighbor.isTraversable then
15
		costToNeighbor = 1
16
	else
17
		costToNeighbor = math.huge
18
	end
19
	return newNeighbor, costToNeighbor
20
end