Menu

1 / 2

Pygame Snake, Pt. 4

DEV Community·David Newberry·6 months ago
#uzglCRNW
#beginners#gamedev#python#tutorial#pygame
Reading 0:00
15s threshold

In Parts 1, 2, & 3 we have put together everything, it would seem, besides the actual game. But now we come to the point.

The first set of changes we need to make involve the snake. Instead of a single dot variable, we'll need a snake list . We'll also introduce a variable to allow the snake to grow.

First, modify this line:

dot = pygame . Vector2 ( W / 2 , H / 2 )

Enter fullscreen mode

Exit fullscreen mode

to

snake = [ pygame . Vector2 ( W / 2 , H / 2 )]

Enter fullscreen mode

Exit fullscreen mode

Just above the while loop, introduce the new variable:

grow = 3

Enter fullscreen mode

Exit fullscreen mode

Inside the while loop, we'll make several changes.

A quick conceptual note: Previously, there was a single ("scalar") variable, dot . The animation worked by updating the x and y attributes of dot (via the code dot += vel ).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.