Eating away at 2d-terrain?

Started by
7 comments, last by MarauderIIC 19 years, 11 months ago
I'd like to draw, say, a 2d building, hit it with something, and have a crater appear in part of the building (like in Worms ). Problem is, I have no idea as to how to go about this. (I suppose my problems are a little with collision detection and a lot with modifying the image.) Can anyone help give me a start? [edited by - MarauderIIC on May 25, 2004 2:16:29 PM]
"Is that a snow-globe in your fire blanket,or are you just stark naked?" --RavenBlack Surrealism
Advertisement
I think worms does a "per-pixel" collison detection and deformation.

I think for the terrain they just have a 2D terain map in a pixel buffer (stored in local memory) on which one color value indicates a solid pixel and another empty space.

and then to deform it it would just take out the pixels and turn em into empty space.

I don't know their exact collision algorithm. But its not that hard to figure out a simple one.

[edited by - snisarenko on May 25, 2004 3:39:29 PM]

[edited by - snisarenko on May 25, 2004 3:41:12 PM]
How do you take out pixels?
"Is that a snow-globe in your fire blanket,or are you just stark naked?" --RavenBlack Surrealism
pbuffer[x][y] = 0 probably...
What snisarenko is trying to say is this:

0 = No Land
1 = Land

Map1:
00000000000000000000000000000000000
00000000000000000000000001100000000
00000011000000000000000011110000000
00000011111000000000000111111000000
00011111111111111111111111111100000
11111111111111111111111111111111111
11111111111111111111111111111111111
11111111111111111111111111111111111
11111111111111111111111111111111111

You check the array and if theres a 0 then you wouldn't render that part of the land. If there is a 1 then you would render that part of the land. So if you shot a bomb and it hit the hill, you just turn the values where the the bomb hit and the blast radius to 0's. Then when you render the next frame it would look like it got "blown" away because it wouldn't render that area of the land. So now it would look like this:

Map1 After Explosion:
00000000000000000000000000000000000
00000000000000000000000001100000000
00000011000000000000000011110000000
00000011111000000000000001111000000
00011111111111111111000001111100000
11111111111111111111100011111111111
11111111111111111111111111111111111
11111111111111111111111111111111111
11111111111111111111111111111111111

One thing though, if you have a large terrain it may be a little slow looping through every item in the array every frame. You would have to use some sort of algorithm that would only check to see what chunk the explosion occured in. Thats another story, but maybe an quadtree would work pretty good...

BTW:
Worms is one my favorite all time games... Now you got me in the mood to play it?!?!??!

-UltimaX-
|Designing A Screen Shot System|

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on May 25, 2004 5:14:30 PM]
Ah! Alrighty. That''ll get me started. Thanks.
"Is that a snow-globe in your fire blanket,or are you just stark naked?" --RavenBlack Surrealism
Even better, use the stencil buffer and you get hardware acceleration! Never tried it though, but I don''t see any problems with that.
I think you may have a bit of a harder time with collision detection. A geometry based collision model that determines which part of the object is visible is probably the best approach...but i''ve never attempted anything like this...
quote:Original post by SoulSpectre
Even better, use the stencil buffer and you get hardware acceleration! Never tried it though, but I don't see any problems with that.


A problem is hat you will have to know whether a piece of land is blown away, not only see it, this way you will have to read the stencil buffer, that's something you want to avoid!

EDIT: you could draw the mask using impact radius sized circles but you will have to do collision detection yourself.

[edited by - Tree Penguin on May 26, 2004 5:24:49 AM]

This topic is closed to new replies.

Advertisement