From the course: Building the Classic Snake Game with Python

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Snake representation and movement

Snake representation and movement

- In this video, I'm going to give you a conceptual overview of how the snake in our game will be represented and how it will move. If you like, before continuing watching, have a think about how you might begin to implement this yourself. So in our version, we're going to represent the snake as a list of pairs of X, Y coordinates. So you can see here we have a list containing other lists, smaller lists, and each of those inner lists contains an X and a Y coordinate. The segments of the snake are currently lying all horizontally with Y coordinates of zero. Now, for this demonstration, consider the leftmost list item to be the tail and the rightmost to be the head. So here's that representation shown on a grid. So the green squares are the segments of the snake. Now, the first thing we do is you make a copy of the head, and then we update the coordinates of that head to the new location and append it. So now there's five segments. So we need to remove the last segment so the snake…

Contents