I'm looking for terrain that gets removed in chunks (like in Worms, of instance). How do you do this in SDL?
-
1\$\begingroup\$ Liquid simulation and deformable terrain are not typically handled the same way. These are two separate questions with two separate answers. \$\endgroup\$– Sean MiddleditchCommented Jul 7, 2013 at 5:26
-
\$\begingroup\$ have you got either? \$\endgroup\$– aboutstairsCommented Jul 7, 2013 at 5:29
-
\$\begingroup\$ The implication is that you should separate this into two separate questions so each can be addressed separately. \$\endgroup\$– ssbCommented Jul 7, 2013 at 5:56
-
\$\begingroup\$ found this link after some googling, might be of use to you: web.archive.org/web/20090101215451/http://blog.xna3.com/2007/12/… \$\endgroup\$– ThatOneGuyCommented Jul 7, 2013 at 6:29
-
2\$\begingroup\$ The graphics, sound and input of such a system are only a very minor part of the system. Check out some of the related questions to learn how you can do this: gamedev.stackexchange.com/questions/6721/… gamedev.stackexchange.com/questions/11840/… gamedev.stackexchange.com/questions/18173/… \$\endgroup\$– HouseCommented Jul 7, 2013 at 12:59
1 Answer
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.