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
Dec 16, 2014


Dec 14, 2014

Dec 9, 2014

Dec 6, 2014

Dec 5, 2014

Dec 3, 2014

Nov 27, 2014


Nov 13, 2014

Nov 11, 2014


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