# Implementing growth in Snake?

I’m new at this, so I thought I’d start simple. Snake. I started with pygame, just looking some things up, and I’ve now got movement, random fruit generation, and a score counter.

``````pygame.init()

size = width, height = (800, 440)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('snake from scratch')

clock = pygame.time.Clock()

notBlack = (40,50,50)
white = (255,255,255)
red = (255,0,0)
blue = (0,0,255)
green = (0,255,0)

w = 20, 760

x1 = 400
y1 = 220
x1Velocity = 0
y1Velocity = 0
x2 = 0
y2 = 0

player = pygame.Rect(x1, y1, 20, 20)
fruit = pygame.Rect(x2, y2, 20, 20)
fruitOnScreen = False
score = 0

def roundTo(x, base):
return base * round(x/base) #rounds to whatever you put as base

def offScreen(x, y):
while x >= 760 or y >= 400:
if x > 760:
x -= 5
if y > 400:
y -= 5
if x < 770 and y < 405:
break
return x, y #forces x and y pos back on screen

running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
if event.key == pygame.K_LEFT:
x1Velocity = -20
y1Velocity = 0
if event.key == pygame.K_RIGHT:
x1Velocity = 20
y1Velocity = 0
if event.key == pygame.K_UP:
x1Velocity = 0
y1Velocity = -20
if event.key == pygame.K_DOWN:
x1Velocity = 0
y1Velocity = 20

x1 += x1Velocity
y1 += y1Velocity

player = pygame.Rect(x1, y1, 20, 20)
fruit = pygame.Rect(x2, y2, 20, 20)
collide = player.colliderect(fruit)

if not fruitOnScreen:
x2 = random.randrange(20, 760)
y2 = random.randrange(20, 400)
x2 = roundTo(x2, 20)
y2 = roundTo(y2, 20)
x2, y2 = offScreen(x2, y2)
fruitOnScreen = True #Generates random coords for fruit
elif collide:
score += 1
fruitOnScreen = False
print(score)

screen.fill(white)

pygame.draw.rect(screen, red, (x2, y2, 20, 20))
pygame.draw.rect(screen, blue, (x1, y1, 20, 20))
pygame.draw.rect(screen, notBlack, (0, 0, 800, 440), 40) #Draws a 20pixel thick border
pygame.display.update()
clock.tick(8)

pygame.quit()
quit()
``````

I think this is pretty good for not having much of any experience, but now I’m stuck. I want to have the body get longer, but I don’t know where to even start. Just looking at it, is it even possible to implement it using what I’ve already got?