#### Archived

This topic is now archived and is closed to further replies.

# Eating away at 2d-terrain?

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

## Recommended Posts

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]

##### Share on other sites
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]

##### Share on other sites
How do you take out pixels?

##### Share on other sites
pbuffer[x][y] = 0 probably...

##### Share on other sites
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]

##### Share on other sites
Ah! Alrighty. That''ll get me started. Thanks.

##### Share on other sites
Even better, use the stencil buffer and you get hardware acceleration! Never tried it though, but I don''t see any problems with that.

##### Share on other sites
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...

##### Share on other sites
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]

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631415
• Total Posts
2999964
×