Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Quiñones <manuq@laptop.org>2012-05-24 20:15:55 (GMT)
committer Manuel Quiñones <manuq@laptop.org>2012-05-24 20:15:55 (GMT)
commit8254afb5ed18706ffb90210747c6beac4d9cf98e (patch)
treed3f2c3822c93e0f98ce0163922abe946bb5269b9
parente45ac5b15ff3925c1a3b8fa9381c4a912fb8be43 (diff)
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 <manuq@laptop.org>
-rw-r--r--test/TestActivity.py1
-rwxr-xr-xtest/TestGame.py12
2 files changed, 11 insertions, 2 deletions
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: