SOLVED: Turns out the rect was set wrong - I'd set it using rect = (x, y, w, h) rather than rect = pygame.Rect(x, y, w, h).
----------------------------------------
I've been trying to detect if a object 'player' is in contact with any opponents in Pygame. I'm using the function pygame.sprite.collide_circle() - although obviously incorrectly. I couldn't find much documentation on it, and what documentation I found, I didn't understand. I'd be grateful if somebody could give me a pointer.
Here's the relevant code (full package attached):
[PYTHON]
PHP Code:
# Update all opponents
for opponent in opponents:
opponent.update(time_passed, player.size)
if pygame.sprite.collide_circle(player, opponent): # If opponent is in contact with player:
print 'Contest:', opponent.size, player.size
if opponent.size > player.size: # Biggest contestant eats the other
opponent.eat(player)
game_over()
if opponent.size < player.size:
player.eat(opponent)
The output I get is:
Code:
Contest: 75 78
Contest: 65 78
Contest: 65 78
Contest: 75 78
Contest: 78 78
Contest: 53 78
Contest: 75 78
Contest: 65 78
Contest: 65 78
Contest: 75 78
Contest: 78 78
Contest: 53 78
...
(a.k.a. recurring output of the highlighted text)
I'm 99% sure that pygame.sprite.collide_circle(player, opponent) is returning True regardless of the positions of player and opponent.
Bookmarks