2D Destructable Terrain / Lemmings / Worms... The easiest way?

I have done some research but I’m having a difficult time understanding

What would be the simplest way to make a sprite/object ‘rub out’ the terrain. I’m guessing from research you would use alpha channels?

For example,

One sprite player controlled with WSAD
Simple bitmap as the terrain that the player walks along with collision
Background with stars/sun/moon or whatever

The player walks/runs along the terrain and decides to dig like lemmings by pressing the mouse on them, or the worm walks along and you press it for the blowtorch

How would you put this into code?

manipulate pixels for terrain and set pixel rgb to what ever when blowtorch is near pixels

And I’m guessing this would be using pixel data for collision? So when the player hits the terrain in some form, you’d use a method like ‘getPixelData()’ which would return the current pixels, then use something like ‘deletePixels()’ ?

yeah probs!

Another way to look at is as a large 2D boolean array: true means there’s ground there, false means it’s empty space. This is how a lot of games work (think about Mario’s blocks), you just have to have very fine resolution (each grid in the array is a pixel).

When an you want to “rub out” some terrain, you simply figure out where in the array to destroy, and set all of those booleans to false.

This isn’t different from what VIrtueel is suggesting- I’m just pointing out that you don’t need to use an image or pixel values, just a grid data structure of some kind.

You could expand this approach to use an array of enums instead of booleans, if you wanted to support different types of terrain.

here is something cool

NdHhwXzRfR4

Thanks peeps

@ VIrtueeL : would the quads here be simular to working with:

public static void DrawQuad(float x, float y, float width, float height) {
		glBegin(GL_QUADS);
		glVertex2f(x, y); // top left corner
		glVertex2f(x + width, y); // top right corner
		glVertex2f(x + width, y + height); // bottom right corner
		glVertex2f(x, y + height); // bottom left
		glEnd();
	}

?? obviously manipulating them?

try your way to it, and you will learn alot along the way

give that one a try =D

Good point, this is where I think I fail a lot sometimes. Programming is very fun for me but seem to be doing more theory than practice and most of the time it doesn’t get you any better IMO

I’ll give it a shot :slight_smile:

tell me if you want to try it out with me i can code in java2D =D