Commit d7c2c8c7 by BellCodeEditor

save project

parent 640d8c56
Showing with 21 additions and 8 deletions
......@@ -15,15 +15,33 @@ food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
x,y=240,120
kkkkk=[(180, 90),(180, 120),(210, 12),(x,y)]
b="right"
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.key== locals.K_RIGHT and b !="left":
b="right"
if event.key== locals.K_RIGHT and b !="right":
b="left"
if event.key== locals.K_RIGHT and b !="up":
b="down"
if event.key== locals.K_RIGHT and b !="down":
b="up"
if b=="right":
x+=30
elif b=="left":
x-=30
elif b=="up":
y-=30
else:
y+=30
x+=30
kkkkk.append((x,y)
kkkkk.append((x,y))
kkkkk.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
......@@ -31,12 +49,7 @@ while True:
screen.blit(right, kkkkk[-1])
# 将贪吃蛇的身体画上去
for i in range(len(kkkkk)-1):
screen.blit(body, (210, 120))
screen.blit(body, (210, 120))
screen.blit(body, (180, 120))
screen.blit(body, (180, 90))
screen.blit(body,kkkkk[i])
# 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面
......
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