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

Re: [pygame] Sprite Collision



I assume it's eating up CPU, it's doing something so that the game slows down the point where updates take about a half a second. I don't have thousands of blocks, but I do have a fair amount, something in the vicinity of fifty, and three monsters.
I'm using for so I can access the attributes of the individual blocks, not to detect the collision. Is there another way?
Thanks!


Jason Massey wrote:
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 <mailto: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!