Per-pixel Destructible Terrain

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
Posts: 173
Joined: Thu Feb 11, 2010 9:46 pm

Per-pixel Destructible Terrain

Post by X Abstract X »

I've been working on a project for a little over a month now, it's got a per-pixel destructible environment similar to Worms. I've reached a point where I could use some help trying to solve an issue I'm faced with though.

My method of "destroying" the environment is to simply take circle-shaped chunks of varying size out of it whenever an explosion or other destructible event occurs. I do this by drawing to the environment's image data using Bresenham's Circle filling algorithm. That's working fine but I'm not too sure on what to do with any stray pixels that could result, and end up cluttering up the game; preventing the player from moving when there's only perhaps a single pixel or two of floating impassable terrain left in some area.

I've thought of trying to come up with a modification to the circle filling algorithm to somehow check around the circle for potential stray pixels that would result and if any are found, just increase the radius of the circle a bit to "absorb" the strays. That seems mathematically difficult though. Anyone have any ideas?
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Per-pixel Destructible Terrain

Post by K-Bal »

You could perform an opening operation with a bigger radius: http://en.wikipedia.org/wiki/Opening_(morphology)

Btw, at least in Worms 2, which is what I played a lot 10 years ago, single pixels weren't removed. You were blocked by them and you could stand on them.

Greetings,
Marius
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Per-pixel Destructible Terrain

Post by Falco Girgis »

I'm wondering if the naive and simple approach would actually be cheaper than trying to be all smart and mathy and recalculate the explosion geometry...

You could probably easily get away with bounding some rectangle around each explosion then simply iterating over it removing any stray pixels you find.
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: Per-pixel Destructible Terrain

Post by MadPumpkin »

Try checking out the source code for Open Liero Xtreme here: http://www.openlierox.net/ here's the Git information page they have. http://www.openlierox.net/wiki/index.ph ... e_from_Git I'm not sure how they perform destructible terrain particularly, but I know it's done per pixel, and they use a color map per level to show which terrain can/cannot be destroyed.

EDIT: It is after all a worm clone in of itself!
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Per-pixel Destructible Terrain

Post by MarauderIIC »

I did something similar long ago, but I didn't get too far. I did it with a color map too, actually.

Instead of removing single pixels you could make them able to be passed thru -- if player collides, see if pixel has at least one adjacent collidable pixel?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Per-pixel Destructible Terrain

Post by dandymcgee »

MarauderIIC wrote:I did something similar long ago, but I didn't get too far. I did it with a color map too, actually.

Instead of removing single pixels you could make them able to be passed thru -- if player collides, see if pixel has at least one adjacent collidable pixel?
Well, you might as well remove them during this check. It would certainly be better than running a "RemoveSinglePixels()" check every frame.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply