Commit a443cbbe by BellCodeEditor

save project

parent e7fa40d3
Showing with 16 additions and 0 deletions
...@@ -14,21 +14,37 @@ background = pygame.image.load('bg.png') ...@@ -14,21 +14,37 @@ 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')
left=pygame.image,load("left.png")
up=pygame.image,load("up.png")
down=pygame.image,load("down.png")
x,y=240,120 x,y=240,120
posion=[(180, 90),(180, 120),(210, 120),(x,y)] posion=[(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()
elif event.type==locals.KEYDOWN
if event.key==localsK_RIGHT and setheading !="left":
setheading="right"
if event.key==localsK_LEFT and setheading !="right"
setheading="left"
if event.key==localsK_UP and setheading !="down"
setheading="down"
if event.key==localsK_DOWN and setheading !="up"
setheading="up"
x+=30 x+=30
posion.append((x,y)) posion.append((x,y))
posion.pop() posion.pop()
screen.blit(right,posion[-1]) screen.blit(right,posion[-1])
for i in range(len(posion)-1): for i in range(len(posion)-1):
screen.blit(body,posion[i]) screen.blit(body,posion[i])
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 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