SHOW:
|
|
- or go back to the newest paste.
| 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 | |
| 23 | ||
| 24 | function neighborsInMap(start) | |
| 25 | return neighborInSequence, start, nil | |
| 26 | end |