Game development HOWTO

From OLPC
Revision as of 13:56, 9 June 2007 by Colin (talk | contribs)
Jump to: navigation, search

This HOWTO is current as-of the first OLPC Game Jam at Olin College on June 8, 2007. Please update it as you learn.

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'.

If you want to test on a laptop, you could set up an [[emulated environment][Emulating the XO]]. Or you could check out a laptop from the organizers at the game jam and use that.

To make your game run as an Activity, check out the existing Pygame activities from Coderanger's Subversion repository:

svn co https://coderanger.net/svn/projects/olpc/games olpcgames

The steps you need to follow are:

  • cp -r TicTacToe.activity MyActivity.activity
  • Put your Pygame program into the directory and remove tictactoe.py
  • Edit activity.py. game_name should be set to the name of your Pygame program (i.e., a python module to load and call main() on). Edit other files and fields relating specifically to Tic-Tac-Toe and change them to your game name.
  • Get your game onto your laptop or emulated environment, in the /home/olpc/Activities folder (see below)
  • Restart X on the laptop via ctrl+alt+erase
  • Journal starts up on boot; you may want to kill it with alt+C to return to the Sugar startup screen
  • Run your activity by clicking its icon at the bottom of the Frame. (Mouse to a corner of the screen to see the Frame.)

There are several possible ways to get the game onto the laptop.

If you're using an emulated environment, simply copy it to your shared folder if you have one. (You could even check out the olpcgames directory into the emulated environment's Activities folder, which is convenient.)

If you have a network, you can copy it via SCP.

If you have a USB stick, copy the Activity onto the usb stick on your PC and unmount it (if your USB stick's filesystem doesn't support symbolic links, you will need to copy the 'olpcgames' directory to each of the .activity subdirectories that you intend to run). Put it into the XO. Enter the Developer console using alt+0. Go to Terminal. Mount the drive: 'mkdir -p /media/sda1; mount /dev/sda1 /media/sda1' and then copy the activity and the 'olpcgames' directory (if not symlinked) to your Activities directory.

Remember, the first time you run an activity, X needs to be restarted before it will be findable through the GUI.

Hardware

The Pygame page has some information on hardware.

Camera

The camera only works through GTK, so you cannot simply modify your Pygame code. This is not a recipe -- more like some ideas of how you might get it working.

Get the source of the Camera activity through the [[Red Hat Activities download page] [1]] and unzip it (.xo files are just zip files)

You want the module 'glive.py'. This module implements live camera streaming inside GTK. Look at how the Camera activity uses it, and at the takePic method. That's how you get a picture out of the camera. You'll need to put in some hooks to analyze it somehow. Good luck.

Mesh or Connection to Internet

You'll want to discover peers and communicate with them through Tubes. More information about Tubes will be forthcoming, but note that it's very unstable on the laptops we have, so you should not really rely on it. (You can of course use IP networking, but the mesh API is unlikely to be available for this conference.)

For this weekend the most reliable internet connection has been to connect to the ap called 'OLIN_GUEST' with the WEP key on the blackboard. We tried to use a wired MAC that advertised an Access Point, but the connections from the XO were not stable.

You may find that the XO needs to be upgraded to q2c12.rom firmware and nand432.img nand. Some people were having trouble getting the WEP key to work with the 406 nand.