SHOW:
|
|
- or go back to the newest paste.
1 | local function neighborInSequence(reference, lastNeighbor) | |
2 | local newNeighbor, costToNeighbor | |
3 | - | local dX, dY |
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 | - | dX, dY = -dY, dX |
9 | + | repeat |
10 | - | if dY = -1 and lastNeighbor then |
10 | + | dX, dY = -dY, dX |
11 | - | return |
11 | + | if dY = -1 and lastNeighbor then |
12 | return | |
13 | - | newNeighbor = reference.parent[reference.yTile + dY][reference.xTile + dX] |
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 |