dXter![]() Member Posts: 59 From: Texas, the US of A Registered: 09-26-2006 |
Is there any "best" way to make destructible terrain like in Worms? I looked for articles and stuff on the web but I didn't find very much on this topic ![]() I found two methods, though: 1) to make the terrain and background made up of large tiles, say 128x128, and when there's an explosion, all tiles that touch the explosion divide into 4 parts, making 4 64x64 tiles. The smaller tiles that are still touching the explosion divide further and the process repeats until you have very small tiles that are touching the explosion. These are then destroyed. 2) to have a huge array holding all the pixels, and when there's an explosion, all pixels affected are changed. I like the first method better, but are there any other ways of doing it, maybe better ways? ------------------ "Time is an excellent teacher, but eventually it kills all of its students." |
|
Lava Member Posts: 1905 From: Registered: 01-26-2005 |
2D Terrain right? A 3rd method could be make the ground like a sprite, and then make different frames of what the ground will look like, like when it's destroyed alot or specific areas. ------------------ |
|
dXter![]() Member Posts: 59 From: Texas, the US of A Registered: 09-26-2006 |
Yeah, but I mean code-generated terrain destruction, like taking out a chunk of dirt where there was an explosion. [url]http://www.deviantart.com/deviation/39769589/[url] shows exactly what I'm talking about. ------------------ "Time is an excellent teacher, but eventually it kills all of its students." |
|
Cohort X![]() Member Posts: 126 From: The Great Pacific Northwest Registered: 09-16-2006 |
Make two pictures . a background and a terrain picture. wherever you have an explosion slap down a picture of a circle the same color as the background. making new ground able two be walked on might be a bit of a challenge with this method. | |
CoolJ![]() Member Posts: 354 From: ny Registered: 07-11-2004 |
Maybe store a bit mask of the non-terrain(open area) and open area created by destoying terrain. Then you could use this mask for both bounds checking and XORing with the terrain to remove your destructed terrain. | |
HanClinto![]() Administrator Posts: 1828 From: Indiana Registered: 10-11-2004 |
Games like Worms, Liero, Gusanos, and other 2d games with destructible terrain often have a single bitmap image that is the "collidable ground". This is usually the dirt layer. The worms all use something called "pixel-perfect collision detection", which lets the worms follow the terrain of the ground on a pixel-by-pixel basis. To deform the terrain, you can either paint on it (to add ground when generating a level), or you can clear it (like when there's an explosion) -- usually by setting to a keyed color or by nixing the alpha channel. Does this make sense? I'm happy to explain it more, but this is a basic overview. --clint |
|
dXter![]() Member Posts: 59 From: Texas, the US of A Registered: 09-26-2006 |
Thanks clint, I'd seen pixel perfect collision detection in the GTGE game engine but I didn't really know what it was. I was just wondering, when the worms are walking, do they check for a steep slope that makes them stop by checking if there are a certain number of vertical pixels right in front of them, like say 2 or 3? Sorry, I don't know anything about this kind of stuff. ------------------ "Time is an excellent teacher, but eventually it kills all of its students." |
|
Realm Master![]() Member Posts: 1971 From: USA Registered: 05-15-2005 |
GAA! I posted something like Clint's repsonse (LIKE, Not CLint's response) but it didn't show And I don't want to type it again... ------------------ Awaiting Avatar Image Size rechange... |
|
HanClinto![]() Administrator Posts: 1828 From: Indiana Registered: 10-11-2004 |
quote: Yup! You're exactly right! Good job figuring that out. Basically, when you do test rect-hits to determine if you move or not, you'll move your test rectangle incrimentally up to see if you can move there. Bah, it's hard to explain with a description, here's some pseudocode:
I hope that's readable pseudocode, but that might give you some clue as to how something like this would work out in a real situation. Feel free to ask for any clarifications or follow-ups -- I really enjoy games with deformable terrain. Cheers! In Christ,
quote: Bummer. I hate it when that happens. :-\ |
|
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
I coded one which did created the 'terrain' as a big array. I did this like 2-3 years ago, and it started to run like crap over time (obviously ![]() It's in C/C++ and OpenGL. You move the mouse around and click on the terrain, and it'll go and delete a circle out of the terrain, and the terrain will fall until it collides with other terrain, or with the ground. Using an array isn't too bad, if you can speed the rest of it up, it'll be fine... I would most likely do it now by having the terrain as a bitmap. And then when you click on it, you delete (make them a certain 'colour key' colour, which you'll use as a sort of 'alpha') those pixels. You could check over all the pixels in the bitmap on each update and if they can move down one pixel (if the pixel below them is that colour key), then move it down one pixel (change the colour of the pixel below the current pixel) and then set the pixels previous position (up one) to the colour key value. ------------------ |
|
dXter![]() Member Posts: 59 From: Texas, the US of A Registered: 09-26-2006 |
quote: Wow.... I actually guessed something right about this kinda stuff for once. Usually when I try to figure out something like this and then check in a book or online to see if I'm right it goes into this whole other thing and says that other, simpler methods (the kind that I think of) are inaccurate or slow or something. Thanks for the explanation, Clint ------------------ "Time is an excellent teacher, but eventually it kills all of its students." |
|
Lazarus![]() Member Posts: 1668 From: USA Registered: 06-06-2006 |
quote: I know exactly what you mean! Laz |
|
buddboy![]() Member Posts: 2220 From: New Albany, Indiana, U.S. Registered: 10-08-2004 |
yeah, happens to me like all the time too. ------------------ | |
|
Jari![]() Member Posts: 1471 From: Helsinki, Finland Registered: 03-11-2005 |
Maybe you could learn from a source of the clonk planet. It uses something called "mass mover" for moving water and sand particles and should have all the code you need. The latest version of it is not free but the version before that is. ------------------ [VoHW] (Help needed) [Blog] - Truedisciple (mp3) |