PDA

View Full Version : Tiled edges, between water and land!


Cyprus106
02-26-2008, 12:45 AM
I've got a tile-based map with Grass and Water. My big problem is the grass tiles have a grass picture and the water likewise. But when I went about making a jpg for when the water meets the land, I ended up with the STICKIEST most convoluted code...

Basically, right now I've got a series of booleans and IF statements to find if grass is directly above, directly to the right, to the left, (and above+left) etc. of the water tile. If it is directly above and not above and to the right or left, it loads a jpg to show that. If it's directly above, above/right or above/left it loads 2 different jpg. There are a lot of possibilities there and subsequently a ton of possible jpgs... not to mention the code itself is... laughable.

What have other people done? Maybe... is there a way to load a jpg that represents partial land on the left and place it on top of my water JPG, etc?

I really appreciate any help!

rrh
02-26-2008, 06:46 PM
You could use a transparent .png for layered images, but that might not result in the cleanest code, either.

Old games usually built this into the map itself, rather than generate them when the map is loaded. If they did calculate it, they'd probably assign each tile a bit in a number, and then use that number to pick the tile out of an array.

Say you assign numbers like this:
123
4_5
678

and this shows the placement of land & and water _
&__
&__
___

Then your corresponding number to represent the surrounding water in binary:
11110110
The first and fourth digits are 0 because they do not have water. This means you would need 256 different tiles to represent all possibilities. Usually they would make the graphics so they could safely ignore diagonals, which would cut it down to 4 bits, and only 16 tiles. Then if you add grass into the mix, you bump it back up to 8 bits, and 256 tiles.