[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
RE: [pygame] multiple key presses
pygame.key.set_repeat(0)
I use that after I call pygame.init(), and it seems to do the trick for my
robotron remake.
However, I use it in conjunction with an event controller, which has two
entrypoints for KEYDOWN and KEYUP events. Once a key is pressed down, the
event sends a signal to another controller which alters the state of an
object corresponding to the event, and once the key is released, the same
thing happens, but reverts the object state back to its original value.
I can't explain for bollocks, so it's pseudocode time!
class KeyboardController:
def poll_events(self):
if event.type == KEYDOWN:
if event.key == K_UP:
FooGameObject.walk_around(True)
if event.type == KEYUP:
if event.key == K_UP:
FooGameObject.walk_around(False)
...
class FooGameObject(Sprite):
def __init__(self):
self.am_i_walking = False
def walk_around(self, state)
self.am_i_walking = state
def update(self, position)
if self.am_i_walking:
self.update_position(x, y)
(Assuming FooGameObject is an actual sprite, has a surface and so on, and
there's some sort of game clock looping and calling the update method on
FooGameObject and the poll_events method in KeyboardController on each
loop).
Man, I need to learn how to pseudocode (I wonder if there's an O'Reilly book
for it?)
~Chris
-----Original Message-----
From: owner-pygame-users@xxxxxxxx [mailto:owner-pygame-users@xxxxxxxx]On
Behalf Of Ian Mallett
Sent: Monday, July 02, 2007 15:00
To: pygame-users@xxxxxxxx
Subject: [pygame] multiple key presses
Hi again,
I'm having problems with multiple key presses (i.e. more than 2). I need at
least 6. Is there a way to do that?
Thanks
Geo
CONFIDENTIAL NOTICE: This email including any attachments, contains
confidential information belonging to the sender. It may also be
privileged or otherwise protected by work product immunity or other
legal rules. This information is intended only for the use of the
individual or entity named above. If you are not the intended
recipient, you are hereby notified that any disclosure, copying,
distribution or the taking of any action in reliance on the contents
of this emailed information is strictly prohibited. If you have
received this email in error, please immediately notify us by
reply email of the error and then delete this email immediately.