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

Make your game models POP with fake rim lighting.

I was watching one of my son's cartoons today and I noticed they models were using serious amounts of simulated rim lighting. Even though it wasn't a dark scene where you'd usually see such an effect, the result was actually quite effective.



The white edge highlighting and ambient occluded creases give a kind of high contrast that is similar to, but different from traditional comic book ink work.


I'll be honest, I don't know if there's a specific term for this effect in 3d design, since my major at university was in traditional art. I learned it as part of photography.


You can find plenty of tutorials on "what is rim lighting" for photography. It basically means putting your main sources of light behind your subject so that they are lit around the edges. It can produce very arresting photographs, either with an obvious effect when used on a dark subject...


..,or as part of a fully lit scene to add some subtle highlights. See how alive the subject look…

How to... build a strong art concept.

So you want to make some art assets for your game. The first on the list is a Steampunk Revolver for your main character to shoot up Cthulhu with. Quickly opening your internet browser you start with a Google image search. Ah, there is is!

It might be a good idea to find a few influences so you don't accidentally end up copying a famous design.


Just mash them up and you're ready to go! Off to your favorite modeling program.
But wait! isn't there more to building a strong design concept than that?

Of course there is.
One of the diseases of modern design is that of recursion. Everything is a copy of a copy of a copy. This is especially a problem with "historical" concepts. Over the course of that recursive process the concept becomes infected with modern design elements, and ends up looking very similar to everything else that anyone else has ever made.
If you want to come up with a really fresh idea, you have to get beyond secondary references and go look at real …

Skynet

Ok, so it's not exactly skynet, but I have got my first AI state working, kind of.


The first state is "HOLD" in which case the agent stays in place where they are and shoots at any unit that comes in range. When I started writing this module, I found that the existing method of triggering actions wasn't good enough to allow the AI to choose the best weapon or target. It worked by simply sending a command to the unit to trigger the currently selected action.

If the action is valid, it triggered, if not it didn't.
That's fine for play controlled units, as that's all they need to do. But AI needs to know in advance if the action is valid. The player can get that info from UI feedback, but that wasn't available to the AI player.

There were three problems:

1. The UI feedback duplicated code in the action trigger function. These  two sets of code could get out of phase so that UI feedback was wrong.

2. The action trigger didn't give enough feedback for …