From 5ef62be743537175b38e5044dbbdcd17ccaf6b1e Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 18 Apr 2013 11:10:28 +0200 Subject: [PATCH] Redo keyboard navigation code to support WASD as well --- erdslangetjie/__main__.py | 14 ++++++-------- erdslangetjie/constants.py | 6 ++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/erdslangetjie/__main__.py b/erdslangetjie/__main__.py index 9a609c6..71ef53b 100644 --- a/erdslangetjie/__main__.py +++ b/erdslangetjie/__main__.py @@ -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) diff --git a/erdslangetjie/constants.py b/erdslangetjie/constants.py index 06d25fb..c9f16e6 100644 --- a/erdslangetjie/constants.py +++ b/erdslangetjie/constants.py @@ -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') -- 2.34.1