Home » Community » Forums » » Tile/Map-Based Game Techniques: Handling Terrain Transitions
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Tile/Map-Based Game Techniques: Handling Terrain Transitions
Post Reply 
There is on best method with only 14 transitions in my french tut :

http://site.voila.fr/pcmappeur1/code/tuiles.htm

 User Rating: 1015    Report this Post to a Moderator | Link

I use a slightly different method.

I use an array that stores a value for each terrain type. This value is a decimal, and it represents what other terrains it can overlap.

A simple example:

My map has 3 terrains, water, grass and sand, represented in the map array as 0,1 and 2 respectively.

My terrain overlap array stores 3 values, 1 for each terrain, and is worked out like this.

Water (bit1) has a value of 1, grass (bit2) is 2 and sand (bit3) is 4. If I want grass to overlap water and sand, it has a value of 5, and if i want sand to overlap water, I give that a value of 1. It follows that water cannot overlap anything, so it has a value of 0. My array therefore is (0,5,1).

Now when drawing a tile, you check the map value of its neighbours ie 8 tiles for a square, 6 for a hex... etc. A simple 3x3 map for example, with grass around the edges and sand in the centre would be ((1,1,1),(1,2,1),(1,1,1)). Say the sand tile is now being drawn, first the basic sand graphic is drawn, then (assuming a square tile) its 8 neighbour tiles are looked up one at a time. Starting with the NE neighbour (doesn't matter what tile you start from), it has a value of 1, so in the overlap array you look up position 1, and see it has a value of 5 (or it overlaps bits 1 and 4). Have you noticed yet with the map data, the tile values correspond to 2^tilevalue=bit value? Take your sand tile (the one currently being drawn) and its value becomes 2^tilevalue or 2^2... its bitvalue is 4. If you then AND the neighbour tile's overlap value with the drawn tile's bitvalue, the result will equal 0 if no overlapping is allowed, or will equal the bitvalue if overlapping is allowed. 5 AND 4 =4, so the NE neighbour forces an overlap in the NE corner of the drawn tile.

This reduces the ammount of graphics needed, you simply have a base graphic, then an overlap graphic for each neighbour possibility (ie 8 for squares), so for each terrain type you only need 9 differnt graphics to represent all possibilities (1 base,4 for edges, 4 for corners). With hex tiles this only needs 7, 1 base and 6 edges (theres no corners produced in a hex map).

Also this method gives you a bit more flexibility, you're not limited to just having a certain terrain overlapping all terrains lower down in the chain. Say grass overlaps water, and water overlaps sand, you get the heirachy grass -> water -> sand, theres no way you can get sand to overlap grass if you wanted it to. However if you use an array to define what terrains can overlap, you can have any combination of overlaps you desire.

If you so wish, you can even go one step further and use the same method on the overlap graphics, giving you some interesting transition possibilities.

 User Rating: 1015    Report this Post to a Moderator | Link

ok there is one thing i didnt fully understand. how do you determine which tile texture you need depending on the two 4bit blocks?


also, i think you can save even more textures by using reflections and rotations.

 User Rating: 1028   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Does this article still shows us a good way how to develop a small tile-based game or is it out-dated?

Do you guys know where the tiles comes from? I really liked them as a prototype when during development.



 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by vermin123
Does this article still shows us a good way how to develop a small tile-based game or is it out-dated?
How can the generic technique of tile transitions with prioritized overlay fringes be outdated? The only "competition" is structuring maps and tiles differently, mainly with explicit transition tiles between the main tiles or with terrain types assigned to edges or corners rather than tile centers.
Quote:

Do you guys know where the tiles comes from? I really liked them as a prototype when during development.

As the article explains, an early version of the author's game, "Artifact".



 User Rating: 1211   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: