First Pyggy version (0.5)
Improvements in this version:- It's not quite so easy to get your yarns tangled, although still possible if you're not careful.
- If you hold one arrow key and press and release another, you now continue moving in the original direction instead of stopping.
- You can now squeeze in between a ball and a wall and nudge the ball away, so it's no longer necessary for me to disallow pushing things up against walls. On the downside, you now have to be a bit more accurate lining up with a ball in order to push it. To make this easier, I've added shadows under the player and balls.
- There are two more levels, and a new kind of object. I won't spoil your fun by telling you what it is. :-)
(log in to comment)
Comments
That won't work in this case, because I need to keep track of the order in which the arrow keys were pressed, so that I can resume moving in the most recently requested direction when a key is released.
Another subtletly is that I don't stop moving the moment a key is released, but only after the end of the next frame. That's so you can quickly tap and release a key and be assured of moving at least one step. Otherwise, the key tap could be lost altogether if it occurs within one frame time.
For these reasons, I need to take notice of the event stream rather than just looking at the current state of the keyboard.
I just took a look at your code. You don't have to be treating everything in the game as events. It's okay to deal with input sometimes by checking it's state instead. For continuous actions such as moving (in most games), that's the method that results in simpler code.
Check the documentation for pygame.key.get_pressed and try it out in future projects. =)