# DirectX 2D Destructible terrain?

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

## Recommended Posts

So,how should I implement destructible terrain? I tried finding something on google,but no code!

##### Share on other sites

It all depends on the kind of 2D terrain you are trying to implement which is very dependant on the kind of scenario/game you are making. Please give us more info.

On the side though there are quite a few ways to implement this and it depends on how you choose to represent your terrain:

For example if you choose to have terrain as a series of triangles in 2D marking solid regions then it is possible to carve chunks out of a triangle by breaking the large triangle up into smaller ones. This method can also be used in conjunction with some physics to allow for things to fall over like if you destroyed a support.

In general though this is a very difficult thing to simulate, especially with physics.

##### Share on other sites

Well,what I had in mind was the same terrain Worms uses.

##### Share on other sites

If I were to write this I would use a 2D grid where each cell would correspond to a pixel and a 2D texture which would be the terrain drawn to the screen. The grid would be a simple 2D array of boolean values, true if the cell is solid and false if empty. This grid would be used for any hit detection to stop players falling through. The texture would be the visible terrain drawn to the screen. It would be initialized with the shape of the terrain you want to start out with. Now whenever you want to remove a chunk of ground, say a circle, you simply set all cells in the grid that fall in the radius of the circle to false and clear all texels in the terrain texture under the circle to a transparent color, say (0, 0, 0, 0).

When you want to render the terrain you simply draw the terrain texture over your background. You might even want to draw the terrain over almost everything including players to stop them appearing *in* the ground.

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

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

• Total Topics
633743
• Total Posts
3013645
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!