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

Re: [pygame] Sprite Collision



Eats up too much CPU?  How do you know? Have you profiled?  Do you have thousands of blocks?

I'd get it working first, with whatever solution works before you start worrying about optimizing.  Also you can always exit the for loop when you find a collision so you don't have to iterate over the whole list.

On 4/30/07, Samuel Mankins <waterflight@xxxxxxxxxxxxx> wrote:
Now that my AI is chasing the Ninja around, I'd like to make it so that
when they bump into a block, they "slide" around it. I figured I'd do
this by having it find out where the block is in relation to the
monster, and then stop moving in the direction that was causing it to
bump into the block. But I don't want to say "for block in block_group"
because that eats up too much CPU, so my question is, how can I figure
out where the block is without using that? Is there an easier way to
solve the problem?
I tried just using ifs to do it (It looked something like: If self.x_dir
== 1 and self.y_dir == 1, self.x_dir = 1 and self.y_dir = 0) but then
the monsters just floated over the blocks.
Thanks!