Skip to content

Instantly share code, notes, and snippets.

@zachelko
Created April 8, 2010 05:18
Show Gist options
  • Save zachelko/359803 to your computer and use it in GitHub Desktop.
Save zachelko/359803 to your computer and use it in GitHub Desktop.
Progressively filling a container with rain
def render(self, screen):
screen.blit(self.image, (self.rect.x, self.rect.y))
if (self.drops > 0):
x = self.rect.x + 2
rainColor = ()
if (self.full):
level = 1
rainColor = (255,0,0)
else:
level = ( float(self.drops) / float(self.capacity) )
# Normalize if full
# TODO: Can this even happen?
if (level > 1): level = 1
rainColor = (67,173,255)
y = screen.get_height() - level * self.image.get_height()
# Normalize if full
if (y >= self.rect.y): y += 5
w = self.image.get_width() - 5
color = ()
pygame.draw.rect(screen, rainColor, Rect(x, y, w, y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment