Skip to main content

Module level

Module level 

Source
Expand description

Build levels from text maps.

Drawing a map as text is the quickest way to make a level:

let level = ctx.physics.build_level(
    "
    #########
    #P...#..C#
    #....#...#
    #..C.....#
    #########
    ",
    2.0, // every character is a 2 x 2 meter tile
);
let start = level.point('P').unwrap();
for coin in level.points('C') {
    // place a coin at `coin`
}
  • # becomes a fixed wall tagged "wall" (3 meters high). Neighbouring walls in a row are merged into one body.
  • . and spaces are empty floor.
  • Every other character is remembered as a point you can look up with Level::point and Level::points.

The first line of the map is north (highest y), columns go east (x). Leading and trailing blank lines and the common indentation are ignored, so the map can be written inline.

Structsยง

Level
The result of World::build_level.