I've been playing a lot of Worms lately over it’s 25th anniversary. I found myself wondering how it creates the game levels. There are some good tutorials on the internet describing how to build Worm like procedural levels. I just can't believe these algorithms were fast enough back in the Amiga era. I need to get a copy or Worms for my A1200 and see how it runs. Anyway, here is my attempt at some procedural geometry and Worms like destruction.
The terrain turned out to be super simple. I create a list of 2D game objects. Each list will have a random length, giving us our height. I then place these lists side by side across the X axis and fill them with sprites, the last sprite being the grass texture. The only issue here is that the result is very jaggy as the lengths are totally random. We can fix this by checking the height of each adjacent column and averaging out the heights creating a smoother adjustment in the list height.
Creating Worms like collisions were craters are left in the ground also turned out to be quite easy. I tried a number of different routes. At first I used Unity's tile map package which worked fine but it felt a little over engineered. This was more to do with the Tilemap API getting in the way when searching for our colliding tiles. It can most likely be done quite elegantly but i didn't have the time to look into it. The tile map excels best when it’s used as a design tool, hand grafting game levels.
In the end I used a sphere collier attached to my projectiles. When a projectile hits the ground I check what objects are inside the sphere then it’s just a case of removing those items giving us a nice crater. As a quick bit of polish I added a particle effect that spawns a coloured particle on our objects being destroyed, helping to sell the effect.
This example is very basic. I've not really scratched the surface of how Worms builds it’s levels. I hope I can get time to come back to this project and fix it up into a full level. There is plenty more to explore.