[Sugar-devel] [PATCH 6/6] Move the ball with left/right arrow keys in the test activity

Manuel Quiñones manuq at laptop.org
Mon May 14 15:51:59 EDT 2012


Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 test/TestActivity.py |    1 +
 test/TestGame.py     |    8 +++++++-
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/test/TestActivity.py b/test/TestActivity.py
index 1eb8744..cb67c3c 100644
--- a/test/TestActivity.py
+++ b/test/TestActivity.py
@@ -35,6 +35,7 @@ class TestActivity(sugar3.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 3ab9026..3141cec 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,10 +45,15 @@ 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
+                self.x += self.vx * self.direction
                 if self.x > screen.get_width() + 100:
                     self.x = -100
 
-- 
1.7.7.6



More information about the Sugar-devel mailing list