Commit 34d6fba0 by BellCodeEditor

save project

parent c59c777c
Showing with 17 additions and 2 deletions
...@@ -5,6 +5,8 @@ x,y=210,120 ...@@ -5,6 +5,8 @@ x,y=210,120
pygame.init() pygame.init()
position=[(180,90),(180,120),(210,120),(x,y)] position=[(180,90),(180,120),(210,120),(x,y)]
# 创建一个窗口 # 创建一个窗口
apple_x=360
apple_y=300
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
# 背景 # 背景
...@@ -18,7 +20,19 @@ while True: ...@@ -18,7 +20,19 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
x=x+30
if setheading =="left":
x-=30
elif setheaing== "right":
x+=30
elif setheading== "up" :
y-=30
else:
y+=30
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
position.append((x,y)) position.append((x,y))
position.pop(0) position.pop(0)
...@@ -30,7 +44,7 @@ while True: ...@@ -30,7 +44,7 @@ while True:
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (apple_x,apple_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
hyfhsihfu.tick(3) hyfhsihfu.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