I'm trying to make a 2d game like Worms (in JS, if it's important). I found 2 possible ways of implementing destructible terrain:
- Bitmap. Store every pixel in a huge 2-dimensional array
- Represent the terrain as a
f(x, y)
function somehow and use the marching squares algorithm with linear interpolation.
But I still don't quite understand how should I calculate worms' movements. When a worm is standing on the ground and is walking in a certain direction, how do I calculate its next position?
I have an idea for how to do it with a bitmap, but I don't think its the best one:
- Before the match find pixels where the worm can stand
- When the worm starts walking find some nearby standable pixels with
standablePixelsX = wormX + direction
, wheredirection = -1 or +1
based on which direction the player is moving (left or right) - And check those selected standable pixels with an
areConnected(pixel1, pixel2)
function which determines whether a worm can move formpixel1
topixel2
(checks for blocking ceilings and stuff)
Which way should I implement destructible terrain and whats the best way to calculate worms' movements?