Make A Maze

I’ve always loved mazes.

I’d also like to build something a little more sophisticated (eg, an RTS). However, anything with that many pieces in play will require some kind of pathfinding. Ie, a pretty major project in itself.

So, in order to get the pieces together such that I CAN start to build this kind of thing inside a day, I thought I’d start with this. The idea is – you build a maze, and my little dude then tries to find his way out. At the moment, it’s a case of letting the user define the play area (an interesting challenge by itself). Thus: click the pieces on the right to define what kind of wall you wish to build, then, click or drag to put it down, creating a maze. Click any positioned wall again to take it away. Pretty simple.

Ok, have a little wizard character in there. There’s some horrible edging around the character – part of the issue with shrinking a slightly larger character down to size. Less important than the pathfinding, so I’ll get to it later.

Right, the wizard was getting a little stuck on the edges of the maze, so I redefined the collision shapes (making them slightly angular stops them getting hooked on the corners). It’s now looking pretty snazzy. You can zoom around with the arrows, and define the maze.

Next up, allow the user to reset the maze, and to hit go, automatically sending the wizard hunting for the finish line.

Reset and Go now work. There’s no path finding (ie, anything in the way will stop the wizard), but it IS moving – in a direct line. Which means a guaranteed score of 27 every time.

Hmm. Interesting. Turns out there’s a bug in the Stencyl Tile API (if you add a tile, then remove it, it leaves the collision box behind). Which means if you change your maze, you have invisible walls. Helpful. I had a look at the source, but it’s too much of a mess for me to easily grok and fix in a few hours.

On top of that, the Haxe pathfinding library I downloaded – which after a bit of fiddling about I managed to get to compile – doesn’t take into account walls. The code is SORT of there (you can add a cost for each node in the grid), but it’s ignored.

Also not helpful. So I’ll have a look at some of the other libraries I’ve downloaded. There’ll be a better one there. This is a bit tedious, but critical. Pathfinding is an absolute core of any decent NPC AI.

Ok, so after a few hours of battling this third party library I was working with, I thought I’d just hack something together to get something out (given that I haven’t even started today’s game yet, and it’s almost 6pm). So, the classic “if you hit a wall turn right” maze solving algorithm. Crude, but it works.

Annnnnd welcome to the world of path finding. Some issues:

  • The wizard randomly gets stuck on blocks (apparently turning right is difficult)
  • The wizard sometimes gets locked on start. Nothing to fix this but restart (not even reset) the game.
  • The scoring is now on high speed
  • Despite turning off ALL collisions, he gets stuck on the edge of walls
  • Despite identifying where the walls are and writing code to avoid them, he still runs into walls
  • The end game identification isn’t done, so he just runs into the wall at the end
  • I can’t get the guy to turn right. He does, then flicks back again. Or something. Very weird

So, you can see there’s suddenly a huge bunch of new bugs. All of which need to be tracked down and fixed in order for this to be vaguely useful. And this was as a “nice quick” alternative to the actual pathfinding. The annoying thing here is – things like crappy collision detection – that’ll come back and bite me even when I get this path finding library in and working perfectly. Back to fighting the environment again – game dev 101.