Game design decisions
Certain versions of snake run differently; however, for the sake of paying homage to the classical approach, we will be implementing a snake that moves based on a grid, as illustrated next:
Taking this approach makes it easier to later check for collision between the snake segments and the apple. Grid movement basically means updating at a static rate. This can be achieved by utilizing a fixed time-step, which we covered back in Chapter 2, Give It Some Structure – Building the Game Framework.
The outside area symbolizes the boundaries of the game, which in the case of a grid-based movement would be in the range of [1;Width-1] and [1;Height-1]. If the snake head isn't within that range, it's safe to say that the player has crashed into a wall. All the grid segments here are 16px by 16px big; however, that can be adjusted at any time.
Unless the player runs out of lives, we want to cut the snake at the point of intersection if its head collides with its...