From 8254afb5ed18706ffb90210747c6beac4d9cf98e Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Thu, 24 May 2012 20:15:55 +0000 Subject: Test activity: move the ball with left/right arrow keys This is to test that the key events are captured by PyGame. Signed-off-by: Manuel QuiƱones --- diff --git a/test/TestActivity.py b/test/TestActivity.py index 1338ff2..9569659 100644 --- a/test/TestActivity.py +++ b/test/TestActivity.py @@ -35,6 +35,7 @@ class TestActivity(sugar.activity.activity.Activity): # Note that set_canvas implicitly calls read_file when # resuming from the Journal. self.set_canvas(self._pygamecanvas) + self._pygamecanvas.grab_focus() # Start the game running (self.game.run is called when the # activity constructor returns). diff --git a/test/TestGame.py b/test/TestGame.py index 223c675..590b921 100755 --- a/test/TestGame.py +++ b/test/TestGame.py @@ -15,6 +15,7 @@ class TestGame: self.vy = 0 self.paused = False + self.direction = 1 def set_paused(self, paused): self.paused = paused @@ -44,12 +45,19 @@ class TestGame: return elif event.type == pygame.VIDEORESIZE: pygame.display.set_mode(event.size, pygame.RESIZABLE) + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + self.direction = -1 + elif event.key == pygame.K_RIGHT: + self.direction = 1 # Move the ball if not self.paused: - self.x += self.vx - if self.x > screen.get_width() + 100: + self.x += self.vx * self.direction + if self.direction == 1 and self.x > screen.get_width() + 100: self.x = -100 + elif self.direction == -1 and self.x < -100: + self.x = screen.get_width() + 100 self.y += self.vy if self.y > screen.get_height() - 100: -- cgit v0.9.1