annotate src/parpg/bGrease/impl/controls.py @ 108:2f928c913c78

Fixed item_type not being set when creating items.
author KarstenBock@gmx.net
date Fri, 23 Sep 2011 13:30:41 +0200
parents 96af64cf3b81
children
rev   line source
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
1 #############################################################################
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
2 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
3 # Copyright (c) 2010 by Casey Duncan
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
4 # All Rights Reserved.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
5 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
6 # This software is subject to the provisions of the MIT License
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
7 # A copy of the license should accompany this distribution.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
11 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
12 #############################################################################
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
13 """Control systems for binding controls to game logic"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
14
66
96af64cf3b81 Renamed grease to bGrease (Basic Grease) to get rid of conflicts with an already installed grease.
KarstenBock@gmx.net
parents: 27
diff changeset
15 import bGrease
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
16 from pyglet.window import key
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
17
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
18 class KeyControls(grease.System):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
19 """System that maps subclass-defined action methods to keys.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
20
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
21 Keys may be mapped in the subclass definition using decorators
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
22 defined here as class methods or at runtime using the ``bind_key_*``
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
23 instance methods.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
24
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
25 See :ref:`an example implementation in the tutorial <tut-controls-example>`.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
26 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
27 MODIFIER_MASK = ~(key.MOD_NUMLOCK | key.MOD_SCROLLLOCK | key.MOD_CAPSLOCK)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
28 """The MODIFIER_MASK allows you to filter out modifier keys that should be
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
29 ignored by the application. By default, capslock, numlock, and scrolllock
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
30 are ignored.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
31 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
32
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
33 world = None
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
34 """:class:`grease.World` object this system is bound to"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
35
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
36 def __init__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
37 self._key_press_map = {}
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
38 self._key_release_map = {}
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
39 self._key_hold_map = {}
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
40 for name in self.__class__.__dict__:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
41 member = getattr(self, name)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
42 if hasattr(member, '_grease_hold_key_binding'):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
43 for binding in member._grease_hold_key_binding:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
44 self.bind_key_hold(member, *binding)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
45 if hasattr(member, '_grease_press_key_binding'):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
46 for binding in member._grease_press_key_binding:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
47 self.bind_key_press(member, *binding)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
48 if hasattr(member, '_grease_release_key_binding'):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
49 for binding in member._grease_release_key_binding:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
50 self.bind_key_release(member, *binding)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
51 self.held_keys = set()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
52
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
53 ## decorator methods for binding methods to key input events ##
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
54
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
55 @classmethod
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
56 def key_hold(cls, symbol, modifiers=0):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
57 """Decorator to bind a method to be executed where a key is held down"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
58 def bind(f):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
59 if not hasattr(f, '_grease_hold_key_binding'):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
60 f._grease_hold_key_binding = []
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
61 f._grease_hold_key_binding.append((symbol, modifiers & cls.MODIFIER_MASK))
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
62 return f
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
63 return bind
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
64
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
65 @classmethod
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
66 def key_press(cls, symbol, modifiers=0):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
67 """Decorator to bind a method to be executed where a key is initially depressed"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
68 def bind(f):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
69 if not hasattr(f, '_grease_press_key_binding'):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
70 f._grease_press_key_binding = []
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
71 f._grease_press_key_binding.append((symbol, modifiers & cls.MODIFIER_MASK))
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
72 return f
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
73 return bind
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
74
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
75 @classmethod
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
76 def key_release(cls, symbol, modifiers=0):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
77 """Decorator to bind a method to be executed where a key is released"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
78 def bind(f):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
79 if not hasattr(f, '_grease_release_key_binding'):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
80 f._grease_release_key_binding = []
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
81 f._grease_release_key_binding.append((symbol, modifiers & cls.MODIFIER_MASK))
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
82 return f
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
83 return bind
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
84
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
85 ## runtime binding methods ##
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
86
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
87 def bind_key_hold(self, method, key, modifiers=0):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
88 """Bind a method to a key at runtime to be invoked when the key is
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
89 held down, this replaces any existing key hold binding for this key.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
90 To unbind the key entirely, pass ``None`` for method.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
91 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
92 if method is not None:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
93 self._key_hold_map[key, modifiers & self.MODIFIER_MASK] = method
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
94 else:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
95 try:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
96 del self._key_hold_map[key, modifiers & self.MODIFIER_MASK]
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
97 except KeyError:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
98 pass
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
99
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
100 def bind_key_press(self, method, key, modifiers=0):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
101 """Bind a method to a key at runtime to be invoked when the key is initially
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
102 pressed, this replaces any existing key hold binding for this key. To unbind
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
103 the key entirely, pass ``None`` for method.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
104 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
105 if method is not None:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
106 self._key_press_map[key, modifiers & self.MODIFIER_MASK] = method
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
107 else:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
108 try:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
109 del self._key_press_map[key, modifiers & self.MODIFIER_MASK]
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
110 except KeyError:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
111 pass
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
112
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
113 def bind_key_release(self, method, key, modifiers=0):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
114 """Bind a method to a key at runtime to be invoked when the key is releaseed,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
115 this replaces any existing key hold binding for this key. To unbind
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
116 the key entirely, pass ``None`` for method.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
117 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
118 if method is not None:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
119 self._key_release_map[key, modifiers & self.MODIFIER_MASK] = method
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
120 else:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
121 try:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
122 del self._key_release_map[key, modifiers & self.MODIFIER_MASK]
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
123 except KeyError:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
124 pass
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
125
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
126 def step(self, dt):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
127 """invoke held key functions"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
128 already_run = set()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
129 for key in self.held_keys:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
130 func = self._key_hold_map.get(key)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
131 if func is not None and func not in already_run:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
132 already_run.add(func)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
133 func(dt)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
134
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
135 def on_key_press(self, key, modifiers):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
136 """Handle pyglet key press. Invoke key press methods and
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
137 activate key hold functions
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
138 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
139 key_mod = (key, modifiers & self.MODIFIER_MASK)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
140 if key_mod in self._key_press_map:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
141 self._key_press_map[key_mod]()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
142 self.held_keys.add(key_mod)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
143
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
144 def on_key_release(self, key, modifiers):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
145 """Handle pyglet key release. Invoke key release methods and
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
146 deactivate key hold functions
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
147 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
148 key_mod = (key, modifiers & self.MODIFIER_MASK)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
149 if key_mod in self._key_release_map:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
150 self._key_release_map[key_mod]()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
151 self.held_keys.discard(key_mod)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
152
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
153
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
154 if __name__ == '__main__':
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
155 import pyglet
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
156
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
157 class TestKeyControls(KeyControls):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
158
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
159 MODIFIER_MASK = ~(key.MOD_NUMLOCK | key.MOD_SCROLLLOCK | key.MOD_CTRL)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
160
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
161 remapped = False
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
162
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
163 @KeyControls.key_hold(key.UP)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
164 @KeyControls.key_hold(key.W)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
165 def up(self, dt):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
166 print 'UP!'
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
167
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
168 @KeyControls.key_hold(key.LEFT)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
169 @KeyControls.key_hold(key.A)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
170 def left(self, dt):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
171 print 'LEFT!'
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
172
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
173 @KeyControls.key_hold(key.RIGHT)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
174 @KeyControls.key_hold(key.D)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
175 def right(self, dt):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
176 print 'RIGHT!'
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
177
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
178 @KeyControls.key_hold(key.DOWN)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
179 @KeyControls.key_hold(key.S)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
180 def down(self, dt):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
181 print 'DOWN!'
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
182
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
183 @KeyControls.key_press(key.SPACE)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
184 def fire(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
185 print 'FIRE!'
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
186
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
187 @KeyControls.key_press(key.R)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
188 def remap_keys(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
189 if not self.remapped:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
190 self.bind_key_hold(None, key.W)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
191 self.bind_key_hold(None, key.A)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
192 self.bind_key_hold(None, key.S)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
193 self.bind_key_hold(None, key.D)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
194 self.bind_key_hold(self.up, key.I)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
195 self.bind_key_hold(self.left, key.J)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
196 self.bind_key_hold(self.right, key.L)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
197 self.bind_key_hold(self.down, key.K)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
198 else:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
199 self.bind_key_hold(None, key.I)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
200 self.bind_key_hold(None, key.J)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
201 self.bind_key_hold(None, key.K)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
202 self.bind_key_hold(None, key.L)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
203 self.bind_key_hold(self.up, key.W)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
204 self.bind_key_hold(self.left, key.A)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
205 self.bind_key_hold(self.right, key.D)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
206 self.bind_key_hold(self.down, key.S)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
207 self.remapped = not self.remapped
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
208
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
209
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
210 window = pyglet.window.Window()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
211 window.clear()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
212 controls = TestKeyControls()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
213 window.push_handlers(controls)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
214 pyglet.clock.schedule_interval(controls.step, 0.5)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
215 pyglet.app.run()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
216