Commit 58fdfeee by BellCodeEditor

save project

parent 72ad2941
Showing with 12 additions and 8 deletions
...@@ -4,11 +4,9 @@ from pygame import locals ...@@ -4,11 +4,9 @@ from pygame import locals
pygame.init() pygame.init()
fps=pygame.time.Clock() fps=pygame.time.Clock()
x,y=240,120 x,y=240,120
apple_x=360
apple_y=300
p=[(180,90),(180,120),(210,120),(x,y)] p=[(180,90),(180,120),(210,120),(x,y)]
if x==apple_x and y==apple_y:
apple_x=360
apple_y=300
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
...@@ -44,11 +42,17 @@ while True: ...@@ -44,11 +42,17 @@ while True:
y-=30 y-=30
elif setheading =="down": elif setheading =="down":
y+=30 y+=30
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
p.append((x,y)) p.append((x,y))
p.pop(0)
if x==apple_x and y==apple_y:
num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=30*num1-30
apple_y=30*num2-30
else:
p.pop(0)
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(snake_head, (x,y)) screen.blit(snake_head, (x,y))
for i in range(len(p)-1): for i in range(len(p)-1):
......
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