# Random 2D Map Generation

This topic is 3967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, im making a game very similar to Worms in Flash 8 and i am having trouble drawring the map. The map should look somewhat similar to this: http://en.wikipedia.org/wiki/Image:WormsArmageddon1.PNG and should also be deformable (if a grenade explodes on the ground, a circular hole will be cut out). My idea was to have a movieclip which is just one green pixel, and another movieclip with a while statement to generate a line of these in the shape of the map and then fill in the gaps. I would need to do it like this so i can have worms walk on the map. When a grenade or something explodes now it would create an invisible circle (with a radius depending on how explosive it is) which would use a hittest to delete the map and would then create more of the pixels along its circumference. This is my idea how to do it, does anyohne have any idea how to do this? (you dont have to show me code in actionscript, i really just need the logic and the maths behind all of this). If there is an easier idea of how to do this effectively, i would also like to here that too :). Thanks in advance, NuclearCarnage

##### Share on other sites
Maybe this can help:
and:
for destruction

##### Share on other sites
yea theyre both quite interesting thanks for that, its given me a few ideas actually :)

however the 3D thing for making random maps is quite hard to do seeing as im using flash :/

anyone else?

##### Share on other sites
I don't know anything about flash, but here is a thought anyhow:

You may be able to use a 2d noise function (perlin or similar) to generate maps like that. For each tile, or pixel in this case, get a value from your noise function using the tile's x/y coordinates. If the value is above a given threshold, make the tile solid. If it's below the threshold, make it empty.

By playing with the threshold value and the parameters of the noise function, I imagine you should be able to generate maps that are pretty close to that style.

Anyhow, good luck!
~Andy

##### Share on other sites
Here is a link to a tutorial which helped me a lot and I've now implemented heightmap generator based on it. I made it on director mx not flash though that shouldnt matter. The tutorial describes diamond-square algorithm and it starts by doing it in one dimension to generate ridgelines that look like they might be what you are looking for. I hope you find it helpfull.

http://gameprogrammer.com/fractal.html

edit. Though I realize this method wont give you cliffs hanging over the terrain like in that picture but maybe it could be used as a starting point or something.

[Edited by - Wrath on February 6, 2008 5:26:19 AM]

##### Share on other sites
Quote:
 Original post by WrathHere is a link to a tutorial which helped me a lot and I've now implemented heightmap generator based on it. I made it on director mx not flash though that shouldnt matter. The tutorial describes diamond-square algorithm and it starts by doing it in one dimension to generate ridgelines that look like they might be what you are looking for. I hope you find it helpfull.http://gameprogrammer.com/fractal.htmledit. Though I realize this method wont give you cliffs hanging over the terrain like in that picture but maybe it could be used as a starting point or something.

yea thats been very helpful actually :D because you can't displace midpoints as such in flash, it gave me the idea to create an array of random points and do a line function on them. im working on it now ;) next thing i need to do is put all the pixels along those lines :|

##### Share on other sites
Quote:
 Original post by NuclearCarnageyea thats been very helpful actually :D because you can't displace midpoints as such in flash, it gave me the idea to create an array of random points and do a line function on them. im working on it now ;) next thing i need to do is put all the pixels along those lines :|

The way I would do this would be to create array of each point of the map ie. for map 129 pixels wide you would have array with 129 cels (like in the tutorial the size is power of 2 plus one for simplicity). You would first generate random values for each end of the array, then calculate average value of those and add random amount of certain range. Next time you would do the same for the both points between the ends and the center but this time you would halve (or multiply with the roughness value) the random range. So you would loop as many times needed for array of given size until all the points have been calculated.

To draw the result to bitmap you could just loop through all the vertical lines of the image and draw every pixel after the value in the array black or whatever color appropriate.

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
14
5. 5

• 9
• 13
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013662
×