Sunday, October 5, 2014

Unity Maze Generator (For Programming Class)


      My programming 3 class was tasked with making a random maze generator over the weekend for our first exam grade. Needless to say it ate a lot of my free time. When people talk about programming 3 they always mention the dreaded maze assignment so it's my class' turn to suffer. Next semester we take on the assembly classes seniors are complaining about.

     The teacher wants to be able to pick the width, height, and frequency of wall blocks. He even says it doesn't have to be solvable. It definitely doesn't search for the fastest path either. Just a start, end, border, walls, and a final path. As to not let my hours of headache go to waste I figured I could share a bit of how I did it below the break.




     This "beautiful" menu above is the interface I slapped together so the input can be entered. As you can tell I put zero polish into this because it's just for a grade and it's the functionality that's being graded rather than the experience. I reused a bunch of sprites from TriGrid and Unicorn Training for everything here.

This is how I centered the camera on the maze and set the end points.
     Due to a problem with camera zooming, I made it so the grid only reaches a maximum of 30x30 using the same limiter that keeps the percentage at or under 100. I also threw in a backspace and clear key for typos. Pressing the blue button will take you to the grid scene where you can see the result. If you want a new maze, you'll need to reset the program. Why not design something more complex and useful? Because I want to go back to working on my game as soon as possible.

This is how blocks decided which sprite to be.
     Once the maze is up it solves itself in one quick frame then highlights the path it took to get from the blue start square to the glowing finish square. It basically figures out which way to go by looking north, then south, then east, then west while preferring to take paths it hasn't stepped over already.

This is how I organized the squares.
    The lesson was about mastering stacks and queues and hopefully I pass with flying colors when I turn it in on Tuesday.

No comments:

Post a Comment