Commit b0898b0c by BellCodeEditor

auto save

parent c858b545
Showing with 7 additions and 0 deletions
...@@ -14,6 +14,8 @@ background = pygame.image.load('bg.png') ...@@ -14,6 +14,8 @@ background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
food = pygame.image.load('apple.png') food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
setheading='right'
snake_head=right
x,y=240,120 x,y=240,120
#建立一个列表(position)记录蛇的身体、头部(x,y)坐标位置 #建立一个列表(position)记录蛇的身体、头部(x,y)坐标位置
position=[(180,90),(180,120),(210,120),(x,y)] position=[(180,90),(180,120),(210,120),(x,y)]
...@@ -22,6 +24,11 @@ while True: ...@@ -22,6 +24,11 @@ while True:
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
if event.type == locals.KEYDOWN:
if event.key==locals.K_RIGHT and setheading!='left':
setheading='right'
snake_head=right
x+=30
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
x+=30 x+=30
......
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