Pixel based 2d destructible terrain?

Hi :),

First off, I should say thankyou! Over the years I have often browsed JGO for answers to my questions or to fill in time, albeit have never signed up until now.

I’m toying with the idea of creating a lemmings-esque game, with pixel based destructible terrain. I’ve had a good googling and have some idea about how I will accomplish this. However I’d like to run my thoughts past the JGO community to see if I am on the right track, or if there is a better way.

Essentially I will use a foreground image that forms the terrain (plus a background image). This would likely be accompanied by a byte array holding destructability & collision information for each pixel.

Should pixels be destroyed (by explosions, digging etc.), then I will set the alpha byte of each affected pixel to 0x00 using BufferedImage.setRGB(), followed by updating the byte array, and then render the images.

Does this sound reasonable and efficient? Or would you guys go about this differently?

Thanks very much,
nerb.

That way works, but is really slow, remember you also have to check collisions with the terrain.
Best way is to use an quad tree like this:

The approach to directly detect collisions and alter terrain on an (Image)array
was used in the original Lemmings on the Amiga.
Thus the method should not slow down a modern PC that much.

It depends more on the resolution of your terrain (how many pixels is 1 lemming?)
if you need an optimization like a quad-tree.

Quad tree is food for thought. At this stage I’m thinking of sticking to low-res maps. Although I guess there would be lots of contiguous empty areas or flat platforms. Using quadtree may reduce the need to inspect 60 or so pixels per ‘lemming’ per update. Although as you mentioned Damocles, it shouldn’t take a big toll on modern hardware. Nonetheless, I intend to design it to run as lean as possible.

Cheers.

I think that getting the pixel-array and editing it would be easier and faster than using setRGB

And this might be some help: http://www.mojang.com/notch/j4k2k6/miners4k/

A quadtree(or octree for that matter) is not that hard to make.

http://rel.phatcode.net/mytutes/octreetute/octree_tute.zip

However, for a lemmings game with less than 20 units, a pixel perfect detection would not hurt your FPS. I know of a Lerio-like game that runs full speed on the 66 mhz NDS. So don’t do premature optimizations until you get a hit on your FPS.

Cheers all.

That link is absolute gold Rorkien, thanks very much. Had to do some further reading on the pixel-array approach, but definitely sounds like the way to go. Calls to get/setRGB() appear to be relatively expensive. (This is new to me, I’m learning as I go!).

nerb.