PDA

View Full Version : tile based maps generator



kalyman
September 15th, 2010, 07:25 AM
Hello all,

Currently am trying to create game editor for strategy game and so far I came up with this (https://dl.dropbox.com/u/565190/editor%20%282%29.swf) just a small part. What I am trying to achieve is nice rounded edges like in some other strategy games that would generate nice transitioned edges even between different type of terrains for now only between water and grass. some example of edge tiles >> http://img716.imageshack.us/img716/7185/examplero.jpg http://img230.imageshack.us/img230/7175/example2ax.jpg http://img715.imageshack.us/img715/4143/example3j.jpg
So Map array will hold full tiles (like grass or water) that have special variable (tile placing) that hold if tile is full or edge. I just cannot figure out algorithm that will calculate where to put edges and where dont. Every time I end up in neverending loop :( Is there some example or tutorial that explains this problem?

Thank you.

bluemagica
September 15th, 2010, 08:12 AM
First layout all tiles as ground or water. After that is done go through all the tiles in a loop, and for each tile check if it's surrounding tiles are of another type, and if they are switch the tile image.

You should show us your code so that we can help fix where you are doing wrong. Also, if you don't want to generate your map in code, you can always try a freeware map editor called "mappy", create you map in it, and generate a 2d array for use in flash.

Your problem however sounds interesting, so I will write a tutorial on this later.

kalyman
September 15th, 2010, 03:27 PM
Thanks for reply bluemagica. Am still playing with it even now :) here is part of the code but its just getting too complicated, I wanted to do it using recursion but somehow i cant :)


private function create_edges(){
var P:Point=new Point(0,0);
for (var i=0;i<map_size[selected_map];i++){
for (var j=0;j<map_size[selected_map]; j++){
if (map_array[i][j].terrain.tile_placing==P){
if(map_array[i+1][j].terrain.tile_placing==P){
// check neighbors
if((map_array[i+1][j-1].terrain.tile_placing==null)){
map_array[i+1][j].terrain.tile_placing.x=1;
map_array[i+1][j].terrain.tile_placing.y=4;
} else
if((map_array[i+1][j-1].terrain.tile_placing==P)){
map_array[i+1][j].terrain.tile_placing.x=2;
map_array[i+1][j].terrain.tile_placing.y=1;
} else
if((map_array[i+2][j-1].terrain.tile_placing==(3,4))){
map_array[i+1][j].terrain.tile_placing.x=0;
map_array[i+1][j].terrain.tile_placing.y=0;
map_array[i+1][j-1].terrain.tile_placing.x=0;
map_array[i+1][j-1].terrain.tile_placing.y=0;
create_edges();
} else
{
map_array[i+1][j].terrain.tile_placing.x=1;
map_array[i+1][j].terrain.tile_placing.y=4;
}

}

}
}

}

where map_array holds all variable from map so terrain.tile_placing is type POINT where X of it represents what tile to use like 0 will be full grass tile, 1 is http://img716.imageshack.us/img716/7185/examplero.jpg, 2 is http://img715.imageshack.us/img715/4143/example3j.jpg, 3 is http://img230.imageshack.us/img230/7175/example2ax.jpg and Y represents rotation of that tile. So P is (0,0) which is full (grass) tile. Am just trying to understand if there is some repetition to it so i can just place it into one function and then repeat for all tiles. But even all this code wont check all the neighbors of selected tile.

something like from this >>
http://img215.imageshack.us/img215/5716/63029017.jpg
to this >>>
http://img801.imageshack.us/img801/7972/36228948.jpg