[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] [Pygame] Key Configuration



On Mon, May 11, 2009 at 05:31:06PM -0700, Fawkes wrote:
> I was wondering what would be the best way to do a key configuration
> for my game? One of the comments from our recent release (
> http://pygame.org/project/1106/ ) was that we ought to have the
> controls configurable by the player for instance if they have a non
> QWERTY keyboard. Right now all the controls are hard coded (e.g. the
> game looks to see if Z is pressed, do something). I was thinking of
> using a dictionary like the following.
> 
> controls{
> "confirm":K_z,
> "cancel":K_x
> "prev_ally":K_a,
> "next_ally":K_s,
> "prev_enemy":K_q,
> "next_enemy":"K_w}
> 
> The values within the dictionary would be changeable by the player
> within the game. Is this a good way to go about doing this?

Sometimes it's useful to allow more than one key for the same action.

Like claudio already said, for the purposes of the main game loop it's
more convenient to have a dictionary from key to action (it also allows
you to detect conflicts).

However for the purposes of the user interface, it may be more
convenient to have a dictionary like you have.  It's pretty simple to
translate between the two forms, so you could have both.

Marius Gedminas
-- 
Never, ever expect hackers to be able to read closed proprietary document
formats like Microsoft Word. Most hackers react to these about as well as you
would to having a pile of steaming pig manure dumped on your doorstep.
	-- ESR (http://www.tuxedo.org/~esr/faqs/smart-questions.html)

Attachment: signature.asc
Description: Digital signature