How to implement a Worms style destructible terrain in XNA?

∥☆過路亽.° 提交于 2019-12-02 15:56:31

There's some nice code at the bottom of the this thread. Also, this is a great step-by-step tutorial on achieving a destructible terrain.

EDIT - The original link for the second tutorial was broken, so I've linked to an archived version of it.

Riemer has a similar approach to a game he developed in XNA, cannon shells cause the terrain to be "destroyed" and any props that were previously on said terrain are moved accordingly.

It needs to be refactored and improved for your needs but it's a start.

Riemer has a good selection of tutorials for other things too.

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Adding_craters.php

There are two possibilties, eighter one work, but it depends on XNA how easy it is to implement:

  • Like others suggested, bitmap masking. You keep a bitmap of all "ground" pixels and all "air" pixels. If you have gravity; a character can't fall through ground, while it can fall through air.
  • Vector geometry. You start with a rectangular "ground", and hold a list of "removed" ground, which creates air. This geometry is very simple to edit: just append a circle or similar to the list, and update the graphics. I don't know whether XNA has vector & shape abilities; but it should be easy to create geometry with these two things, and later apply a texture or similar. Also, this can be easy to optimize, by keeping a cached version of the rendered landscape, and only update the cache of the bounding-box of the newly added "air". This solution requires a bit more math though.

Here are two examples that build on each other of how to do this with pixel shaders in XNA 4. Both examples include sourecode.

http://www.syntaxwarriors.com/2012/xna-alpha-mapping-with-pixel-shaders/

http://www.syntaxwarriors.com/2012/xna-alpha-mapping-with-pixel-shader-and-rendertarget2d/

Doing this with pixel shaders is very fast as all the heavy lifting is done on the gpu.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!