[OLPC-Games] Pygame game templates and cookbook

Mike C. Fletcher mcfletch at vrplumber.com
Fri Dec 21 15:23:15 EST 2007


Clare Richardson wrote:
> Good catch!  That demo program was written back in August and was used this fall semester as a teaching tool, so unfortunately we're pretty much done using it.  However, we definitely need that eye on our code for the upcoming semester!  Most of the code isn't OLPC laptop-ready, since we're trying to keep the code as simple as possible for our novices.
>  
> I hadn't seen the Pygame best practices.  Could we standardize this and put it up somewhere on the wiki?  I know it'd be a great resource for those starting out.
>   
I've put something together that should work reasonably well with most
games.  It is not quite as efficient as waiting all the time, but
provides visual feedback when the activity is paused and works in much
the same way as the Pippy functionality that provides similar feedback.

You can try it out with this .xo:

    http://dev.laptop.org/~mcfletch/testactivities/pausetest-1.xo

The code looks like this to use it:

    from olpcgames import pausescreen
    ...

            events = pausescreen.get_events(sleep_timeout=5)

then you process events as normally.  The code will iterate at full
frame-rate (which you can limit as you normally would with Clock.tick())
until sleep_timeout seconds pass without any events (of any type).  At
that point it will take a screenshot of your activity, and dim it,
adding a faint overlay of a sleeping cartoon face.  You can override the
overlay by passing a different function to produce the "sleeping" view. 
The sleeping face was chosen primarily because it doesn't require
localization.

When the underlying system has a way for us to signal "we're fine with
you going to sleep", we'll add that functionality to pausescreen. 
pausescreen should show up with the next release of OLPCGames.

Note:

    pause screen does *not* help with the problem of shared
    simulation-based games where network events are going to be coming
    in all the time.  When to pause your simulation is a decision you'll
    have to make based on when it makes sense and simple
    "screensaver-type" screen-pausing won't likely help you.

Take care,
Mike

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com



More information about the Games mailing list