Commit 29c4a5a7 by BellCodeEditor

save project

parent 6948f397
Showing with 22 additions and 23 deletions
......@@ -16,46 +16,45 @@ up = pygame.image.load('up.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
head="right"
setheading=right
x,y=240,120
screen.blit(right, (x, y))
LEN=[(180, 90),(180, 120),(240, 120),(x,y)]
while True:
LEN.append((x,y))
LEN.pop(0)
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type==locals.KEYDOWN:
# if event==K_RIGHT and setheading!=left:
# setheading=right
# if event==K_DOWN and setheading!=up:
# setheading=down
# if event==K_LEFT and setheading!=right:
# setheading=left
# if event==K_UP and setheading!=down:
# setheading=up
if event.type == locals.KEYDOWN:
if event.key==locals.K_RIGHT and head!="left":
head="right"
setheading=right
if event.key==locals.K_DOWN and head!="up":
head="down"
setheading=down
if event.key==locals.K_LEFT and head!="right":
head="left"
setheading=left
if event.key==locals.K_UP and head!="down":
head="up"
setheading=up
if setheading==right:
screen.blit(right, (x, y))
if head=="right":
x+=30
if setheading==down:
screen.blit(down, (x, y))
if head=="down":
y+=30
if setheading==left:
screen.blit(left, (x, y))
if head=="left":
x-=30
if setheading==up:
screen.blit(up, (x, y))
if head=="up":
y-=30
LEN.append((x,y))
LEN.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
# screen.blit(right, (x, y))
screen.blit(setheading, (x, y))
# 将贪吃蛇的身体画上去
for i in range(len(LEN)-1):
screen.blit(body,LEN[i])
......
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