Game development HOWTO: Difference between revisions
(+Category:Developers (is this still a useful category?)) |
No edit summary |
||
Line 25: | Line 25: | ||
The 'main' method will be called by the activity wrapper later on, so it must be called 'main'. |
The 'main' method will be called by the activity wrapper later on, so it must be called 'main'. |
||
If you want to test |
If you want to test using laptop software, but you don't have a real one, you could set up an [[Emulating the XO|emulated environment]]. You need at least build 432. |
||
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. |
|||
To make your game run as an Activity, check out the existing Pygame activities from Coderanger's Subversion repository: |
|||
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. You need to copy or link the 'olpcgames' directory into the root of your Activity. |
|||
The steps you need to follow are: |
|||
* cp -r |
* cp -r Example.activity MyActivity.activity |
||
* Put your Pygame program into the directory and remove |
* Put your Pygame program into the directory and remove example.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 |
* 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 Example and change them to your game name. |
||
* (Optional) Create an icon .svg and put it in the activity/ directory, and update activity.info to match. |
|||
* Get your game onto your laptop or emulated environment, in the /home/olpc/Activities folder (see below) |
* 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 |
* 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.) |
* Run your activity by clicking its icon at the bottom of the Frame. (Mouse to a corner of the screen to see the Frame.) |
||
Line 57: | Line 57: | ||
===Camera=== |
===Camera=== |
||
The camera works |
The camera works sorta using the wrapper. Support will be improved in the future. |
||
import olpcgames |
import olpcgames |
||
Line 69: | Line 69: | ||
===Mesh or Connection to Internet=== |
===Mesh or Connection to Internet=== |
||
You'll want to discover peers and communicate with them through Tubes. |
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. |
You can use IP networking just fine. |
||
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. |
|||
Revision as of 20:24, 27 June 2007
This HOWTO is current as of June 2007. Rapid changes are occurring; expect things to change.
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'.
If you want to test using laptop software, but you don't have a real one, you could set up an emulated environment. You need at least build 432.
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. You need to copy or link the 'olpcgames' directory into the root of your Activity.
- cp -r Example.activity MyActivity.activity
- Put your Pygame program into the directory and remove example.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 Example and change them to your game name.
- (Optional) Create an icon .svg and put it in the activity/ directory, and update activity.info to match.
- 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
- 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 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.