Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function getSuccessors( q )
- local successors = {}
- local region = region.getAtPosition( q )
- local x, y = q.x, q.y
- local w, h = region:getTileSize()
- local directions = {
- [ 1 ] = node( x, y - h ), -- North
- [ 2 ] = nil,
- [ 3 ] = node( x + w, y ), -- East
- [ 4 ] = nil,
- [ 5 ] = node( x, y + h ), -- South
- [ 6 ] = nil,
- [ 7 ] = node( x - w, y ) -- West
- }
- if ( getDirections() == 8 ) then
- merge( directions, {
- [ 2 ] = node( x + w, y - h ), -- North East
- [ 4 ] = node( x + w, y + h ), -- South East
- [ 6 ] = node( x - w, y + h ), -- South West
- [ 8 ] = node( x - w, y - h ) -- North West
- } )
- end
- for _, position in ipairs( directions ) do
- if ( region:isTileWalkableAtPosition( position ) ) then
- insert( successors, position )
- end
- end
- return successors
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement