Commit d9672186 by BellCodeEditor

save project

parent 31674e53
Showing with 11 additions and 5 deletions
...@@ -23,7 +23,13 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)] ...@@ -23,7 +23,13 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading = "right" setheading = "right"
snake_head = right snake_head = right
def xy():
x=random.randint(1,22)
y=random.randint(1,16)
x*=30
y*=30
return x,y
ax,ay=xy()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -52,9 +58,8 @@ while True: ...@@ -52,9 +58,8 @@ while True:
y -= 30 y -= 30
else: else:
y += 30 y += 30
if x==ax and y==ay: if x==ax and y==ay:
ax=random.randint(0,660) ax,ay=xy()
ay=random.randint(0,480)
position.append((x, y)) position.append((x, y))
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -66,7 +71,7 @@ if x==ax and y==ay: ...@@ -66,7 +71,7 @@ if x==ax and y==ay:
screen.blit(body, position[i]) screen.blit(body, position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (ax, ay)) screen.blit(food,(ax,ay))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(3)
\ 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