Skip to main content

Moving the Snake

To move the snake, you have to change the X and Y position of every body-part of the snake.

For this, you can start at the end of the body and give this part the values of the part ahead. Since the final piece to get its values "stolen" is the head, the head seems to disappear for very brief moment.

After this is done, you simply move the head in the direction of the snake. Since all of this happens, before the snake is rendered, it appears as a fluid motion.

This is how the logic looks like:

Keep in mind: This is not what the player sees. This is:

Moving the Body#

// TODO

Moving the Head#

// TODO

That's it. Now you should see the snake running from left to right. Maybe a little too fast, though.

Moving Snake (fast)

Slowing Down#

By default WASM-4 runs at 60 FPS. This means your little snake moves 60 fields in each second. That is 3 times the whole screen. There are several ways to slow the snake down.

The easiest way is probably to count the frames and update the snake only every X frames.

// TODO