I would like to have a system that randomly generates rooms (for something like a house that you only see the inside of). Something that would look like this from a top-down view:
Either example would work for me. I spent a large portion of today trying out different ways of generating random rooms, but I could not come up with anything that worked the way I would have liked it to. It would be cool if it could be set up in a Spelunky-esque way where you can make different rooms and the generator will randomly pick five different rooms and put them together. (That’s why I’ve been trying to make).
Any nudges in the right direction would be greatly appreciated.
You could either do it procedurally or create a large set of “puzzle piece” rooms of different sizes, check the size of the partitioned space and select an appropriately sized room to spawn into that area.
If your binary tree is building “rooms” you can store whatever data you want about a particular “room” when it gets generated and placed in the tree.
Think about the structure of a binary tree, or at least research it a bit, the links provided in a post above are quite useful.
The leafs of the tree at the bottom of the structure will be your final iteration on the tree, thus the final “version” of the generated dungeon. If you use objects to represent your rooms, upon generation you can store perhaps the width and height of the room within the object thats held in the tree.
I wrote a quick BP based on the algorithm explained herein. It only includes the portion to for building BSP. I’ll post it as soon as I work out the bugs.
I created a box structure that contains 4 Vectors: Start, Stop, (Size, Center for future extension). For 2D, I only use the X,Y values.
Building the BSP
I start with a Box that is the maximum size and store into a array. For this example the its 9x9
At the end of the day doing this only results in an Array with the final layout which is what you probably intended. Though building a Binary Tree properly has its uses, you may want to perform operations on different levels of the tree after its generated the rooms.
Well done on the explanation of the algorithm though.