When I started designing the internal model of the dungeon, I started off with a basic object oriented approach that went something like this – ‘a dungeon has many rooms. A room has many things in it….’. This was all well and good, but I realized that this would cause problems with actual game logic. How would I know where in the room a character or monster was standing? Hmm, all my room knew was its logical position in the dungeon, and who its neighbouring rooms were. So the game logic would have been something like a bunch of air traffic controllers managing the progress of a single flight:
The Bad Way – Air Traffic Controller Game Model
Room A : “The wizard has moved left though the door. Room B, wizard is now inside you.”
Room B: “Thank you Room A. I’ve got the wizard now….”
This is complicated, because the room has to know its location in the dungeon, and the location of the character, but game play would be managed in this ‘pass the parcel’ way. Scrolling the view around as the character explored the dungeon would have been ugly. This approach smelled ‘wrong’, so I abandoned it pretty quickly.
The Better Way – The Grid Model
In this model a dungeon is a big map of discrete grid locations or squares (I’m going with 1 foot squares). This way every object and item has a grid coordinate. As the character moves around, collision detection is simpler (no walking through walls), and the dungeon manager logic could query each grid square about it’s objects, which room it belonged to and so on. The downside is that there is a lot of redundant data sent to the browser for drawing, as most of the grid information is the same for neighbouring squares (hmm..I smell an optimisation…). Still, this way feels cleaner, simpler, and there are ways to reduce the size of all that grid data sent down the wire.
With the grid model, a dungeon editor would look something like a big grid with clickable grid locations:
I am working on this and plan to add the dungeon editor to the Web Dungeon app soon. I have adapted the flood fill algorithm (in Dart of course!) to quickly find out which grid locations belong to a room and paint it. It’s pretty neat and will allow the designer (me for now) to right click a grid location inside the room and select ‘Create Room’ and give it a name.
The reason I am building this (apart from the fun factor) is that I have manually created some dungeons, and found the process awkward. I decided there were enough reasons to divert on a minor tangent and build a dungeon editor specific to my needs. It also dovetailed with my plans to allow players to create their own dungeons. There are dungeon generators online, and some are excellent (I really like donjon) but they output text or images. I need to export everything as JSON, send it to the browser,create a Dart object model and then draw it.
After I finish the editor and build a simple dungeon, I will use it in Web Dungeon and get my red runner sprite walking around the dungeon.