Commit ab6e0fe7 by BellCodeEditor

auto save

parent 51ffb8e9
Showing with 27 additions and 3 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)
...@@ -29,9 +52,10 @@ while True: ...@@ -29,9 +52,10 @@ while True:
screen.blit(right, (x, y)) screen.blit(right, (x, y))
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range (len(oo)-1): for i in range (len(oo)-1):
screen.blit(body,oo[i]) screen.blit(body,oo[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
qq.tick(3) qq.tick(3)
\ No newline at end of file
\ 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