After I made "Snake", I took it to work the next day to show my coworkers. They all seemed interested, asking questions and looking at the code. Then, one issued an interesting challenge: “Dude, you should make ‘worm’”. The idea was an interesting incremental change. Rather than occupying discrete blocks within a grid like the snake, the worm position values would be continuous.
I was intrigued and pumped out the change that night.
Working with a grid made things really easy for “snake”. But it was a little more complicated for “worm”.
I decided to try and map over some of the high-level ideas. I rendered the snake as a series of circles rather than boxes. That worked, but it looked more like a bug of some sort rather than a worm. But if I rendered the circles more closely together, it would look more like worm-y. If the head circle overlaps any of the “body” circles, then the worm has eaten itself. However, this check starts a number of circles down the list since the circles are so tightly packed.
For the movement, rather than picking a direction and filling in the next box, I had to transition between directions. That is, if you were heading east, and you press “up”, rather than instantly turn north, it smoothly slithers toward the target direction. It stops once you either reach the direction or you release the button.
The source is available on GitLab.