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

Re: [pygame] Character Movement



Charles Christie wrote:
So, I've finally gotten to the point where I want to make playable characters controllable. (took me long enough :P )

With that, I'd like to say I am very grateful to you. A few more questions and I'll be off your back... for this project, at least. ;)

Now then, in my event cue I have it check for key presses. When the tab button is pressed, the game changes so that the textsprite class doesn't get any keypresses. The point of this was to make it so that the character could use buttons on the keyboard to move without negatively impacting their scores, and that they wouldn't move and type words at the same time. So, my dillema is this:

I send the event.unicode to the move function, which makes the character move. However, I don't think I can use event.unicode to send keyup events. So that means when the person presses the button to move, when they release the button they won't stop moving. That's a Very Bad Thing. If you want to see my (really badly written) code I can send it if you want it.
It's pretty simple, just add an extra parameter to move that's a boolean state of that keypress. No reason you have to try to cram all the info into one argument.
Alternatively, you could just send the event object (you can check if it's a keypress before you send it so you don't waste time sending mousemove events to your move function) and just get the event.type out of the event object in your move function.
Another way would be to abstract the event processing away from the move function (determining which key is mapped to which button, etc), and just have the move take in 2 args: an x and a y to move it. Then if you need to move up or left, just pass in negative values.
HTH,
-Luke