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

Re: [pygame] Strategies for pixel-based collision



> I've thought about defining the bounding box of the car as four vertexes,
> transforming them when I rotate the car and then manually drawing a line
> between them (using Bresenham - has anyone written that in Python? :) and
> checking only those pixels.
> 
> Just wondering whether there's any other ideas out there?


A simple stragegy using circles instead of boxes might work, assuming
that your sprites are relatively square in shape...

Set the radius of your sprite to something slightly smaller than its width.

Measure the distance between the centers of  the two sprites. If the
distance is less than the sum of the two sprite radiuses, you have a
collision. This strategy would cope quite happily with your rotating
sprites.

sw.