Redo keyboard navigation code to support WASD as well
authorNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 09:10:28 +0000 (11:10 +0200)
committerNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 09:10:28 +0000 (11:10 +0200)
erdslangetjie/__main__.py
erdslangetjie/constants.py

index 9a609c610d75dc7e5c96edeb41fe27d2d0c26af8..71ef53b405cc46e9c6f5a8780109e6eaeac8abda 100644 (file)
@@ -1,6 +1,4 @@
-import pygame
-
-from erdslangetjie.constants import TILE_SIZE
+from erdslangetjie.constants import TILE_SIZE, LEFT, RIGHT, UP, DOWN
 
 from kivy.app import App
 from kivy.uix.widget import Widget
@@ -164,15 +162,15 @@ class GameWindow(RelativeLayout):
         self.keyboard.unbind(on_key_down=self._on_key_down)
 
     def _on_key_down(self, keyboard, keycode, text, modifiers):
-        # FIXME - likely portablity issues
         direction = None
-        if keycode[0] == pygame.K_UP:
+        letter = keycode[1].lower()
+        if letter in UP:
             direction = (0, 1)
-        elif keycode[0] == pygame.K_DOWN:
+        elif letter in DOWN:
             direction = (0, -1)
-        elif keycode[0] == pygame.K_LEFT:
+        elif letter in LEFT:
             direction = (-1, 0)
-        elif keycode[0] == pygame.K_RIGHT:
+        elif letter in RIGHT:
             direction = (1, 0)
         if direction:
             self.do_move(direction)
index 06d25fb9298fcff07caa68c055affa7f83a4331e..c9f16e6b4c2a949efbc28fcd1274b48c8ee54f14 100644 (file)
@@ -19,3 +19,9 @@ if platform() != 'android':
 else:
     TILE_SIZE = 64
     Config.set('graphics', 'fullscreen', 'auto')
+
+# Change here to tweak keyboard controls
+LEFT = ('a', 'left')
+RIGHT = ('d', 'right')
+UP = ('w', 'up')
+DOWN = ('s', 'down')