For the last few weeks I’ve been working on Gravity Maze a game/prototype that uses the idea of gravitational forces moving an avatar to solve mazes.
The goal for this game was getting it done quickly and reusing as much code as possible to reach a deadline for a contest.
One of the problems that arose was the interaction between the avatar and the maze. I had two ideas in my mind:
- Using a mask for the walls of the maze and detecting collision with a pixel-by-pixel technique.
- Using a physics engine.
I chose the physics engine for many reasons.
What did it mean? That each wall in the maze was part of a body, this way I could apply a rotation to the body and the whole maze would rotate. Also we got the avatar’s collisions and bouncing for free.
Then another problem arose: how to design levels.
There were a few options here too: creating the levels by hand, or developing a level editor.
I suddenly realized that both options would kill the project. Both were too complicated. Constructing a level editor is a long development task, and doing the levels by hand was a lot of work. Both were so time consuming that conflicted with the main goal of getting things done quickly.
Then I recalled an old project I built in 2005. It was a regular polygon generator that used the n-th root of unity.
The interesting thing about that project was that it generated an SVG using the vertices from the equations.
The idea came to my mind: we could use Inkscape to design the levels! We only had to parse the XML (SVG files are XML files) and bingo!
I started to work at once and, after three hours, we had successfully finished an XML parser that loaded all the walls into the physics engine.
I must say that this simple idea made the difference between finishing the project on time and losing it. I think it’s a great option when there is little time.
If you plan to use this on your next game, be careful! Read the generated XML all the time since Inkscape uses matrix transforms when you move or rotate objects and groups. Either have your parser handle this or design the levels carefully taking care that no transformations are applied.
Another cool detail to have in mind is that Inkscape allows you to add custom attributes to objects.
I used them to define the maze’s start and finish. I'll be waiting for your comments and hope you still use FLOSS and let your head innovate on new ways to use existing stuff!