-1
\$\begingroup\$

I'm looking for terrain that gets removed in chunks (like in Worms, of instance). How do you do this in SDL?

\$\endgroup\$
6

1 Answer 1

1
\$\begingroup\$

Something like this usually utilizes simple texture operations. The basic promise: Use a texture as your map. If there's full alpha, you consider a pixel to be air. If there's not full alpha, you consider a pixel to be ground. Different thresholds can be set to achieve things such as transparency.

If you want solid drawn parts that are translucent or have different properties (like ice) you'll most likely want two textures: One to display, one for game logic. The game logic one could be as simple as an array of bytes, where each byte represents one pixel. You can then use bitwise operations to determine terrain attributes like solid, frozen, bouncy, indestructible, etc.

Overall, the whole thing is rather easy to realize:

  • Check pixels do determine whether they're solid (are visible).
  • For explosions simply draw filled circles of full alpha.
  • For gun shots simply draw lines using full alpha.
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .