Engines

[ LiB ]

Engines

An engine is simply a tool, and this chapter focuses on tools and engines available that help you program games . These tools are all Python-based and open -source, and, for the most part, are geared towards the beginning programmer and so have easy-to-use interfaces.

The Cyclon Online Gaming Engine

The Cyclon Online Gaming Engine (COG for short) is an open-source computer game-authoring system. The system comes with a development application to facilitate game creation, a " fill-in-the-blanks " GUI that brings up windows in which you set up the game information, player information, rooms, directions, items, events, and even define action verbs that can be taken in by the text parser. The development application is shown in Figure 5.1.

Figure 5.1. The COG development application

graphic/05fig01.gif


COG currently supports a semi- Myst interface, with photo-realistic screens, text-based input, and mouse company-point movement. Games created with COG are meant to be run online via HTTP or through a Web browser interface. The engine can be found on Sourceforge at http://cogengine. sourceforge .net/.

Python Adventure Writing System

The Python Adventure Writing System (PAWS) is a text adventure system developed by Roger Plowman. As with many Python-based game tools, PAWS is aimed at the non-programmer and consists of a game engine, a world library, and a play module. PAWS is fairly well documented, and comes with a few sample games and two great explanatory texts , one aimed towards first-time game writers and another, aimed towards code-heads, that explains how the Python sources work. Even the source code itself is well documentedespecially the sample games, which read like tutorials themselves . You can find PAWS on the CD accompanying this book under the Python section (see Figure 5.2).

Figure 5.2. The PAWS engine at work

graphic/05fig02.gif


PAWS includes a few fun tricks to keep its games lively. For instance, it has a say() function that takes the place of print in Python; say() has the special ability to read commands for paragraph breaks, boldface, titles, and color . These tricks are especially helpful when designing a text-based game. say() also has a parse alias, Object, which is called P in the code for short. PAWS also includes a number of fun and unique classes, set up in the core game and in the universe library, for creating game objects and doing lots of useful things. These classes and what they are used for are outlined in Table 5.1.

Table 5.1. PAWS Classes

Class

Summary

ClassActivatableItem

Creates items a player can turn on and off

ClassActor

Creates people, animals, monsters, and other things players will be able to talk to or fight with. Based on ClassBasicThing .

ClassBaseObject

Base class for creating all "things" the player can interact with

ClassBasicThing

Defines basic physical laws. Base for specialized classes of "things"

ClassContainer

Creates containers that can hold things

ClassDirection

Used to create direction traveled by the player

ClassDoor

Creates one side of a door

ClassFundamental

The base root class of all the other classes. All other classes are based on this parent

ClassGameObject

Creates the game object

ClassGlobal

Creates a global object

ClassItem

Creates an object that can be taken and carried by the player

ClassLockableDoor

Creates a lockable door

ClassMonster

Defines anything with combat abilities . Based on ClassActor

ClassOpenableItem

Defines items that can open or close

ClassParserError

Stores error messages

ClassPlayer

Defines the player character object

ClassRoom

Defines room

ClassScenery

Creates props and atmosphere

ClassShelf

Creates a fixed shelf that items can be placed on

ClassUnderHider

Creates an item that drops contents when taken


PAWS makes it very easy to develop games quickly if you're accustomed to Python. For instance, the directions a player can traverse are set up through a Python dictionary. An example map might be something like the following:

 MyRoom_1.Map = {North:      "You can't go that way.",                    Northeast:  "You can't go that way.",                    East:       "You can't go that way.",                    Southeast:  "You can't go that way.",                    South:      "You can't go that way.",                    Southwest:  "You can't go that way.",                    West:       "You can't go that way.",                    Northwest:  "You can't go that way.",                    Up:         MyUpstairsRoom_1,                    Down:       MyDownstairsRoom_1,} 

PAWS knows its maps well enough to figure out how to link rooms together or print out a string if that's what you want to have happen when a player travels in a certain direction. Items and rooms in PAWS are defined by using the class and then overriding the appropriate defaults methods , like so:

 MyItem_1 = ClassItem("Mine") MyItem_1.Bulk = 1 MyItem_1.StartingLocation = MyUpstairsRoom_1 

In this example, I defined an item, MyItem . The argument given ( "Mine" ) is the noun descriptor PAWS will use to reference the item. The Bulk() and StartingLocation() methods (inherited from ClassItem ) set up where the item will originally be found, along with its weight/size in the player's inventory.

Other fun PAWS features include a parser that can be extended so that a programmer can add new verbs and adverbs, game daemons that can be spawned to run functions at every player turn, and " fuses " that will run a function after a delay of so many turns. There is even a debug mode that allows you, for testing purposes, to trace commands and set variables while playing.

To get the latest version of Paws, hit Roger's site, at http:// members .nuvox.net/~zt.wolf/PAWS.shtml.

PyPlace

PyPlace, by Peter Goode (and based on work by Pete Shinners), is a tool for generating isometric maps"Place" rendering in Python.

The power behind PyPlace is a render.py module. This render model takes in a map object, which is basically a three-dimensional array, and uses the map to render an isometric view map with a number of square tiles (which are provided in a .png format).

Unfortunately, the project has been in alpha for quite a while, and it appears as though development on the project has stopped . Still, for the guru, this could be a good starting place for an isometric game engine. Find the project homepage at: http://www.mrexcessive.net/pyplace.

And find it at Sourceforge project page at http://sourceforge.net/projects/pyplace/.

Python Universe Builder

The Python Universe Builder is a set of Python modules used to create text-based games or works of interactive fiction . PUB was originally built by Joe Strout and was subsequently revised by Terry Handcock for his AutoManga project. PUB is currently now under the wing of Joshua Macy, who has made efforts to update PUB for Python 2.0 and document the project. The Sourceforge page can be found at http://py-universe.sourceforge.net/index.html.

NOTE

The Basic Universe Simulator

PUB's younger brother, the Basic Universe Simulator, is a set of Python code that demonstrates interactive fiction and Python. It is meant to be a short example of what Python is capable of, or a building block for a more complex game (the BUS is really just a few scripts capable of parsing English sentence -like commands). BUS was also built by Joe Strout and can be found at his Website, http://www.strout.net/.

PUB has a handful of modules for importing, as shown in Table 5.2. The modules are object-oriented, and have several big base classes grouped around objects that players interact with and verbs that the PUB uses to translate player commands.

Table 5.2. PUB Modules

Module

Function

demo

Contains a simple demo game

gadgets

For building specific objects

pub

Contains globals

pubobjs

Contains standard objects

picklemod

For saving ( pickling ) entire modules

pubscore

Contains datatypes, functions, and constants

pubtcp

Used for network support

pubverbs

Contains standard verbs

tcpdemo

Used for MUD adaptation


PUB also has classes for schedulers , commands, the parser itself, and events, which can be used to create everything used in the engine.

After importing PUB, you can begin building MUD-like rooms and areas fairly quickly.

 # Create a room with module pubobjs and method Room MyPrisonRoom = pubobjs.Room("Dungeon Prison Cell") # Describe room with desc method room.desc = "You're in a small barred cell with walls of stone.\ To the north is a rusty Iron-barred door. \ A small bowl filled with water lies In one corner of the room." # Establish north exit exits   room_n= Exit("north,n,out,bars,door") # Describe exit room_n.desc = "The door appears to be unlocked." # Add object Into the room water = pubobjs.Liquid("water,liquid") # Describe object water.desc = "It appears to be ordinary water, and fairly clean." 

This example first creates a sample room called MyPrisonRoom using pubobjs.Room , and then describes the room and establishes exits with the desc() and Exit() method calls. Then an object, in this case a Liquid() object, is created within the room and described in a similar way. Notice how creating an object in a room and creating the room itself are nearly identical.

PUB's biggest strength is likely its sentence parser, which allows fairly complex input from players ("Get the dragon and put it in the shoe ").

The Sourceforge page provides a few sample games (including a sample game that has been turned into a MUD version) and a template script that handily shows, via comments, where objects must reside. The source code itself is also available and fairly well commented.

The Pyzzle Game Engine

Pyzzle is a free (under the GNU public license), pre-built game user -interface in the spirit of the Myst and Riven (it is included in this book's CD under the section on Python). Authored by Andrew Jones and written in Python and Pygame, the engine includes the following features:

  • A modular rendering interface capable of using OpenGL, SDL, or Direct3D.

  • Runs on several platforms (Windows, NT4, OSX, BeOS, FreeBSD, IRIX, and Linux).

  • Full API using Python scripting.

  • Support for different display sizes (640x480, 800x600, 1024x768, and so on).

  • Ambient sound, music, and sound effects (using WAV files).

  • Over-slide images (formats include BMP, GIF, PNG, JPG, PCX, and TGA), text using True Type fonts, and movie playback using MPEG files.

  • In-game objects that players can carry.

  • Zip navigation option.

  • Customizable color graphical cursors .

  • Slide-like Riven-style area transitions.

  • Basic menus .

See Figure 5.3 for a look at Pyzzle's packaged demo game in action. Pyzzle is composed of the handful of modules listed in Table 5.3.

Figure 5.3. The Pyzzle demo game showing the engine at work

graphic/05fig03.gif


Table 5.3. Pyzzle Modules

Module

Use

AmbientSound

Defining ambient sounds and music

Image

Defining over-slide images

Movie

Defining movies

Object

Defining objects

parameters

Controlling the global game parameters

paths

Defining the default paths

Pyzzle

The base engine

Slide

Defining slides. The basic graphics unit

Sound

Defining sound effects

Text

Defining over-slide text


The API isn't quite finished as far as documenting goes, but just opening up the demo game files (check demogame.py) and perusing them can be quite revealing (and, of course, the source code is freely available).

Once Pyzzle has been imported, you use parameter methods to set the game parameters like screen size and background color:

 #import Pyzzle import pyzzle from pyzzle import * # Set a few game parameters parameters.setScreenSize((800,600)) # window size in game parameters.setBackgroundColor((0,0,0)) # set background to black 

Then you use the paths module to set the paths to the WAV, MPEG, screen, and other files:

 #Tell Pyzzle about a few paths to use. paths.setSlidePath(os.path.join('data', 'slides')) paths.setSoundPath(os.path.join('data', 'sounds')) paths.setImagePath(os.path.join('data', 'images')) paths.setMoviePath(os.path.join('data', 'movies')) 

You will need at least one slide, which is basically a game screen. It can be easier to start off giving each slide a label:

 #define Slide containers MyStartingSlide   = Slide() MySecondSlide  = Slide() MyThirdSlide   = Slide() 

And then defining each slide:

 # Define slides MyStartingSlide.setNavType(standard) MyStartingSlide.setSlideFile('MyImageFile.jpg') MyStartingSlide.setNavigation([MySecondSlide, MyThirdSlide,]) MySecondSlide.setNavType(standard) MySecondSlide.setSlideFile('MyImageFile2.jpg') MySecondSlide.setNavigation([MyStartingSlide]) 

This would set and connect two different images as slides that could navigate to each other. Starting the game up requires two lines:

 # Set the starting slide pyzzle.setFirstSlide(MyStartingSlide) #start the game pyzzle.start() 

There is a lot more that Pyzzle can do. Each slide can include music, items, special effects, and special behavior defined for clicking and navigating. Text, objects, ambient sound, containers, and puzzle control logic can all be defined and used to make a great game. For the latest version of Pyzzle, check out its homepage on Sourceforge, at http://pyzzle.sourceforge.net/.

[ LiB ]


Game Programming with Pyton, Lua and Ruby
Game Programming with Pyton, Lua and Ruby
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net