Main / Game Development
- Reading material
- Pygame demo
- User apps
- Share your game
- Joystick controls
- Advanced topics
Rogue Class Linux has games written in many languages and is open to new additions. Authors are welcome to write games in any way they see fit. Most of the games in RCL are compiled ahead of time in a full Slackware system. These games are not easily modified after they have been installed. This page will demonstrate how to develop simple games from within RCL, how to modify them, and how to share them over the Internet. Pygame was chosen because it is cross-platform and it is well documented.
Books are a good place to start. RCL includes a pubcast to subscribe to a shelf of development ebooks. This requires Internet access to download the books. Open the file manager. Open the pubcasts directory. Open dev.pubcast. Choose the menu option to Download content. Once you have downloaded the content, click Quit. You only need to download the content once. Then choose the menu option to View the downloaded content. The first book on the shelf is Making Games with Python and Pygame by Al Sweigart. Click the book cover. Click the PDF next to Read:. Click Open and start reading!
Disregard the Linux and Ubuntu instructions. Pygame is already installed in Rogue Class Linux. The IDLE development environment is not available. The file manager and default text editor will have to suffice.
Some of the example programs from the book do not run well in RCL. The first example can only be quit from the close button in the window's title bar. RCL does not have windows nor title bars, so this program cannot be closed. You can find copies of the book's examples adapted for RCL at the following link. http://rogueclass.org/files/pygame Note that some of the examples have an accompanying .sh script. This script takes care of details like the working directory and the environment variables. Run the .sh script instead of the .py script.
Chapter 3 of the Pygame book includes a memory game demo. You can find the source code download link on the bottom of page 52 of the PDF (page 34 of the book). http://invpy.com/memorypuzzle.py Go to the links browser. Use "File, Save as" to save a copy of memorypuzzle.py. Exit links and start the file manager. Find memorypuzzle.py in the home directory.
Click memorypuzzle.py and press Alt-R to run it. This will alert you that memorypuzzle.py is missing the required hashbang sequence, also known as she-bang. Below is an excerpt from chapter 2 of the Advanced Bash Scripting Guide, one of the other books in the dev pubcast.
The sha-bang #! at the head of a script tells your system that this file is a set of commands to be fed to the command interpreter indicated. The #! is actually a two-byte magic number, a special marker that designates a file type, or in this case an executable shell script (type man magic for more details on this fascinating topic). Immediately following the sha-bang is a path name. This is the path to the program that interprets the commands in the script, whether it be a shell, a programming language, or a utility. This command interpreter then executes the commands in the script, starting at the top (the line following the sha-bang line), and ignoring comments.
This is easy enough to add. Click memorypuzzle.py. Press o to open as text. Add a new line to the very beginning of the file:
Then save your changes and close the editor. Click memorypuzzle.py again and press Alt-R to run it. You should see a brief animation on the screen, then a grid of white tiles on a blue background. This demo can only be played with a mouse. Click on tiles to search for matching pairs. Press Escape to quit.
Due to the way the console works, it can be difficult to run and debug a game on the same console. It works best to run the game on the console and debug over the network. To do this, you will need to configure networking and SSH access. Then you will need to log from another system. Make sure you are able to SSH in as user rogue before proceeding.
Open the file manager and click memorypuzzle.py. This time press Alt-B to debug the script. You will see a screen that says "Launching debug server..." Now, at the SSH command prompt, run "rpdb2-client". Wait for it to connect. It will look like the following log.
rogue@darkstar:~$ rpdb2-client RPDB2 - The Remote Python Debugger, version RPDB_2_4_8, Copyright (C) 2005-2009 Nir Aides. Type "help", "copyright", "license", "credits" for more information. > *** Attaching to debuggee... > *** Debug Channel is NOT encrypted. > *** Successfully attached to '/home/rogue/memorypuzzle.py'. > *** Debuggee is waiting at break point for further commands.
in the debugger, you can use the help command for reference. Let's go through the exercise of making breakpoints and stepping through the main loop. Type "list 60" and press Enter.
Source lines for thread -1220901184 from file '/home/rogue/memorypuzzle.py': 60 revealedBoxes = generateRevealedBoxesData(False) 61 62 firstSelection = None # stores the (x, y) of the firs... 63 64 DISPLAYSURF.fill(BGCOLOR) 65 startGameAnimation(mainBoard) 66 67 while True: # main game loop 68 mouseClicked = False 69 70 DISPLAYSURF.fill(BGCOLOR) # drawing the window 71 drawBoard(mainBoard, revealedBoxes) 72 73 for event in pygame.event.get(): # event handling... 74 if event.type == QUIT or (event.type == KEYUP... 75 pygame.quit() 76 sys.exit() 77 elif event.type == MOUSEMOTION: 78 mousex, mousey = event.pos 79 elif event.type == MOUSEBUTTONUP: >
Type "bp 68" to set a breakpoint at the start of the main loop. Type "go" to start execution. At the console, you should see the memory puzzle animation, then the grid of white tiles. After the animation completes, you should see a notice in the debugger that the script has reached the breakpoint. You can use the next command to run the main loop a single line at a time, the list command to show where the script execution is at, and the eval command to examine variables.
Type "bl" to list the breakpoints. Type "bd 0" to delete the demo breakpoint. Type "go" to continue script execution. Type "detach" and wait for the debugger to detach from the script. Type "exit" to quit the debugger. If you exit without detaching, it will quit the debugged script.
RCL includes features to create packages that can be installed on other computers. Let's go through the process and create a package from the memory puzzle demo.
Put the code in place. Go to the file manager and create a mempuz directory to hold the package contents. Click memorypuzzle.py and copy it. Open the mempuz directory and paste a copy of memorypuzzle.py. Rename it to __main__.py
Put the icon in place. Go to links and browse to http://inventwithpython.com/pygame/chapter3_files/image002.png. Click File, Save as, and save to /home/rogue/mempuz/icon.png
Sign the directory. This helps to check whether the files have been tampered with after you upload them. Press Alt-S to begin.
The first time, it will prompt for an email address. This identifies you as the author of the package. Click OK.
Choose "app" and click OK. At the success screen, click Exit. Now you will see a lark-inf directory along with __main__.py and icon.png. This contains the cryptographic signature.
Make sure you are in the mempuz directory and no files are selected. Click File, Compress zip. This will create a user app named mempuz.lark. The first time you open mempuz.lark, it will install to the User Games menu, and automatically run. In the future, you can run it from the User Games menu.
Share your game
RCL has features to help share games with others. Let's go through the process to share the mempuz.lark app. This requires an Internet connection.
Click mempuz.lark. Press Alt-L to upload the file. Choose a file sharing service. Bayfiles is a good one. Click OK. Wait for it to upload. You will see 3 new files in the file manager. mempuz.lark.log is a log of the network transfer, and in some cases it will contain a delete link. mempuz.lark.plowshare is a link to download the file. mempuz.lark.announce is a template of an announcement to copy and paste.
One could announce the package in a forum post, pasting in the contents of the .announce file and attaching the .plowshare file for the benefit of RCL users.
On the other end, open the .plowshare file to download the package. Open the .lark package to install it. The first time it will show a cryptographic fingerprint to check against the author's announcement. Either click Trust to trust the author or click Quit. You will only be prompted to trust an author the first time you install an app signed by that author. After the first installation, the app will automatically run. Then you can run it from the User Games menu.
Many games lack joystick controls, but have keyboard controls. The easiest way to add joystick support is to use the RCL virtual keyboard. This requires a configured joystick.
The memory puzzle demo even lacks keyboard controls. You can use the links web browser to save a copy of http://rogueclass.org/files/memory2.py. This new version has minimal keyboard controls. The arrow keys move the selection. The Enter and Space keys flip the selected tile.
Take the following actions to use this new version. Delete mempuz.lark. Copy memory2.py to the mempuz directory. Delete the lark-inf directory. Delete __main__.py and rename memory2.py to __main__.py. Sign the directory and zip up the app. Open the new mempuz.lark and choose the Upgrade option.
Now that you have keyboard controls, it is easy to add joystick controls too. The virtual keyboard allows you to map combinations of joystick buttons to key sequences.
Create a new file mempuz-vjk.txt for the joystick configuration. Feel free to refer to the joystick controls in other apps. Edit mempuz-vjk.txt and add the following lines.
# see also base-vjk.txt button-a SDLK_SPACE button-start *-right SDLK_ESCAPE
Save this file. Delete the lark-inf directory, Sign the directory and zip up the app. Open the new mempuz.lark and choose the Upgrade option.
Now you can press A to flip a tile, and Start+R to quit the game. Thanks to the base settings, you can move the selection with the directional controls.
Suppose you wished to change the app description, or put it in the User Apps menu instead of the User Games menu. To do this, you will need to provide an additional configuration file.
Delete mempuz.lark. Go to the mempuz directory and create a new file named mempuz.desktop. Click mempuz.desktop. Press "o" to edit this file and enter the following lines.
[Desktop Entry] Name=Memory Puzzle Comment=Use your memory to find matching tiles Exec=lark-run mempuz Terminal=false Type=Application Categories=System; Icon=~/cache/userapp/mempuz/icon.png
Save and quit. Delete the lark-inf directory. Sign the directory and zip up the app. Open the new mempuz.lark and choose the Upgrade option. Since the Categories field is set to System instead of Game, the app will be listed in User Apps instead of User Games.
Suppose you wished to write a game in a language other than Python. In that case, name the file __main__ instead of __main__.py and specify the script interpreter in the hashbang sequence.