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

[pygame] Fwd: Collision Detection



This message written by Chris Armstrong, but rejected by the mailing
list server. I've forwarded it along.

-----------------------------------------------------------------------
Ok all, I've come to the part of my breakout game where I need to write the
collision detection code.

#update the balls.
sprite_rects = []
for x in self.vis_sprites:
    sprite_rects.append(x.rect)
for ball in self.balls:
    ball.Move()
    for target in ball.rect.collidelistall(sprite_rects):
self.vis_sprites[target].Ball_hit()
ball.Bounce()
del sprite_rects

The contents of self.balls is also in self.vis_sprites. Currently the only
sprites in vis_sprite are the paddle and the ball. There is only one ball
in self.balls. The problem I'm having is that since the rect for the ball
we're currently calculating is also in sprite_rects, so at every iteration
it's detecting a collision, with itself. I can't figure out an elegant way
to fix this. Thanks for any help I might get! :)

--
Chris Armstrong        http://www.dynup.net:8010/       carmstro@dynup.net
There is a 90% chance that this message was written when the author's been
awake longer than he should have. Please disregard any senseless drivel.

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