Hey, I'm trying to make a snake game with free movement. I've got the head of the snake moving about perfectly, but I'm having trouble with the math to make all the other parts follow behind. There is no grid, so that's out! So far all I have is a second piece starting with the head, then it flies off the screen, whoops. I'm using allegro 5 to generate the graphics of the game if you want to try it out, but I really just need some math help. Thanks!
I didn't really look at the code, but my first thought would be to have a movement queue, maybe coupled with some timestamps.
Basically, you would log the direction the head moved along with the time of the movement into a big list. The rest of the snake segments would walk through that list performing the same step, but each segment would delay the timestamp a bit more.
Once the tail performs the step, it can be removed from the queue.
Let me get this straight, there will be a queue with a location far enough back for even the 300th piece. With each piece that's added the queue gets longer, but once the tail moves along it dequeues. But there needs to be a delay in between each or else they'll be on top of each other. O.K. I think it'll work! I hope the queue doesn't slow down the program too much.