Random 2D Map Generation

Started by
5 comments, last by Wrath 16 years, 2 months ago
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
____________________________Portfolio (under construction) Nastycritter
My tutorial site: Noobic
(my video site is coming soon)
Advertisement
Maybe this can help:
gamedev thread
and:
for destruction
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?
____________________________Portfolio (under construction) Nastycritter
My tutorial site: Noobic
(my video site is coming soon)
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
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]
Quote:Original post by Wrath
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.


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 :|

____________________________Portfolio (under construction) Nastycritter
My tutorial site: Noobic
(my video site is coming soon)
Quote:Original post by NuclearCarnage
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 :|


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.

This topic is closed to new replies.

Advertisement