Talking about Maze game, Game development and Php.
You may wonder why I am publishing another maze script.
The reason is simple: in Perfect maze generation with AS3 post and previous ones I just showed you how to make a perfect maze, but it’s not the kind of maze you can use in tile based or roguelike games.
Why not? Because walls aren’t tiles but just a side of the tile. In tile based games, walls are solid, but in my mazes walls are just paper sheets placed between a tile and another.
And it’s not over: in future posts (yes, expect more mazes, so what?) we’ll see how to convert a perfect maze into a dungeon.
This time I used PHP but it’s easily adaptable to AS3 or whatever other language, and of course I used backtracking.
The script is similar to the other ones, anyway I want to focus on maze size: in a normal perfect maze the size of the maze is exactly the number of empty spaces (tiles) we have on each side.
This happens because walls are not solid tiles, but just lines between a tile and another. Same thing for the boundaries.
In a tile based maze, a wall is a concrete tile, and same thing for the boundaries, so if you want a tile based maze with (virtually) the same walkable tiles as a normal (x,y)
one, your size has to be (x*2+1,y*2+1)
.
Finally, when you walk through the maze removing walls, in tile based mazes you must walk through 2 tiles at every step, assuming the first tile is a wall and the second one is the tile you want to land on.
So here it is the script
";
for($x=0;$x<$height;$x++){
for($y=0;$y<$width;$y++){
if($maze[$x][$y]==1){
echo "#";
}
else{
echo " ";
}
}
echo "
";
}
echo "";
?>
At lines 3-4 you define maze size
And this is a demo of the script with a step-by-step explaination of the entire process during the creation of a 8×8 maze
If you want to translate it into AS3, I will be glad to publish it.
Next time, I’ll show you the differences between this maze and a dungeon.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.