Destructible/deformable terrain help

Hi,

I just want to try to create a very simple demo/tutorial on how to create a game with destructible/deformable terrain like the good old lemmings or worms.

The problem is that I have no idea where to start. Are there any physics involved? I’s like to write a simple level in plain java 2d. I tried to find some examples, but I couldn’t.

Any help?

Thanks

I’d very much like to know that as well! :slight_smile:

If you don’t know what you are doing, its probably not a good idea to do a tutorial about it. A basic prerequisite for teaching is to know your material well.

However that aside, I would answer that question with a question. What data structure would you store “ground” information in?

making something like in worms should be really easy, from the destruction part. Just take a mask texture which resambles the terrain and on each explosion just draw an “empty” circle in this texture.

The more problematic part would be the collision detection, but this would be the same as with any other pixelperfect sprite collision which is used in other 2d games.

If you want it tile based, just created a 2 dimensional array of tiles, each tile will have their co ordinates and texture.

When something collides with the tile have a for loop that checks around the tile to see what tiles to remove.

Hi luisoft,

Bit of a late reply here.

I asked a very similar question a while back, and got some good answers in the following post:

(Come to think of it, I should go back and appreciate a few of the replies, now I know how).

For the lemmings approach, you can use and manipulate an image for the terrain, and hence have pixel-based destructible terrain. Take note of Rorkien’s reply about accessing an image’s byte array directly; it’s more efficient than messing with get/setRGB().

The only physics involved would be checking the terrain around your ‘lemming’ and deciding whether he should be falling & splatting, or climbing. A worms clone is obviously a different story, as you then have to handle projectiles and explosions.

Hope it gives you a bit of a starting point.

nerb.

Hey guys! I’m fairly new here but I code java for a long while now and I know a tip about this… If you learn how to render good quadtrees (the datastructure) you can generate points where you explode stuff. Worms use quadtrees to make those awesome smooth maps and the results are better than using pixel-perfect. Also pixel perfect consume a lot of time to process compared to quadtree operations.

This video ilustrates quad tree usage for 2d terrain with awesome results:

NdHhwXzRfR4

And here an awesome blog post on terrain rendering:
http://chrisbunner.wordpress.com/2011/01/23/terrain-rendering/

Also,
http://chrisbunner.wordpress.com/2011/01/23/deformable-terrain/

I wish I could help you with a tutorial but for that I would have to code the renderer my self and I’m too lazy now. Also I would probably make something ineficient and some godlike coder here would hit me with a bazooka. But if you need help with quad tree’s PM me.

Hi luisoft,

Bit of a late reply here.

I asked a very similar question a while back, and got some good answers in the following post:

(Come to think of it, I should go back and appreciate a few of the replies, now I know how).

For the lemmings approach, you can use and manipulate an image for the terrain, and hence have pixel-based destructible terrain. Take note of Rorkien’s reply about accessing an image’s byte array directly; it’s more efficient than messing with get/setRGB().

The only physics involved would be checking the terrain around your ‘lemming’ and deciding whether he should be falling & splatting, or climbing. A worms clone is obviously a different story, as you then have to handle projectiles and explosions.

Hope it gives you a bit of a starting point.

nerb.

This is neat.

oacZwUGP11c

Hey guys! I’m fairly new here but I code java for a long while now and I know a tip about this… If you learn how to render good quadtrees (the datastructure) you can generate points where you explode stuff. Worms use quadtrees to make those awesome smooth maps and the results are better than using pixel-perfect. Also pixel perfect consume a lot of time to process compared to quadtree operations.

This video ilustrates quad tree usage for 2d terrain with awesome results:

NdHhwXzRfR4

And here an awesome blog post on terrain rendering:
http://chrisbunner.wordpress.com/2011/01/23/terrain-rendering/

Also,
http://chrisbunner.wordpress.com/2011/01/23/deformable-terrain/

I wish I could help you with a tutorial but for that I would have to code the renderer my self and I’m too lazy now. Also I would probably make something ineficient and some godlike coder here would hit me with a bazooka. But if you need help with quad tree’s PM me.

Is that polygon based? Maybe he is generating and averaging points around his mouse, and making the poly from them…
anyway, seems good for collision detection =)

This is neat.

oacZwUGP11c

Is that polygon based? Maybe he is generating and averaging points around his mouse, and making the poly from them…
anyway, seems good for collision detection =)

It uses Chipmunk Pro’s “autogeometry” to generate geometry from images.

It uses Chipmunk Pro’s “autogeometry” to generate geometry from images.