Commit 70ae0ec5 by BellCodeEditor

save project

parent c5c2f5e0
Showing with 21 additions and 21 deletions
...@@ -18,40 +18,40 @@ down = pygame.image.load('down.png') ...@@ -18,40 +18,40 @@ down = pygame.image.load('down.png')
x,y=240,120 x,y=240,120
pos=[(180, 90),(210, 120),(240, 120),(x,y)] pos=[(180, 90),(210, 120),(240, 120),(x,y)]
setheading='right' 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.type == locals.KEYDOWN:
if event.key==locals.K_RIGHT and setheading!='left': if event.key==locals.K_RIGHT and setheading!='left':
setheading='right' setheading='right'
snake_head=right snake_head=right
if event.key==locals.K_LEFT and setheading!='right': if event.key==locals.K_LEFT and setheading!='right':
setheading='left' setheading='left'
snake_head=left snake_head=left
if event.key==locals.K_LEFT and setheading!='down': if event.key==locals.K_UP setheading!='down':
setheading='up' setheading='up'
snake_head=up snake_head=up
if event.key==locals.K_LEFT and setheading!='up': if event.key==locals.K_DOWNand setheading!='up':
setheading='down' setheading='down'
snake_head=down snake_head=down
x+=30
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(right, (x,y))
# 将贪吃蛇的身体画上去
if setheading=='right': if setheading=='right':
x+=30 x+=30
elif setheading=='left': elif setheading=='left':
x-=30 x-=30
elif setheading=='up': elif setheading=='up':
x-=30 y-=30
else: else:
x+=30 y+=30
pos.append((x,y)) pos.append((x,y))
pos.pop(0) pos.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(snake_head, (x,y))
# 将贪吃蛇的身体画上去
screen.blit(body, pos[1]) screen.blit(body, pos[1])
screen.blit(body, pos[2]) screen.blit(body, pos[2])
screen.blit(body, pos[0]) screen.blit(body, pos[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