Sunday, June 13, 2010

Crawler Dungeons

While I'd like to start with the character and player classes, I'm going to start instead by talking about what's already done. Basic dungeon generation.

I've actually already worked out a lot of the kinks in the system, so I'll talk about the problems as I'd seen them.

Firstly, I know the top floor of the dungeon is going to be the ground. I'm going to be adding above ground 'building' dungeons too, but they're not ready yet. Anyways, the top floor is the ground, and there are three types of tiles. Floor tiles the character can walk on, wall tiles the character cannot walk on, and ladder tiles the character can walk across, and also climb up and down. Simple.

Really, what this is is a conditional type of simple maze. When a hero looks for a treasure, they calculate all the paths based on moving left and right or up and down, then they go to it. there's less need for the algorythm I wrote now then there originally was, but for the moment it's still in there. I might make the dungeons more complex again, though they look far better when simplified.

Pathfinding aside, the first way I generated random floors was to pick between one and five floors at random, and fill in the entire floor as walkable space. Once all teh floors were filled in, for each floor I picked another floor to connect with a ladder. It was a little complex, and it made it possible to have disjointed underground sections. Also, it made it possible to overwrite floors that already existed with ladders as the ladders came afterwards. Sometimes, there were just huge bricks of space with one ladder next to another and it was hell on the pathfinding, as well as looking ugly.

The first improvement I made was changing how I picked the floors. Rather than picking two to five floors at random, every floor is now picked to be one to three levels below the last randomly chosen floor, counting the ground. That allowed for potentially more floors, and no longer were there floors regularly all pressed up against one another.

The next major improvement I made is the ladder creation. Ladders had been previously started after all the floors were made. They would randomly connect from one floor to any other random floor in the dungeon. So, it was possible with six floors for all the ladders to cut through all the floors above it to reach the ground level, which looked terrible. So, I changed the ladder code. The ladders now pick a random X location on the current floor (as they did before) and they go upwards until they hit any other walkable space. This solved both the problems of having disjoined space (no longer can the ladders pick to go to a space below them), but also with the mess of ladders cutting through multiple floors. If that were to happen, it would just result in one floor acting as a junction between the next, and a sort of staircase effect. Overall, elegant I think.

But, it was still boring. Everything was flat, the dungeon floors always spanned every space on a particular level. So, the most recent change to dungeon generation I made was that floors now span a random number of spaces, from three to two less than the map is wide. They're placed randomly across the map, and with natural random staggering it creates a really nice, burrow-look. Some places have a large deep room with several smaller ones below it and a single separate hole off to the side, some are zig-zagging holes where the characters have to walk the whole length of the dungeon to go down a floor. It's really nice looking.

But what good is a dungeon without treasure? I'll get to treasure, it's mechanics and difficulties next time.

No comments:

Post a Comment