Commit 54b9bb77 by BellCodeEditor

save project

parent c19981f3
Showing with 14 additions and 7 deletions
......@@ -22,7 +22,6 @@ x, y = 240, 120
a_x=360
a_y=300
position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading = "right"
snake_head = right
......@@ -44,10 +43,14 @@ while True:
if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down'
snake_head = down
#按键控制蛇移动1
if x==a_x and y==a_y:
a_x=random.randint(0,33)*30
a_y=random.randint(0,16)*30
a_x=random.randint(0,32)*30
a_y=random.randint(0,15)*30
screen.blit(food, (a_x, a_y))
else:
# 苹果被吃后重新出现
if setheading == "right":
......@@ -58,21 +61,24 @@ while True:
y -= 30
else:
y += 30
#按键控制蛇移动
#按键控制蛇移动2
position.append((x, y))
position.pop(0)
# 将蛇头的图画上去
screen.blit(background, (0, 0))
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (a_x, a_y))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
print("game is over")
\ 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