Commit dc9ebd8a by BellCodeEditor

auto save

parent e926014a
Showing with 13 additions and 0 deletions
...@@ -16,12 +16,25 @@ body = pygame.image.load('body.png') ...@@ -16,12 +16,25 @@ body = pygame.image.load('body.png')
#贪吃蛇位置信息(初始:贪吃蛇四段身体四个坐标) #贪吃蛇位置信息(初始:贪吃蛇四段身体四个坐标)
x,y = 240,120 x,y = 240,120
position = [(180, 90),(180, 120),(210, 120),(x,y)] position = [(180, 90),(180, 120),(210, 120),(x,y)]
#不断更新列表:增加新元素,删除索引为0得元素
#实现蛇各个部分得坐标位置得更新,实现小蛇移动得效果
heading = "right"
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:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
elif event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and heading!="left":
heading = "right"
x -= 30
if event.key == locals.K_RIGHT and heading!="left":
heading = "right"
x -= 30
if event.key == locals.K_RIGHT and heading!="left":
heading = "right"
x -= 30
x += 30#向右移动 x += 30#向右移动
position.append((x,y)) position.append((x,y))
position.pop(0) position.pop(0)
......
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