Monday, December 31, 2012

Mazes continued

Apologies for the outage, I have been sick for the past few days.  Little has been accomplished since late friday evening.  However, I did get some good coding in that evening and would like to share some of the results with you.

Before that though I would be remiss if I didn't give a nod to Jamis for his great blog about mazes.  I had my implementation done before I saw his page, but it's definitely a fantastic resource, and helped me flesh out my understanding of what I am doing.

Anyhow, shortly after my last post I went after making rooms.  Rooms turned out to be harder than I expected.  I first tried to make random rooms placed randomly around the map, allowing for overlaps. That didn't work out as well as I'd hoped.  I added some collision detection of sorts to the random placement of rooms as well as boundaries between rooms and the results were much better.  Once I had the rooms more or less placed as random rectangles, I moved to making 2 to 4 exits per room.  At this point I switched the depth-first algorithm to be after room generation and it very nicely made corridors between the rooms.  (You are in a maze of twisty passages all alike!)  Finally I added code to the corridor searching to say if they had found a room exit or not.  If they did not then they were "trimmed" and re-filled, leaving the larger dead-ends out.  There are still dead ends because of the way my code works though--any dead end that branches off of an exit gets kept.  That will need to be addressed.

Here are some pictures, both with and without the dead end trimming.



I like the overall look with the dead ends intact.  However for the project I'm doing I think I'd like to trim all dead ends as well as make the corridors straighter (rather than randomly turning at every possible juncture).  I'll probably work on that some tomorrow.  In addition, better odd shaped rooms would be useful here as well.

I also dropped my room code over the top of the caves project I did a bit ago and changed the tiles so the rooms were slightly different.  Just for fun.  There could be uses to a mixture of these two methods, though this is very rough.


As usual, the source to the new maze with rooms can be found here.

Edit:  Added with additional code to a github repo by request.

(Comment out lines 267-268 in DungeonLayer.m to stop the dead-end removal.)

More later!

No comments:

Post a Comment