public NavPath findPath ( float sx , float sy , float tx , float ty , boolean optimize ) { Space source = findSpace ( sx , sy ) ; Space target = findSpace ( tx , ty ) ; if ( ( source == null ) || ( target == null ) ) { return null ; } for ( int i = 0 ; i < spaces . size ( ) ; i ++ ) { ( ( Space ) spaces . get ( i ) ) . clearCost ( ) ; } target . fill ( source , tx , ty , 0 ) ; if ( target . getCost ( ) == Float . MAX_VALUE ) { return null ; } if ( source . getCost ( ) == Float . MAX_VALUE ) { return null ; } NavPath path = new NavPath ( ) ; path . push ( new Link ( sx , sy , null ) ) ; if ( source . pickLowestCost ( target , path ) ) { path . push ( new Link ( tx , ty , null ) ) ; if ( optimize ) { optimize ( path ) ; } return path ; } return null ; }
Find a path from the source to the target coordinates