# HG changeset patch # User Stefano Rivera # Date 1301944488 -7200 # Node ID bf7d511d365000830ba299d8bc5dbf08d9426c2e # Parent c455b79252128a2f218955ff9111c30b66e0a829 Dvorak support diff -r c455b7925212 -r bf7d511d3650 skaapsteker/__init__.py --- a/skaapsteker/__init__.py Mon Apr 04 21:05:33 2011 +0200 +++ b/skaapsteker/__init__.py Mon Apr 04 21:14:48 2011 +0200 @@ -1,4 +1,5 @@ options = { 'debug_rects': False, + 'dvorak': False, 'sound': True, } diff -r c455b7925212 -r bf7d511d3650 skaapsteker/__main__.py --- a/skaapsteker/__main__.py Mon Apr 04 21:05:33 2011 +0200 +++ b/skaapsteker/__main__.py Mon Apr 04 21:14:48 2011 +0200 @@ -18,12 +18,15 @@ parser = optparse.OptionParser() parser.add_option("--no-sound", action="store_false", default=True, dest="sound", help="disable sound") + parser.add_option("--dvorak", action="store_true", default=False, + dest="dvorak", help="Dvorak keyboard layout") if DEBUG: parser.add_option("--level", type="str", default=None, dest="level", help="Initial level") parser.add_option("--no-rects", action="store_false", default=True, dest="rects", help="Disable debugging rects") opts, _ = parser.parse_args(args or []) + options['dvorak'] = opts.dvorak options['sound'] = opts.sound if DEBUG: options['debug_rects'] = opts.rects diff -r c455b7925212 -r bf7d511d3650 skaapsteker/levelscene.py --- a/skaapsteker/levelscene.py Mon Apr 04 21:05:33 2011 +0200 +++ b/skaapsteker/levelscene.py Mon Apr 04 21:14:48 2011 +0200 @@ -1,24 +1,17 @@ """Scene wrapping a level object.""" +from pygame.locals import (KEYDOWN, K_DOWN, K_ESCAPE, K_LEFT, K_RIGHT, + K_SEMICOLON, K_UP, K_q, K_x, K_z) + +from . import options import engine import level import physics import sprites.player import pygame -from pygame.locals import KEYDOWN, K_UP, K_DOWN, K_LEFT, K_RIGHT, K_x, K_z, \ - K_q, K_ESCAPE class LevelScene(engine.Scene): - KEY_TO_PLAYER_ACTION = { - K_LEFT: 'action_left', - K_RIGHT: 'action_right', - K_UP: 'action_up', - K_DOWN: 'action_down', - K_x: 'action_fire1', - K_z: 'action_fire2', - } - def __init__(self, leveldef, player=None): if not player: self._player = sprites.player.Player() @@ -40,10 +33,26 @@ self._build_action_map() def _build_action_map(self): + KEY_TO_PLAYER_ACTION = { + K_LEFT: 'action_left', + K_RIGHT: 'action_right', + K_UP: 'action_up', + K_DOWN: 'action_down', + } + QUIT_KEYS = [K_ESCAPE] + + if options['dvorak']: + KEY_TO_PLAYER_ACTION[K_SEMICOLON] = 'action_fire1' + KEY_TO_PLAYER_ACTION[K_q] = 'action_fire2' + else: + KEY_TO_PLAYER_ACTION[K_x] = 'action_fire1' + KEY_TO_PLAYER_ACTION[K_z] = 'action_fire2' + QUIT_KEYS.append(K_q) + self._key_map = {} - for key, action in self.KEY_TO_PLAYER_ACTION.items(): + for key, action in KEY_TO_PLAYER_ACTION.items(): self._key_map[key] = getattr(self._player, action) - for key in [K_q, K_ESCAPE]: + for key in QUIT_KEYS: self._key_map[key] = self._quit def _quit(self):