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...
...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.
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:
Layer 2:
Layer 3:
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.
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 |
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
Post a Comment