Results 1 to 3 of 3

Thread: Pygame Circular Collision

  1. #1
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Question Pygame Circular Collision

    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_passedplayer.size)
        if 
    pygame.sprite.collide_circle(playeropponent):  # If opponent is in contact with player:
            
    print 'Contest:'opponent.sizeplayer.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.
    Attached Files Attached Files
    Last edited by Penguin Guy; March 2nd, 2010 at 09:57 PM.

  2. #2
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Pygame Circular Collision

    Obvious question - did you set the rect and/or radius attributes correctly on the sprites ?
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  3. #3
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Pygame Circular Collision

    Quote Originally Posted by Tony Flury View Post
    Obvious question - did you set the rect and/or radius attributes correctly on the sprites ?
    Ahh, it seems I've set rect incorrectly - thanks!
    Last edited by Penguin Guy; March 2nd, 2010 at 08:58 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •