App 6: Make a Game, Snake in Pygame / Build Snake
Lesson 4 of 10
Moving the snake
Each frame, add a new head one cell in the current direction and remove the tail. That's the whole trick to snake movement.
Key points
- direction = (1, 0) means right
- snake.insert(0, new_head)
- snake.pop() removes the tail
direction = (1, 0)
head_x, head_y = snake[0]
new_head = (head_x + direction[0], head_y + direction[1])
snake.insert(0, new_head)
snake.pop()Your turn
Make the snake move right across the screen.
Quiz · +10 XP
How does the snake move forward?
Log in to save progress and earn XP.