I'm looking for terrain that gets removed in chunks (like in Worms, of instance). How do you do this in SDL?
Asked
Active
Viewed 735 times
-1
-
1Liquid simulation and deformable terrain are not typically handled the same way. These are two separate questions with two separate answers. – Sean Middleditch Jul 07 '13 at 05:26
-
have you got either? – aboutstairs Jul 07 '13 at 05:29
-
The implication is that you should separate this into two separate questions so each can be addressed separately. – ssb Jul 07 '13 at 05:56
-
found this link after some googling, might be of use to you: http://web.archive.org/web/20090101215451/http://blog.xna3.com/2007/12/2d-deformable-level.html – ThatOneGuy Jul 07 '13 at 06:29
-
any idea how to do that in sdl? – aboutstairs Jul 07 '13 at 07:32
-
2The 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: http://gamedev.stackexchange.com/questions/6721/implementing-a-2d-destructible-landscape-like-worms http://gamedev.stackexchange.com/questions/11840/in-an-artillery-game-how-do-i-mask-out-the-part-of-the-terrain-that-was-hit http://gamedev.stackexchange.com/questions/18173/what-are-some-current-techniques-for-rendering-deformable-landscapes – House Jul 07 '13 at 12:59
1 Answers
1
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.

Mario
- 8,442
- 1
- 29
- 34