void load(Level level)

Loads and inits a new level

Source

void load(Level level)
{
    if (isRunning) return;

    // Set State
    enemyCount = 0;
    world = new World(level.size, this);

    // Character
    player = world.spawnActor(new Character(), new Vector2(level.size.x / 2, 150.0));

    // Walls
    world.spawnActor(new Box(), new Vector2(level.size.x / 2,   0.0),               scale: new Vector2(wallWidth + level.size.x, wallWidth));
    world.spawnActor(new Box(), new Vector2(level.size.x / 2,   level.size.y),      scale: new Vector2(wallWidth + level.size.x, wallWidth));
    world.spawnActor(new Box(), new Vector2(0.0,                level.size.y / 2),  scale: new Vector2(wallWidth, level.size.y + wallWidth));
    world.spawnActor(new Box(), new Vector2(level.size.x,       level.size.y / 2),  scale: new Vector2(wallWidth, level.size.y + wallWidth));

    // Trees
    world.spawnActor(new Shrub(), new Vector2(-200.0, -200.0), scale: new Vector2(200.0, 350.0), rotation: new Vector2(0.0, 1.0));
    world.spawnActor(new Shrub(), new Vector2(level.size.x + 200.0, -200.0), scale: new Vector2(200.0, 350.0), rotation: new Vector2(0.0, 1.0));


    // Spawn Actors
    for (final data in level.actors)
    {
        Actor actor = world.spawnActor(
            data.factory(),
            data.location,
            scale: data.scale,
            rotation: data.rotation
        );

        if (actor is Enemy) enemyCount++;
    }

    // Door
    world.spawnActor(new Door(), new Vector2(level.size.x / 2, 0.0));

    // Update State
    world.onActorRemoved.listen((a) {
        if (--enemyCount == 0) gameOverEvent.add(true);
    });
}