Maze

../_images/maze_game.png
class quest.examples.maze.MazeGame[source]

Get all the stars as fast as you can! My record is 45 seconds.

MazeGame is an example of how you can make a fairly complex game without making too many changes. Because MazeGame is a subclass of QuestGame, we just need to change the parts we want to work differently. We need to set some of the MazeGame properties and override a few of the class methods.

To run this example:

$ python -m quest.examples.maze

After you play it, check out the sorce code by clicking on “source” in the blue bar just above.

tile_size=32

Each square tile in the map is 32 pixels across.

grid_columns=33

The map will have 33 columns of tiles.

grid_rows=33

The map will have 33 rows of tiles.

player_sprite_image="images/boy_simple.png"

The sprite’s image file.

player_scaling=0.5

The image is too big, so we scale it down. (We could also just resize the image itself.)

player_initial_x=1.5 * tile_size

By starting the player at 1.5 times tile_size, the player will initially be positioned at the center of tile (1, 1). The outer edge of the map is walls.

player_initial_y=1.5 * tile_size

Again, centering the player at (1, 1)

score=0

Keeps track of how much loot has been collected.

max_score=25

Total amount of loot to be distributed through the maze.

game_over=False

Keeps track of whether the game has ended.

setup_maps()[source]

Creates a MazeMap (see below) and adds it to game’s list of maps.

setup_walls()[source]

Assigns self.wall_list to be all the sprites in the map’s “walls” layer.

setup_npcs()[source]

Assigns self.npc_list to be all the sprites in the map’s “loot” layer.

on_loot_collected(collector)[source]

A method to be called whenever loot is collected.

See the Loot NPC sprite below. It calls this method whenever there is a collision with the player.

message()[source]

Returns a string like “Time 12 (12/25)”

class quest.examples.maze.Loot(filename=None, scale=1, image_x=0, image_y=0, image_width=0, image_height=0, center_x=0, center_y=0, repeat_count_x=1, repeat_count_y=1)[source]

Loot is a NPC which shows up in the game as a star. Its only job is to get collected by the player.

on_collision(sprite, game)[source]

When the player collides with a Loot, it calls quest.maze.MazeMap.on_loot_collected() to tell the game to make needed updates. Then the Loot kills itself.

class quest.examples.maze.MazeMap(columns, rows, tile_size, num_loot)[source]

A Map which creates a wall layer using a Maze.

MazeMap is a subclass of Map which automatically generates a maze. It uses a Maze to figure out where to put walls, and adds wall sprites to a map layer in a corresponding pattern. :param columns: The number of columns of tiles in the map :param rows: The number of rows of tiles in the map :param tile_size: The size (in pixels) of each square tile :param num_loot: The number of loot sprites to add to the map

generate_maze(seed=None)[source]

Generates (or re-generates) the map. The Maze does most of the work.

Regenerates the maze, clears the wall map layer and the loot map layer (in case there was a previous maze), and then populates these layers with new wall sprites and loot sprites.

Parameters

seed – Random seed to pass to the maze (see Maze.generate())

get_wall_map_layer()[source]

Creates a new GridMapLayer to hold walls.

get_loot_map_layer()[source]

Creates a new GridMapLayer to hold loot.

possible_loot_locations()[source]

Returns a list of points where loot could be placed.