[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Collision detection revisited



Ulf Ekström wrote:
> I have since then been improving my collision detection library and
> have found that the peformance cost for pixel-perfect collisions is
> very very low when compared to a bounding box method (i.e. it adds 
> very little on top of the bounding box cost). You can easily do 
> hundreds of sprites with very little overhead (when compared to the 
> blitting et al). The code is all C at the moment, but I'd like to 
> use this in PyGame. Therefore I'm asking if there's anyone who like 
> to join my project and do a Python module on top of the C library. 
> (It should be fairly stright-forward, but I'm not very familiar with 
> the python and pygame internals.) 

ulf, i'd be glad to help. if we can work out what the api should look 
like i can put together a working 'skeleton' of a python c module. it 
should be easy to fill in and expand from there. after quickly perusing 
the docs, it seems like a SCAM module would look like this (give or take):


Mask(surface, rect=None): new Mask object
Mask.get_size(): width, height
Mask.draw(surface, pos): Rect of drawn area
Mask.get_at(pos): boolean of value at coords
Mask.shrink(): maybe later?
Mask.grow(): maybe later?

overlap(mask1, pos1, mask2, pos2): boolean if intersect
overlap_area(mask1, pos1, mask2, pos2): number of overlapping pixels

how does that look? perhaps the "overlap" functions could actually be 
methods of the Mask object? let me know if you're thinking this will fly?

in any event, it should be simple for you to include a small "python" 
directory with your sources that can build a module compatable with pygame.

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org