[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Pathfinding



Yanom Mobis wrote:
ok, i didn't get any of that

There's a mask module in pygame with a Mask class that contains one bit per pixel. It's not in the online docs yet, but in svn head there's a method called convolve that takes in another Mask. If you start with a Mask (lets call it map) which has the corresponding bit set if there's an obstacle there, and another Mask (call it player) which has the shape of your player, then map.convolve(player) will have the (x,y) bit set if the player can be moved to (x,y). Then you can do your pathfinding in that mask with A* or whatever, and the resulting path will be one where the player never touches an obstacle.

If your map is small, this will be feasible, but if it's large then building and searching a pixel-based map of the whole area will possibly take too long and you'd need to do something smarter.

--Mike