1 min
By checking for intent to change direction each update the class can store the next planned move for the snake. So by updating each tick for movement by a few pixels each time (divisible by the tile size) the snake can check for a change in direction when the next tile is lined up.
Problems in this system relies on the inconsistencies of update and tick, by spamming input it is possible to change direction multiple times before the next tick is called. To solve this it’s as simple as either moving the snake in the direction after it has changed, or having a bool to only take one change of direction per tile.
Subscribe to this blog via RSS.
Blog 17
Snake 4
Birdman 2
Blog (17) Low-level programming (17) Snake (4) Endless runner (2) Birdman (2) Chess-com (6)