Map¶
-
class
quest.map.Map[source]¶ Implements a map for a level or stage in the game.
Each QuestGame may have multiple Maps. Each Map represents a game map with multiple layers, allowing the map to describe walls, loot, and multiple layers of background imagery.
-
background_color¶ a 3-tuple of integers for red, green, blue. Each from 0-255. The
colormodule also predefines many colors.
-
tile_scaling¶ Factor by which to scale all map tiles. Default is 1.
-
background_color= (0, 0, 0)
-
tile_scaling= 1
-
-
class
quest.map.TiledMap(filename, sprite_classes=None)[source]¶ A subclass of Map which loads its layers from a TMX file. Each layer has a collection of tiles. When TiledMap is initialized, a sprite is created for each of these tiles. The sprite’s image and position are read from the tile layer data. The sprite’s class (which can determine its behavior) can be set using the sprite_classes argument.
Use TiledMap when you want to design your map using [Tiled](https://www.mapeditor.org/). This app saves maps as TMX files.
- Parameters
filename (str) – Path to the .tmx tilemap file
sprite_classes – {layer_name: SpriteClass} dict specifying the sprite class that should be used for each layer.
-
class
quest.map.MapLayer(name, sprite_list=None)[source]¶ Each Map is made up of one or more MapLayers.
- Parameters
name (str) – The layer name.
sprite_list – An optional
arcade.SpriteList.
-
class
quest.map.GridMapLayer(name, columns, rows, pixel_width, pixel_height, sprite_filename=None, sprite_class=None)[source]¶ A MapLayer which is aware of grid coordinates. GridMapLayers are useful in situations when you want to place sprites programmatically. Several methods are provided to support calculations about sprite positions with respect to the grid. This cam be simpler than working in pixel positions. For example, the maze example program generates a maze and then uses a GridMapLayer to place the walls of the maze.
- Parameters
name (str) – Layer name.
columns (int) – Number of columns in the grid.
rows (int) – Number of rows in the grid.
pixel_width (int) – Width of the grid in pixels.
pixel_height (int) – Height of the grid in pixels.
sprite_filename (str) – Path to sprite image file. Only needed if you will be creating sprites on this grid layer.
sprite_class – Class of sprites to create on this layer.
-
sprite_class¶ alias of
quest.sprite.QuestSprite
-
add_sprite(grid_x, grid_y, sprite=None)[source]¶ Adds a sprite at a given grid position.
- Parameters
grid_x (int) – The x-coordinate of the grid position
grid_y (int) – The y-coordinate of the grid position
sprite (QuestSprite) – (Optional) sprite to add to this layer and place at this grid position. If no sprite is given, a new sprite will be created.
-
create_sprite()[source]¶ Creates a sprite with image self.sprite_filename and class self.sprite_class.
-
get_pixel_position(grid_position, center=True)[source]¶ Converts pixel coordinates to grid coordinates.
- Parameters
grid_position (int, int) – x and y grid coordinates
center (bool) – By default, returns the pixel position of the center
the grid tile. When False, returns the pixel position of the lower (of) –
corner of the grid tile. (left) –
- Returns
(float, float) pixel position.