Bubble Racing: Maze Generator
Note: The source code to Bubble Racing and a living version of this tutorial can be found here.
Rather than taking the time to actually design interesting levels (or create a level editor), we’re going to go with randomly generated mazes instead! It’s amaaaze-ing!
If you’re wondering how one goes about writing some maze-generating code, here’s the secret: Do a search for “how to program something", and some useful results will turn up. I searched for “how to program maze algorithm". This Wikipedia page was one of the results, and it was both helpful and interesting.
Setup
Create the following files and folders:
📂maze_generator
┣ 📜MazeGenerator.gd
Well, the structure of this one is pretty simple. The code is a bit complex though. If you’re interested in looking through the code, go for it! Just copying and pasting it works fine, too. If you’re into that kind of thing.
Here’s the code for MazeGenerator.gd
Test
Create the following files and folders:
📂maze_generator
┣ 📜MazeGenerator.gd
┣ 📜MazeGeneratorTest.gd
┣ 📜MazeGeneratorTest.tscn
Here’s the code for MazeGeneratorTest.gd
Attach MazeGeneratorTest.gd
to the root node of MazeGeneratorTest.tscn
. Hit the Play Scene
button to test out your amazing code.