Next: , Previous: , Up: Top   [Contents][Index]


3 Module map

This chapter describes the contents of the map module in detail.
The map module is imported from cursgame.map.
The map module is located at cursgame/map.py.

3.1 The Map class

The Map class holds the fields of the game and is responsible for printing the map on the screen. Also it carries out the action-loop. It inherits from dict, since it holds the map-data as a dictionary. You should rarely subclass it.

3.1.1 methods

Here are all methods of the Map class.

3.1.1.1 __init__/constructor

The Map takes at initialization on argument. This argument must be an iterable (usually an tuple) with exactly two arguments. These two items define the size of the Map, they must be of type int.

3.1.1.2 print

This method prints the map-data on the screen. This method can’t be called until the game is created and the map is registered on the game. The data is printed at Map.screen. See Map.screen. This method takes no arguments.

3.1.1.3 place

This function places an Obj on the Map. After that the Obj is displayed on the screen (if in sight) and can act in the game. This method takes from three to four arguments. The first is the Obj to place on the Map. The second and third are the x and y coordinates for the Obj (x first, even if curses has y first!). The optional fourth should be a bool, defaults to False and if it’s True the Obj is placed on the action-loop. For more on Objs, see Obj and Obj. For more on the action-loop, see Map.aloop.

3.1.1.4 distance

This method takes two arguments. Both are Objs. The method then returns the distance between the Objs.

3.1.1.5 remove

This method removes an object from a given position. It takes three aguments. The first is the Obj to remove. The second and third are the X and Y coordinates to remove from.

3.1.1.6 do_aloop

This method carries out the action-loop. You shouldn’t call it unless you’re overriding the main-loop (see Game.loop).

3.1.2 attributes

Here are the important attributes of the main class.

3.1.2.1 x/y

These two attributes represent the x and y size of the map.

3.1.2.2 screen

This attribute holds the screen the map should print on. It is None until the Map is registered on a Game.

3.1.2.3 lookon

This attribute holds the Obj the screen should be centered on. You can change it just by setting this variable to another value. Changes to this variable will take effect in the next frame.

3.1.2.4 aloop

This is a list holding all objects on the action-loop.

3.1.2.5 game

This holds a reference to the game this map is registered on.


Next: , Previous: , Up: Top   [Contents][Index]