diff options
author | Wade Brainerd <wadetb@gmail.com> | 2009-10-30 07:27:07 (GMT) |
---|---|---|
committer | Wade Brainerd <wadetb@gmail.com> | 2009-10-30 07:27:07 (GMT) |
commit | 30f43754e2924f4cfb19631b1c6549d438ba35d3 (patch) | |
tree | 6f365b86845ba54eb5e7e7adb694b5314d254a4f /test | |
parent | 3ae993cd446cbd737dee890fd440688f16fc0911 (diff) |
Add bouncing ball to test game.
Diffstat (limited to 'test')
-rwxr-xr-x | test/TestGame.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/test/TestGame.py b/test/TestGame.py index da99ad8..2c96803 100755 --- a/test/TestGame.py +++ b/test/TestGame.py @@ -6,10 +6,14 @@ class TestGame: def __init__(self): # Set up a clock for managing the frame rate. self.clock = pygame.time.Clock() - - # Set up a font for rendering. - pygame.font.init() - self.font = pygame.font.Font(None, 24) + + self.x = -100 + self.y = 100 + + self.vx = 10 + self.vy = 0 + + self.paused = False def set_paused(self, paused): self.paused = paused @@ -38,9 +42,25 @@ class TestGame: if event.type == pygame.QUIT: return + # Move the ball + if not self.paused: + self.x += self.vx + if self.x > screen.get_width() + 100: + self.x = -100 + + self.y += self.vy + if self.y > screen.get_height() - 100: + self.y = screen.get_height() - 100 + self.vy = -self.vy + + self.vy += 5; + # Clear Display screen.fill((255,255,255)) #255 for white + # Draw the ball + pygame.draw.circle(screen, (255,0,0), (self.x, self.y), 100) + # Flip Display pygame.display.flip() |