Pure JavaScript perfect tile maze generation – with a bit of magic thanks to Phaser

I am always been in love with mazes and maze games, I created some prototypes about mazes some years ago and now it’s time to re-introduce them again because I want to expand the concept of perfect mazes to create some games.

First, let me remind you the definition of a perfect maze: a perfect maze is defined as a maze which has one and only one path from any point in the maze to any other point. This means that the maze has no inaccessible sections, no circular paths, no open areas.

Now, have a look at the generation of a perfect tile based maze generation with pure JavaScript, using Phaser just to let you see how I am building it:

The script makes large use of backtracking, here it is:

As you can see, drawing a maze is really easy, next time we’ll see how to walk in it thanks to A* pathfinding, meanwhile you can download the source code.