Original Post
🔒 Locked
random iso map
Advertisement
Are they the tiles I supplied in my article? If not, why do you have a hole for tile 16?
Anyway...
How I'd did it was to create a 6x6 grid and do the usual random height generator, making sre you only change the height by one along the X / Y axis...
the 6x6 grid for your test map is (ignore the X rows for now):
Now to convert this into the 5x5 map take the 4 values around an X and assign these to a bit field:
Making sure that the values you put in are the diference between the lowest height for that 4 and the corner your looking at. Once you put these values into a bitfield, you will have the tile you need. If there is a case where the height between the lowest and highest point is 2 then you use the special tiles at the end of that tile set you pasted.
First row conversion:
0 0 0 0 = Tile 0 or a flat tile ( 1 1 1 1 = tile 0 as well )
0 1 1 0 = Tile 6 or the slope up at the bottom right
1 1 1 1 = Tile 0 as the lowest point is also the same height as the rest of the tile
1 0 0 1 = Tile 9 or slope down from top right
0 0 0 0 = Tile 0 or a flat tile ( 1 1 1 1 = tile 0 as well )
Nice and easy 2 stage process...
Of course you could add a further tileset for water - ground (basically all the edges at height 0 have some sand on them, and the flat tile is blue) or a rocky set (brown tiles) and finally a white set for snow.
Anyway...
How I'd did it was to create a 6x6 grid and do the usual random height generator, making sre you only change the height by one along the X / Y axis...
the 6x6 grid for your test map is (ignore the X rows for now):
0 0 1 1 0 0 X X X X X0 0 1 1 0 0 X X X X X0 0 1 1 0 0 X X X X X0 1 1 1 1 1 X X X X X0 1 1 1 1 1 X X X X X0 1 1 0 1 1Now to convert this into the 5x5 map take the 4 values around an X and assign these to a bit field:
8 4 2 1BL BR TR TLMaking sure that the values you put in are the diference between the lowest height for that 4 and the corner your looking at. Once you put these values into a bitfield, you will have the tile you need. If there is a case where the height between the lowest and highest point is 2 then you use the special tiles at the end of that tile set you pasted.
First row conversion:
0 0 0 0 = Tile 0 or a flat tile ( 1 1 1 1 = tile 0 as well )
0 1 1 0 = Tile 6 or the slope up at the bottom right
1 1 1 1 = Tile 0 as the lowest point is also the same height as the rest of the tile
1 0 0 1 = Tile 9 or slope down from top right
0 0 0 0 = Tile 0 or a flat tile ( 1 1 1 1 = tile 0 as well )
Nice and easy 2 stage process...
Of course you could add a further tileset for water - ground (basically all the edges at height 0 have some sand on them, and the flat tile is blue) or a rocky set (brown tiles) and finally a white set for snow.
Well, height in most iso views is simply a translation up or down. You can prove this by writing a program that randomly generates an array of height values and then plot them in iso fashion to the screen (each height as a point of intersection of the lines). Now implementing this in a tile based game is ofcourse a bit more challenging. The issue is that if you use standard iso tiles then your elevation will be strictly stair stepping (as all the tiles are flat). To solve this you could create custom tiles that show elevation change (as done above). This would work relatively well but would take some extra constraints to generate a random world that makes sense. Another option is to use 3D logic to “skin” the tile to an arbitrary shape based on the heights generated. This would be fastest if done by a hardware system, however it is relatively straightforward to do this in software. If you want to look into that a good place to start is triangle drawing algorithms.
Hope that helps.
**edit**
Beaten...
Hope that helps.
**edit**
Beaten...
K thanks Steven. Really helped.
One thing tho. How would you generate the heights of the map. C# doesn't have a really good random number generator, so there are practically no flat tiles that are elevated.
One thing tho. How would you generate the heights of the map. C# doesn't have a really good random number generator, so there are practically no flat tiles that are elevated.
From looking online, other people seem to be using the C# random number generator ok, so maybe you're doing something wrong somewhere? But, if you're right, the late great Dak Losar implemented the Mersenne Twister in C# here if you need it.
How are they using the random number generator? Could you tell me where to find a sample? I was using the Random class not the RandomNumberGenerator class, so i guess that's what i was doing wrong.
C# - Urg I'm not touching that with a barge pole - well not for a while at least :D
I've been trying to find an old article I read about a simple random terrain generator, but alas I can not, so this is from memory.
This is in C using the rand() functiona...
Of couse you will have to put in some checks to make sre that the height that has just been done does not break the rules of your tile set, but that code can produce some interesting maps with the right seed for the random number generator.
Doesn't C# use Direct8+ which means your working in DirectGrpahics, if that's the case then I'd sugest forgetting about the tileset, and making the engine use the hieghts that you are generating with your terrrain generator it would look better, and you can change the rand() * 3 - 1 to something like rand() * 5 - 2, which would give you a more random map...
I've been trying to find an old article I read about a simple random terrain generator, but alas I can not, so this is from memory.
This is in C using the rand() functiona...
for( x = 0; x < 6; x ++ ){ for( y = 0; y < 6; y ++ ) { if( ( x == 0 ) && ( y == 0 ) ) /* First pos, pick a random height */ map[y][x] = rand() * 5; else if ( ( x == 0 ) && ( y > 0 ) ) map[y][x] = map[y-1][x] + ( ( rand() * 3 ) - 1 ); else if ( ( x == 0 ) && ( y > 0 ) ) map[y][x] = map[y][x-1] + ( ( rand() * 3 ) - 1 ); else map[y][x] = ( ( map[y-1][x] + map[y][x-1] ) / 2 ) + ( ( rand() * 3 ) - 1 ); }}Of couse you will have to put in some checks to make sre that the height that has just been done does not break the rules of your tile set, but that code can produce some interesting maps with the right seed for the random number generator.
Doesn't C# use Direct8+ which means your working in DirectGrpahics, if that's the case then I'd sugest forgetting about the tileset, and making the engine use the hieghts that you are generating with your terrrain generator it would look better, and you can change the rand() * 3 - 1 to something like rand() * 5 - 2, which would give you a more random map...
Um there's something wrong with the code. there are two if statements that are the same but contain different code.
else if ( ( x == 0 ) && ( y > 0 ) )
map[y][x] = map[y-1][x] + ( ( rand() * 3 ) - 1 );
else if ( ( x == 0 ) && ( y > 0 ) )
map[y][x] = map[y][x-1] + ( ( rand() * 3 ) - 1 );
else if ( ( x == 0 ) && ( y > 0 ) )
map[y][x] = map[y-1][x] + ( ( rand() * 3 ) - 1 );
else if ( ( x == 0 ) && ( y > 0 ) )
map[y][x] = map[y][x-1] + ( ( rand() * 3 ) - 1 );
Quote:
Original post by web_scripter
Um there's something wrong with the code. there are two if statements that are the same but contain different code.
else if ( ( x == 0 ) && ( y > 0 ) )
map[y][x] = map[y-1][x] + ( ( rand() * 3 ) - 1 );
else if ( ( x == 0 ) && ( y > 0 ) )
map[y][x] = map[y][x-1] + ( ( rand() * 3 ) - 1 );
Well I did say it was from memory :D
The correct lines should be:
else if ( ( x == 0 ) && ( y > 0 ) ) map[y][x] = map[y-1][x] + ( ( rand() * 3 ) - 1 );else if ( ( x > 0 ) && ( y == 0 ) ) map[y][x] = map[y][x-1] + ( ( rand() * 3 ) - 1 );
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement

