Skip to main content
Version: Next

(PRO) Platformer 1

In this tutorial, we will use this tileset by @KenneyNL to create basic platformer levels. Be sure to check out their work if you like the tileset. We will not care about room decorations very much - the goal of this tutorial is to demonstrate all the basic steps needed to create platformer levels.

image
Example result
image
Example result

Note: I recommend reading Example 1 first as this is a bit harder to set up, and I will not repeat the basics here.

Note: All files from this example can be found at Examples/Grid2D/Platformer1.

Limitations​

If this is your first time reading about procedural platformers, please see the Limitations section of the Platformer generator page.

Room templates​

Below you can see a few of the room templates that were created for this example.

image
Start
image
Goal
image
Basic room
image
Basic room
image
Basic room
image
Basic room

Doors and corridors​

Even though there are no real corridors used in generated levels, we use the corridor feature to make sure that neighbouring rooms do not share walls.

image
Horizontal corridor
image
Vertical corridor

Moreover, there is a small problem with doors because there are no background tiles inside room templates. And that means that when the corridor rooms are placed over non-corridor rooms, all the walls remain there, and it is not possible to go from one room to another (as can be seen in the image below). We usually do not have this problem because when there are background tiles, they are placed over walls and everything is working.

There are no holes between individual rooms because we have no background tile in room templates.

The solution is quite simple. We have to create a simple post-processing task that goes through all door positions and deletes all the door tiles.

[CreateAssetMenu(menuName = "Edgar/Examples/Platformer 1/Post-processing", fileName = "Platformer1PostProcessing")]
public class Platformer1PostProcessing : DungeonGeneratorPostProcessingGrid2D
{
public override void Run(DungeonGeneratorLevelGrid2D level)
{
RemoveWallsFromDoors(level);
}

private void RemoveWallsFromDoors(DungeonGeneratorLevelGrid2D level)
{
// Get the tilemap that we want to delete tiles from
var walls = level.GetSharedTilemaps().Single(x => x.name == "Walls");

// Go through individual rooms
foreach (var roomInstance in level.RoomInstances)
{
// Go through individual doors
foreach (var doorInstance in roomInstance.Doors)
{
// Remove all the wall tiles from door positions
foreach (var point in doorInstance.DoorLine.GetPoints())
{
walls.SetTile(point + roomInstance.Position, null);
}
}
}
}
}

Note: The term doors is used throughout the text but in this context it simply means a connection between two rooms.

Level graph​

Level graph

Results​

image
Example result
image
Example result