Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. local function getSuccessors( q )
  2. local successors = {}
  3. local region = region.getAtPosition( q )
  4. local x, y = q.x, q.y
  5. local w, h = region:getTileSize()
  6.  
  7. local directions = {
  8. [ 1 ] = node( x, y - h ), -- North
  9. [ 2 ] = nil,
  10. [ 3 ] = node( x + w, y ), -- East
  11. [ 4 ] = nil,
  12. [ 5 ] = node( x, y + h ), -- South
  13. [ 6 ] = nil,
  14. [ 7 ] = node( x - w, y ) -- West
  15. }
  16.  
  17. if ( getDirections() == 8 ) then
  18. merge( directions, {
  19. [ 2 ] = node( x + w, y - h ), -- North East
  20. [ 4 ] = node( x + w, y + h ), -- South East
  21. [ 6 ] = node( x - w, y + h ), -- South West
  22. [ 8 ] = node( x - w, y - h ) -- North West
  23. } )
  24. end
  25.  
  26. for _, position in ipairs( directions ) do
  27. if ( region:isTileWalkableAtPosition( position ) ) then
  28. insert( successors, position )
  29. end
  30. end
  31.  
  32. return successors
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement