Skip to main content

4 walls and a floor.

 4 walls and a floor.

Those are the basic options when creating a room in a game. Of course, one or more of those walls could have a door. And some rooms might have pits, stairs, secret doors or other features.



A room is made up of any number of tiles laid edge to edge. What is important is how those tiles are combined to create the room.

We might construct our room taking in to account each neighbor, including diagonals. This is just making a rod for our own back though, and results in lots of tiles and much more work. I've tried it in the past and the result is not any better that what I'm going to describe here, more work seldom results in better results, we need to find the optimal solution. With that in mind we only really want to look at the tiles in the cardinal directions.

In that case a tile is made up of 1 square with 4 neighbors, that makes 5 components...

Cardinal Tiles
 ...but with a clever bit of offsetting we can make one of the neighbors the original square. That means any that any tile has just 4 components.

Offset Tiles

If you have only walls and floors you need only 16 different combinations (4 to the power of 2, or 4x4) to create any kind of room. If you also have doors you need 4x4x4, or 64 combinations. If you want to add corridors, pits, stairs up and down, secret doors and other features you start getting in to impossible levels of combination. Of course it's not just straight numbers, some combinations are impossible and can be discarded, but it's still a huge number of required tiles.

Using a set of rules can help, so that further combinations are impossible; for example corridors can only be bordered by corridors or doorways or doorways can't be placed in the corner of rooms and doorways can't border other doorways. But it still leaves a lot of work to do. Also as I started to put together art assets for the tile sets I was very unhappy about how they looked, every thing had to be exactly square to fit together, negating many of the advantages of the new system altogether. There was no way to know what a tile edge might be joined up to, so there was no way to get a pleasant transition. How can we get around these problems?

The solution is actually quite simple, we just use layers.

Layer 1:
  • Floors and pits.

Layer 2:
  • Walls, open spaces (which could be either pits or floors) and doors. (with rules to state how they can be combined). Walls can be corridors, but as above they can't mix with regular walls.

Layer 3:
  • Overlays. These can be anything, but for now I'm just using bridges as a test case. 

The layers are added one at a time and parented together, so that any visibility checks will make the whole stack visible or invisible as needed.
The resultant tile set looks something like this:


The bridges now are overlays and are added to pit squares. Overlays need to be handled differently to regular tile parts, they don't have an offset, so they are placed using a different algorithm (The cardinal tiles picture above show how).

I hope to write an algorithm to get the walk mesh directly from the combination of tiles rather than placing the parts and then "reading" the level to get the walk mesh data. This has a lot of benefits, such as being able to check a level for walk-ability during generation, and also being able to load the level in chunks, reducing loading time considerably. Again it'll be handled by getting the walkable tile data in layers and then using layer masks.

Anyhow, the current result looks like this:

As a bonus I've also added some code to place an "error tile" whenever the rules are broken during placement. This gives visual feedback about what you can and can't do.

Still needs some more work, perhaps I'm going to make doors and stairs as overlays like the bridges, or maybe not. I'm not sure yet. I'll try it and see how it feels.

Comments

Popular posts from this blog

Advice needed on tilesets...

I need some advice on which is the best way to handle building the dungeon. Right now I'm using prefabs for my dungeon, they have a north south east and west section for each "room": The basic tileset. This has several advantages, and also several disadvantages. Firstly I can have curved rooms, I can have tunnels and other interesting shapes. The tilesets can look quite nice with a little work. On the other hand I can't easily get the navigation data before building the map and once the map has been built I can't make changes to the layout, like having active pit traps or believable secret doors. Although the rooms are interesting, they are quite repetitive, and it takes a lot of effort to make even a few different variations. Also rooms are constrained to one size. A newer version of the tileset with a lot of variant parts for making more interesting rooms. To create a tile set is a real headache too. Planning how to lay out the UVs, trying to cra...

Upstairs / Downstairs.

I've decided to make my prefabs multilevel. Later this should allow me to add pit traps and other great stuff. It also makes it easier to line up stairs so that you can exit them on the same co-ordinates where you entered them. The prefab editor is pretty much finished, it just needs some code for loading up prefabs from a saved dictionary, so that they can be checked or edited. The entries will need to be forwards compatible, so I'll be loading each tile and then translating the indexes to a new array, that way if I add extra indexes or extra info (like traps or puzzles) I'll be able to update existing prefabs to work with the new standard. Click for a video.

Video Diary 8

Things are moving along well, there's been a lot of progress on the action manager side of things. Actions have finally moved to the UI, so you can initiate actions by clicking the appropriate button. I've set up some dummy actions to show what happens visually when actions are taken, but the actual dice rolls and such are yet to be integrated. The UI objects are also being added, though some are non functional or empty at the moment. Click on the image to see this week's development video. Every time I add something big I also add about a dozen small things. Like the selection box visualization. Previously this was using render.drawline, and old fashioned Blender function which can be impossible to see at certain resolutions, or at certain frequencies. I replaced it with a function that adds planes of the right size and scale in the right location. I also made all characters a little bigger. I still need to do some work with vectors and final target locations t...