Created
April 8, 2010 05:18
-
-
Save zachelko/359803 to your computer and use it in GitHub Desktop.
Progressively filling a container with rain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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