....
I'm just going to make my game tile-based, I guess.

--- On Wed, 1/28/09, Michael George <mdgeo...@cs.cornell.edu> wrote:

From: Michael George <mdgeo...@cs.cornell.edu>
Subject: Re: [pygame] Pathfinding
To: pygame-users@seul.org
Date: Wednesday, January 28, 2009, 8:41 AM

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



      

Reply via email to