Lazo Lab Sign up

App 6: Make a Game, Snake in Pygame / Build Snake

Lesson 3 of 10

A grid and the snake

Split the screen into 20-pixel cells. The snake is a list of (x, y) cells, head first. Draw a square for each.

Key points

  • CELL = 20
  • snake = [(10, 10), (9, 10), (8, 10)]
  • pygame.draw.rect draws squares
CELL = 20
snake = [(10, 10), (9, 10), (8, 10)]

for x, y in snake:
    pygame.draw.rect(screen, (74, 222, 128), (x * CELL, y * CELL, CELL - 2, CELL - 2))

Your turn

Draw a three-cell snake in the middle of the screen.

Watch a video on thisOpens YouTube search results for “A grid and the snake” in a new tab

Quiz · +10 XP

Why store the snake as a list of cells?

Log in to save progress and earn XP.