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

Re: [pygame] my rpg game (so far)



Michael Fiano wrote:

It works as expected if the first key is left or right, and the 2nd key
held is up or down. It does not work with up or down as the first key
pressed (it just keeps moving rather than stopping this time).

It sounds like what you want is that if more than one
key is down at once, you move in the direction of the
*most recently* pressed key. Is that right?

To get that, you'll have to process key events, and
to be able to revert to a previous direction, you'll
have to keep a list of currently outstanding movement
requests in order of occurrence.

When you get a key-down event, add a token for the
corresponding direction to the end of the list. When
you get a key-up event, remove it from the list
wherever it is. Each tick, look at the last item in
the list to tell which direction to move in.

--
Greg