Setlock
Setlock

Reputation: 47

Creating 2D Angled Top Down Terrain Instead of Fully Flat

Similar to the game Factorio im trying to create "3D" terrain but of course in 2D Factorio seems to do this very well, creating terrain that looks like this enter image description here

Where you can see edges of terrain and its very clearly curved. In my own 2D game Ive been trying to think of how to do the same thing, but all the ways I can think of seem to be slow or CPU intensive. Currently my terrain looks like this: enter image description here

Simply 2D quads textured and drawn on screen, each quad is 16x16 (except the water thats technically a background but its not important now), How could I even begin to change my terrain to look more like a Factorio or other "2.5D" games, do they simply use different textures and check where the tile would be relative to other tiles? Or do they take a different approach?

Thanks in advance for your help!

Upvotes: 2

Views: 1708

Answers (2)

Dominik
Dominik

Reputation: 41

I am a Factorio dev but I have not done this, so I can only tell you what I know generally.

There is a basic way to do it and then there are optional improvements.

Either way you will need two things

  1. Set of textures for every situation you want to handle
  2. Set of rules "local topology -> texture"

So you have your 2d tile map, and you move a window across it and whenever it matches a pattern, you apply an appropriate texture.

You probably wouldn't want to do that on the run in every tick, but rather calculate it all when you generate the map (or map segment - Factorio generates new areas when needed).

I will be using your picture and my imba ms paint skills to demonstrate.

This is an example of such rule. Green is land, blue is water, grey is "I don't care". In reality you will need a lot of such rules to cover all cases (100+ I believe).

A rule for terrain texture selection

In your case, this rule would apply at the two highlighted spots.

enter image description here

This is all you need to have a working generator.

There is one decision that you need to make here. As you can see, the shoreline runs inside the tile, not between tiles. So you need to chose whether it will run through the last land tile, or the last water tile. The picture can therefore be a result of these two maps (my template example would be from the left one):

Shoreline_drawing

Both choices are ok. In fact, Factorio switched from the "shoreline on land" on the left to the "shoreline on water" on the right quite recently. Just keep in mind that you will need to adjust the walking/pathfinding to account for this.

Now note that the two areas matched by the one pattern in the example look different. This can be a result of two possible improvements that make the result nicer.

First is that for one case you can have more different textures and pick a random one. You will need to keep that choice in the game save so that it looks the same after load.

Another one is more advanced. While the basic algorithm can already give you pretty good results, there are things it can't do. You can use larger templates and larger textures that span over several tiles. That way you can draw larger compact pieces of the terrain without being limited by the fact that all the tiles need to be connectable to all (valid) others.

Upvotes: 4

n247s
n247s

Reputation: 1918

The example you provided are still 2D textures (technically). But since the textures themselves are 'fancy 3D', they appear to be 3D/2D angled.

So your best bet would be to upgrade your textures. (and add shadow to entities for extra depth).

Edit:

The edges you asked about are probably layed-out by checking if a 'tile' is an edge, and if so it adds an edge-texture on top the background. While the actual tile itself is also a flat image (just like the water). Add some shadow afterwards and the 3D illusion is complete.

I hope this answers your question, otherwise feel free to ask clarification.

Upvotes: 2

Related Questions