A Maze Game for You
A while back I created a maze game for a tutorial I wrote for Friends of Ed. It uses a recursive function to generate a random maze, then places a player at one end, and then sprinkles bad guys and energizers around the maze.
The object of the game is to get to the other end of the maze. Use the arrow keys to move around, space bar to lay traps.
Download the Source File (20k zip) »
The heart of the maze game is the recursive function that creates the maze. There are three algorithms that are the most widely used, Depth-First Search, Prim�s Algorithm, and Kruskal�s Algorithm. If you would like to read about all of these algorithms, there is a great explanation here. I went with the simplest algorithm, Depth-First Search.
The bad guys’ AI is very simple. Perhaps I should add the ability for some of the bad guys to be able to trace their way back to the start point. This could be simply done by recording the distance from the starting point for each cell as the maze is created. This would be obtained by checking the depth of the recursion of the maze generator function. The bad guy could then look for an adjacent cell that has a distance that is shorter than his current position, and go there.
That might be a little boring because this would be a perfect bad guy, he would know automatically how to reach you at the start point. Perhaps another way to do it would be to incorporate a maze-solving algorithm to let the bad guy figure it out for himself.
Recently Steamed:
- 08/20/2007: Moving to the Bay Area!
- 06/12/2007: iPhone, Flash, and Multi-touch
- 06/11/2007: Apple’s Safari Browser for Windows



Good one
Comment by Hasufel — 11/27/2004 @ 11:44 pm
You got some talent
Comment by Ash Haque — 11/29/2004 @ 7:49 pm
How would i add a new level? It keeps recking the game.
Comment by Jacob Miller — 7/26/2006 @ 7:45 pm
That’s interesting!
But I’m afraid the link to “here” and “maze-solving algorithm” are out of reach.
Comment by acai — 8/27/2006 @ 12:59 am
This is great code and I’m trying to wrap my head around it.
I’ve got a question about it though. I want to make the stage bigger and have therefore increased the size of the maze accordingly.
I can’t work out how to move the players starting point to the centre though. Everytime I do it ends up in a wall and movement is restricted.
Any (more) help would be grately appreciated.
Comment by matt — 5/24/2007 @ 9:21 am
Erm,
Yeah, in reply to my last post, sorry about that, should have spent a little more time looking at the code. Got that all working fine now.
Any reason though, why the game self destructs immediately if you try to publish in flash 7 or later?
Cheers
Comment by matt — 5/29/2007 @ 8:34 am
Matt,
This little proggy is about 5 years old, written in Actionscript 1 - for Flash 5, so I’m not surprised if it blows up in Flash 7. You might want to try changing all instances of null to undefined and see if that fixes it.
Comment by geoff — 5/30/2007 @ 11:03 am
Hiyaaaa… Can someone on here get me a maze game explanation on structure and use pleasles
xx
Comment by Charlie — 11/16/2007 @ 6:54 am