Commit c341b5c9 by BellCodeEditor

save project

parent bf250627
Showing with 6 additions and 3 deletions
...@@ -12,11 +12,12 @@ left = pygame.image.load('left.png') ...@@ -12,11 +12,12 @@ left = pygame.image.load('left.png')
up = pygame.image.load('up.png') up = pygame.image.load('up.png')
down = pygame.image.load('down.png') down = pygame.image.load('down.png')
x, y = 240, 120 x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)] position = [(180,90),(180,120),(210,120),(x, y)]
setheading = "right" setheading = "right"
snake_head = right snake_head = right
apple_x = randint(0,630) apple_x = randint(0,630)
apple_y = randint(0,430) apple_y = randint(0,430)
changdu=4
while apple_x%30!=0 or apple_y%30!=0: while apple_x%30!=0 or apple_y%30!=0:
apple_x = randint(0,630) apple_x = randint(0,630)
apple_y = randint(0,430) apple_y = randint(0,430)
...@@ -46,12 +47,14 @@ while True: ...@@ -46,12 +47,14 @@ while True:
else: else:
y += 30 y += 30
if x==apple_x and y==apple_y: if x==apple_x and y==apple_y:
changdu+=1
apple_x = randint(0,630) apple_x = randint(0,630)
apple_y = randint(0,430) apple_y = randint(0,430)
while apple_x%30!=0 or apple_y%30!=0: while apple_x%30!=0 or apple_y%30!=0:
apple_x = randint(0,630) apple_x = randint(0,630)
apple_y = randint(0,430) apple_y = randint(0,430)
position.append((x, y)) position.append((x, y))
if not changdu>=len(position):
position.pop(0) position.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(snake_head, position[-1]) screen.blit(snake_head, position[-1])
...@@ -59,4 +62,4 @@ while True: ...@@ -59,4 +62,4 @@ while True:
screen.blit(body, position[i]) screen.blit(body, position[i])
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(14)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment