Commit ab6e0fe7 by BellCodeEditor

auto save

parent 51ffb8e9
Showing with 25 additions and 0 deletions
...@@ -15,11 +15,34 @@ food = pygame.image.load('apple.png') ...@@ -15,11 +15,34 @@ food = pygame.image.load('apple.png')
body = pygame.image.load('body.png') body = pygame.image.load('body.png')
x,y = 240,120 x,y = 240,120
oo=[(180,90),(180,120),(210,120),(x,y)] oo=[(180,90),(180,120),(210,120),(x,y)]
setheading = "right"
snake_head = 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()
if event.type == locals.KEYDOWN:
if event.key == locals.KEY_RIGHT and setheading !="right"
setheading='right'
snake_head = right
if event.key == locals.KEY_LEFT and setheading !="left"
setheading='left'
snake_head = left
if event.key == locals.KEY_UP and setheading !="up"
setheading='up'
snake_head = up
if event.key == locals.KEY_DOWN and setheading !="down"
setheading='down'
snake_head = down
if setheading == "right"
x +=30
elif setheading == "left":
x-=30
elif setheading == "up" :
y-=30
else:
y+=30
x+=30 x+=30
oo.append((x,y)) oo.append((x,y))
oo.pop(0) oo.pop(0)
...@@ -35,3 +58,4 @@ while True: ...@@ -35,3 +58,4 @@ while True:
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
qq.tick(3) qq.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