pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Wiki

SmallerRectForSpriteCollision

      
Search:  
 
 
To get sprite collsion methods to use a different member Rect can be useful. I use my Sprite.rect for rendering purposes, and want a smaller rect for collision detection. To get that effect I added the method below to my Charactor class:
# TODO: make this method more generic, so it can be used outside of your
# program.
def am_in_collision(self):
    v_shrink_by=.7
    h_shrink_by=.45
    smaller_me=self.rect.inflate(-self.rect.width*h_shrink_by,
        -self.rect.height*v_shrink_by)
    allsprites2=allsprites.copy()
    allsprites2.remove(self)
    smaller_all=[sprite.rect.inflate(-sprite.rect.width*h_shrink_by,
        -sprite.rect.height*v_shrink_by) for sprite in allsprites2]
    return bool(smaller_me.collidelistall(smaller_all))
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Apr 21, 2014


Apr 19, 2014

Apr 16, 2014

Apr 13, 2014

Apr 9, 2014

Mar 18, 2014


Mar 15, 2014


Mar 14, 2014

Mar 13, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)