Level managers

Rapid Pygame provides a level manager that keeps tract of level and is capable of level parsing

class rapidpg.levelmgr.collision.Level(config, data, tiles, backgrounds=None, player=None, animations=())

Responsible for handling player movement and level related collision detection. The structure of a level can be found in Level format

Contains the interpreted level and methods that should be called every frame to update the level. Also handle player movement. Since the interpreted level is exposed, the built in movement method doesn’t have to be used. The movement methods can be overridden by a child class to achieve a different movement effect. Note that if the child class has a different constructor, the LevelManager will have to be sub classed as well.

Parameters:
  • player – The player object to manipulate
  • config – The config dict of the level
  • data – The uninterpreted, but parsed level
  • tiles – A dict of tile sets, mapping a name to a surface
  • animations ([Animation]) – A list of animations that is shown in the background
  • backgrounds – A dict of backgrounds, mapping a name to a surface
  • animation ([[Surface]]) –
_gravity()

This method is called every update cycle to simulate gravity. Override this method to produce different behavior

_jump_action()

Called by update() when _is_jumping() returns true

_jump_condition(movement)

This method is called to decide when a jump is possible

Param:movement: The movement dict forwarded from update()
Return type:bool
_left_action()

Called by update() when left is held

_right_action()

Called by update() when right is held

static find_max(rect_list)

Find the rect with the largest y in the rect_list

static find_min(rect_list)

Find the rect with the lowest y in the rect_list

get_dimensions()

Get the width and height of the level

Returns:(width, height)
interpret()

Interpret the level, breaking it down into a list of rect that should collide with the player. Whether a tile collides with the player or not is specified in the level file. See Level format for more details

Returns:A list of rects
Return type:[Rect]
update(movement)

This method should be called every frame to update the location of the player and the environment. Player‘s start_jump() and jumping is used to start the jump and check if a jump is in progress, respectively.

Parameters:movement – Dict with keys up, down, left, right mapping to booleans
draw_list

A list of tuples, that are (surface, rect). Drawing the whole list with display_surf.blit(*level.draw_list) will draw the background, level, and player

exit

Exit of the level. (x, y) None if unspecified in the level

interpreted

A list of rects that should collide with the player, see interpret()

spawn

Spawn point of the player (x, y)

class rapidpg.levelmgr.collision.LevelManager(origin, player=None)

Load and manage levels.

Takes a path to the level file and the player object to manipulate

Parameters:
  • originstring origin of loading
  • player – An instance of a class that has a rect property
_get_current_level()
Return type:Level
load_level(path)

Load a level relative to the origin

Parameters:path – Path to the level in list format
next_level()

Advance current_level

previous_level()

Set current_level to the previous level

current_level

Current level object, set by using next_level() and previous_level()

Previous topic

Introduction

Next topic

Image loader

This Page