Changeset 106:bf7d511d3650


Ignore:
Timestamp:
Apr 4, 2011, 7:14:48 PM (9 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Dvorak support

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/__init__.py

    r105 r106  
    11options = {
    22    'debug_rects': False,
     3    'dvorak': False,
    34    'sound': True,
    45}
  • skaapsteker/__main__.py

    r105 r106  
    1919    parser.add_option("--no-sound", action="store_false", default=True,
    2020            dest="sound", help="disable sound")
     21    parser.add_option("--dvorak", action="store_true", default=False,
     22            dest="dvorak", help="Dvorak keyboard layout")
    2123    if DEBUG:
    2224        parser.add_option("--level", type="str", default=None,
     
    2527            dest="rects", help="Disable debugging rects")
    2628    opts, _ = parser.parse_args(args or [])
     29    options['dvorak'] = opts.dvorak
    2730    options['sound'] = opts.sound
    2831    if DEBUG:
  • skaapsteker/levelscene.py

    r104 r106  
    11"""Scene wrapping a level object."""
    22
     3from pygame.locals import (KEYDOWN, K_DOWN, K_ESCAPE, K_LEFT, K_RIGHT,
     4                           K_SEMICOLON, K_UP, K_q, K_x, K_z)
     5
     6from . import options
    37import engine
    48import level
     
    610import sprites.player
    711import pygame
    8 from pygame.locals import KEYDOWN, K_UP, K_DOWN, K_LEFT, K_RIGHT, K_x, K_z, \
    9                           K_q, K_ESCAPE
    1012
    1113class LevelScene(engine.Scene):
    12 
    13     KEY_TO_PLAYER_ACTION = {
    14         K_LEFT: 'action_left',
    15         K_RIGHT: 'action_right',
    16         K_UP: 'action_up',
    17         K_DOWN: 'action_down',
    18         K_x: 'action_fire1',
    19         K_z: 'action_fire2',
    20     }
    2114
    2215    def __init__(self, leveldef, player=None):
     
    4134
    4235    def _build_action_map(self):
     36        KEY_TO_PLAYER_ACTION = {
     37            K_LEFT: 'action_left',
     38            K_RIGHT: 'action_right',
     39            K_UP: 'action_up',
     40            K_DOWN: 'action_down',
     41        }
     42        QUIT_KEYS = [K_ESCAPE]
     43
     44        if options['dvorak']:
     45            KEY_TO_PLAYER_ACTION[K_SEMICOLON] = 'action_fire1'
     46            KEY_TO_PLAYER_ACTION[K_q] = 'action_fire2'
     47        else:
     48            KEY_TO_PLAYER_ACTION[K_x] = 'action_fire1'
     49            KEY_TO_PLAYER_ACTION[K_z] = 'action_fire2'
     50            QUIT_KEYS.append(K_q)
     51
    4352        self._key_map = {}
    44         for key, action in self.KEY_TO_PLAYER_ACTION.items():
     53        for key, action in KEY_TO_PLAYER_ACTION.items():
    4554            self._key_map[key] = getattr(self._player, action)
    46         for key in [K_q, K_ESCAPE]:
     55        for key in QUIT_KEYS:
    4756            self._key_map[key] = self._quit
    4857
Note: See TracChangeset for help on using the changeset viewer.