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

Back to Vinland.

I'm going back to my real time tactics project, Vinland 1936.
While working on the other project I overcame the problems which were stopping me from saving/loading the game and also cleaned up the base code a lot.

After a few weeks I'm getting near the the state I was in before.


Infantry are back to their previous state, and vehicles are running OK.
This time I'm going to push ahead with mocking up the combat system though before I work any more on the vehicle builder or graphical aspects of the game.

Map screen designs

I've been working some more on the map window. Right now you can only see the base, it doesn't show items, enemies or even doors on the map yet. These would be decals.


In the top window you can see the modified result of last night's tile based map. It looks good but there are some visual artifacts related to the problems I encountered yesterday, and as well it takes much more code and time to calculate.

The second window uses a cheap trick to fake an beveled look from a smoothed version of the 32x32 map. It uses black to mask unexplored areas.

Finally the third version is meant to look like a had drawn map. I'm using a cross hatching texture to distort it and unexplored areas are shown as blank map paper.

There's going to be a mechanic in game where you need to use some paper every level in order to activate the map for that level. From there it will fill it in automatically. Paper will be pretty rare so it might be worth keeping it safe for the more complex level…

Infantry combat and entering buildings.

I've been working a lot on the game recently and I've nearly rebuilt it to the level it was before. Past that maybe, since now I have the beginning of a working combat system and the ability to save and load the game.


Infantry can now occupy a building. It's quite an abstract representation, since they stay at the door and turn invisible. But they can then fire from one of the windows and take damage from shots at the windows too. I think I've set it up well so that when building damage and destruction is working then the system should continue to work.

For combat I tried some new ideas, but they didn't work out that well. It seems that it's important that viewing range should be further than shooting range. Now shooting range is pegged at 18 units of distance, while viewing range can extend out past that.

In the above image one unit has an officer, so has further viewing range. The other can only see as far as they can shoot, a dangerous situation since the en…