Maps

From Post-Apocalyptic RPG wiki

Jump to: navigation, search

Submitted code proposal.png This article features an submitted code proposal.

Submitted code proposals are currently under consideration for implementation.


Contents

Map Storage

Each map in the game is made up of two main component parts: the ground textures (which are on the GroundLayer) and the objects with which the PC can interact (which are on the ObjectLayer).

Object Storage

Objects must be stored so that lookup is fast, the ideal solution is a python dictionary with the id of the object (or its name as the engine sees it) as the dictionary key and the object itself as the value. {id : MapObject()}.

Map Representation

It will also be useful to be able to look up objects by what map they are on, given the id of the map. Map ids are stored inside the map.xml files, and, in the future, we should ensure that the filename matches the map id as seen by the engine. So we'll have another dictionary, with map id names as keys and lists of object ids or pointers to the objects in the object dictionary as values. {map id : [object ids] OR [pointers]}.

Map Population

To figure out what objects initially belong on a map, the map_objects.xml files must be parsed by some xml parser. We'll call this parser the Object Loader

The Object Loader

The Object Loader is responsible for parsing a .xml file with information about objects with which the PC can interact. As of now, we have NPCs, objects such a crates that could be opened and contain other objects, and 'Doors' which are transitions to other maps. A crate might contain objects like Knife. All of these objects must be associated with fife.Instance objects while they are on the active map during gameplay.

The Object Loader reads from the _objects.xml file, line by line, and makes a dictionary containing the xml information. For example:

  • {name=asdf, type=door, posx=0.0, posy=1.0}
  • {name=barrel, type=container, posx=1.0, posy=20.0}

Each dictionary is passed to an Object Factory, which calls whatever required constructors need to be called and returns an object.

The Object Loader finally adds the object returned by the factory to the global object storage dictionary, and to the map dictionary for the current map.

The Object Factory

As laid out by tZee, the Object Factory has a method create, where it calls constructors and passes information based on the 'type' key in the dictionaries passed by the Object Loader.

Retrieved from "http://wiki.parpg.net/Maps"
Personal tools