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

Re: [pygame] Function for keyboard movement



Hi Bob,

The smaller number of concepts used the better.

Try not to require defining functions or classesÂwhen explaining events.



Print the events out in the event loop. So people can see what events come in when they do things. TheÂevent example that comes with pygameÂis nice to showÂall the eventsÂon the screen.

Then you have to make the x, y axis concept clear. Draw the axis with labels on the screen.

Just use one rect and the screen.fill method to start, since this is the minimum you need to explain the concept. Make sure to print out the rect each time around the loop. They can see when adding 1 to the x of the rect that it moves over. They know what state the x is in for the rect.

Print at each stage, 'clearing buffer with screen.flip'.

Put a sleep in there at each point so they can see things slowly happening. When they press a key, they see an event happen, and know where it is in the code.

Sleep also helps giveÂthemÂsome idea of how it is a machine that takes time to do things. How there is a queue of events waiting from when you press a key, until when you ask for them. How there is a flow to the execution.


Hope that helps!



Happy hacking.



Am Dienstag, 6. Oktober 2015 schrieb Bob Irving :
Hi folks,

We're introducing Python for 9th grade this year and moving from Blitz Basic for game programming. Just wondering if anyone has come up with a way to hide the complexity for keyboard movement..... it's one of those things that makes sense to more advanced programmers but not to beginners. We've experimented with making a few functions to detect collisions, mouse clicks....

TIA,
Bob Irving
Porter-Gaud School
Charleston, SC