Jump to content
  • Advertisement
Sign in to follow this  
noatom

DirectX 2D Destructible terrain?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

Your question is very vague.

 

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!