Skip to content

Instantly share code, notes, and snippets.

@zachelko
Created April 8, 2010 04:14
Show Gist options
  • Save zachelko/359768 to your computer and use it in GitHub Desktop.
Save zachelko/359768 to your computer and use it in GitHub Desktop.
Exclude rain drops below the beaker
# Find the shortest beaker so we know which drops to check for collisions
# against
beakerHeights = []
shortest = 0
for beaker in level.beakers: beakerHeights.append(beaker.rect.y)
beakerHeights.sort()
if (beakerHeights): shortest = beakerHeights[0]
# Get the current drops to test for collisions
drops=pygame.sprite.Group()
for cloud in level.clouds:
for drop in cloud.drops:
# Only check for collisions with drops that are above or = to the top
# of the shortest beaker
if (drop.rect.y <= shortest):
drops.add(drop)
for beaker in pygame.sprite.groupcollide(level.beakers, drops, False, True).keys():
beaker.takeDrop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment