mtx.Level

class Level(width, height, name=None, number=None, groundTexture=0, wallTexture=1)[source]

Bases: object

Class for managing a game level. It contains a field and a backup of the initial state of the field to allow a level reset. It keeps track on the number of the different game objects and gives access to specific objects.

Parameters:
  • width (int) – The width of the level.
  • height (int) – The height of the level.
  • name (str) – The name of the level.
  • groundTecture (mtx.TEXTURE.GROUND) – The texture for the ground of the level.
  • wallTecture (mtx.TEXTURE.GROUND) – The texture for a wall in the level.
Add(x, y, symbol)[source]

Creates a new game object for the given symbol and adds it to the level at position (x, y).

Parameters:
  • x (int) – X coordinate of the position of the game object.
  • y (int) – Y coordinate of the position of the game object.
  • symbol (str) – The symbol of the game object.
static Create(defDict, number=None)[source]

This method creates a new level on the basis of a level definition in the form of a directory. It defines all the information for the level such as the name, the textures and the structure. The level structure itself is defined by an ascii matrix where each ascii sign represents one or more game objects.

Available dictionary keys:

name:The name of the level (str). - optional
ground:The texture for the ground of the level (mtx.TEXTURE.GROUND). - optional
wall:The texture for a wall in the level (mtx.TEXTURE.WALL). - optional
plan:List of rows with object symbols representing the structure of the level (list). - required
Parameters:defDict (dict) – A dictionary with the level definition.
Returns:The level object for the given definition.
Return type:mtx.Level

Example

{'name':   'Level 1',
 'ground': mtx.TEXTURE.GROUND.EARTH,
 'wall':   mtx.TEXTURE.WALL.RED_BRICKS,
 'plan':  ['#####',
           '#1bt#',
           '#####']}
GetCell(x, y)[source]
Parameters:
  • x (int) – X coordinate of the cell position.
  • y (int) – Y coordinate of the cell position.
Returns:

The cell for the given coordinates.

Return type:

mtx.Cell

GetField()[source]
Returns:The field of the level.
Return type:mtx.Field
GetFieldSize()[source]
Returns:The levels field size.
Return type:tuple
GetGame()[source]
GetGroundTexture()[source]
Returns:The texture for the ground of the level.
Return type:mtx.TEXTURE.GROUND
GetName()[source]
Returns:The name of the level.
Return type:str
GetNumber()[source]
Returns:The number of the level.
Return type:int
GetObject(id)[source]
GetObjectCount(symbol)[source]
Parameters:symbol (str) – The symbol of the object.
Returns:Returns the number of objects in the entire level with the given symbol.
Return type:int
GetObjects(symbol)[source]
GetPlayer(number)[source]
Parameters:number (int) – The number of the player.
Returns:The player object or None, if no player with the given number exists.
Return type:mtx.BaseObject or None
GetPlayers()[source]
Returns:All players in a directory that maps a player number to a player object.
Return type:dict
GetWallTexture()[source]
Returns:The texture for a wall in the level.
Return type:mtx.TEXTURE.WALL
Reset()[source]

Resets the level to the initial state.

SetGame(game)[source]
SetNumber(number)[source]
Parameters:number (int) – The number of the level.