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
Oct 28, 2014

Oct 21, 2014

Oct 20, 2014

Oct 16, 2014

Oct 9, 2014

Oct 8, 2014

Oct 7, 2014

Oct 4, 2014

Oct 1, 2014

Sep 19, 2014

Sep 17, 2014

Sep 9, 2014

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