I made a snake clone part 2

2018-05-23

In my last post I wrote about the snake clone I have written.

With some feedback I got from a couple of friends I added some features to make the game more interesting.

First of all every 10 points the game spawns a stone on the field. The stone is an other obstacle which the snake is not allowed to run into. If you do, you lose a life. The stones are only generated on positions where there is no food or the snake and are at least 4 blocks away from the head of the snake. (Pythagorean theorem fuck yeah!)

The second adjustment I made is to increase the games speed over time. I initially wanted to change the game speed whenever some food is eaten. But since coding, testing and thinking about what you are actually doing hasn't worked out I changed the game speed every step the game does. After a couple of games I realized what I had done and I like the mechanic because it rewards a more aggressive playstyle which collects the food in a faster fashion than allways taking a nice way which gets your snake out of the way and keeps the field open. Especially with a formula like

timestep = timestep * 0.97

the game got pretty fast pretty fast. At ~30 points the game was to fast to be played by a human. Other values like 0.995 moved that point further away but were not really motivating because the game still got insanly fast. So I had to limit the speed of the game to some level that is still playable but not demotivating. I came up with

timestep = basestep * (0.5 + e**(-0.01*step)/2)

basestep is the starting speed of the snake. By default this 333ms. step is the amount of steps the game has done so far. This is basically how often your snake has moved yet. e**(-0.01*step)/2 decreases from 0.5 to 0 for large step counts. Together with the 0.5 this results in a timestep that decreases from basestep to 0.5*basestep. For example after 500 steps the total speed is at ~0.506*basestep or about twice as fast as at the beginning.

Also the game can now be played here.