Commit 29c4a5a7 by BellCodeEditor

save project

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