Game development HOWTO

From OLPC
Revision as of 16:01, 28 June 2007 by 18.85.46.120 (talk)
Jump to: navigation, search

This HOWTO is current as of June 2007. Rapid changes are occurring; expect things to change.

Note: The Pygame wrapper requires at least build 432 to work.

Crash Course on Pygame

The slides from Noah's lecture at the start of the game jam are online at http://dev.laptop.org/~coderanger/ (both PDF and PowerPoint form).

Development Environment

Start with Pygame. If you are running Mac OS X, check out the Mac setup instructions.

You don't need a laptop for simple Pygame development. When creating your Pygame game, use this boilerplate:

import pygame
pygame.init()

def main():
    # Start Pygame displays...
    # screen = pygame.display.set_mode((600,600))
    while True:
        # Pygame event loop.
        pass

if __name__=="__main__":
    main()

The 'main' method will be called by the activity wrapper later on, so it must be called 'main'.

Wrapping and Testing

If you want to test using laptop software, but you don't have a real one, you could set up an emulated environment.

To make your game run as an Activity, you will need the 'olpcgames' wrapper, otherwise known simply as "the wrapper". Eventually, the wrapper will be included as part of the standard laptop software distribution, but for now you must include it in your Activity.

git clone git://dev.laptop.org/projects/games-misc

This will download several games-related projects. There are a few game Activities checked in, as well as the wrapper.

First construct an activity development bundle as in Sugar Activity Tutorial.

The wrapper requires the following boilerplate as the main class of your activity as specified in activity.info. Generally this is called 'activity.py' and your Pygame app retains its original name:

import olpcgames

class ExampleActivity(olpcgames.PyGameActivity):
    """An example of using a Pygame game as a Sugar activity."""
    
    game_name = 'examplemodule:main'
    game_title = 'Example'
    game_size = (1200,825)

The game_name parameter has the format "module:method". The module will be imported and the method called to start your Pygame application. Method is optional and defaults to main. (FIXME: Use Gettext to localize the game_title parameter.)

The game_size is what sets the display mode in Pygame.

The last step: you need to copy or link the 'olpcgames' directory from the Git repository you checked out into the root of your Activity. (Eventually, 'olpcgames' will be part of the main laptop build, so you will no longer need to do this.)

Hardware

The Pygame page has some information on hardware.

Camera

The camera works sorta using the wrapper. Support will be improved in the future.

import olpcgames

Whenever you need a camera, just do:

img = olpcgames.camera.snap()

This blocks your game until the camera returns a picture, then returns it as a Pygame surface. (note: test how long it tends to take)

Mesh or Connection to Internet

You'll want to discover peers and communicate with them through Tubes. You should be using build >=451 for mesh related stuff. We're working on a Pygame wrapper for Tubes.

You can use IP networking just fine.

Troubleshooting

Ensure you are using build >=432.

Check your log files. Alt+0 on the XO will bring up the developer console. Look at the Log Viewer and select your activity's logfile, and look at the output/traceback.

lincolnquirk is the current maintainer of the wrapper, and resides in the #olpc-content IRC channel (Freenode, like other OLPC channels). Contact him if you get stuck, and bring your logfiles.