Commit 0bbc60a9 by BellCodeEditor

save project

parent a0612cc5
Showing with 14 additions and 15 deletions
...@@ -19,7 +19,7 @@ up = pygame.image.load('up.png') ...@@ -19,7 +19,7 @@ up = pygame.image.load('up.png')
OKCLOCK=pygame.time.Clock() OKCLOCK=pygame.time.Clock()
x,y=240,120 x,y=240,120
yuhotui=[(180,90),(180,120),(210,120),(x,y)] position=[(180,90),(180,120),(210,120),(x,y)]
setheading = "up" setheading = "up"
snake_haed = up snake_haed = up
...@@ -30,22 +30,22 @@ while True: ...@@ -30,22 +30,22 @@ while True:
exit() exit()
elif event.type==locals.KEYDOWN: elif 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_haed=right snake_haed=right
if event.key==locals.K_UP and setheading!="down": if event.key==locals.K_UP and setheading != "down":
setheading="up" setheading="up"
snake_haed=up snake_haed=up
if event.key==locals.K_LEFT and setheading!="right": if event.key==locals.K_LEFT and setheading != "right":
setheading="left" setheading="left"
snake_haed=left snake_haed=left
if event.key==locals.K_DOWN and setheading!="up": if event.key==locals.K_DOWN and setheading != "up":
setheading="down" setheading="down"
snake_haed=down snake_haed=down
if event.key==locals.K_SPACE: # if event.key==locals.K_SPACE:
OKCLOCK.tick(100) # OKCLOCK.tick(100)
else: # else:
OKCLOCK.tick(3) # OKCLOCK.tick(3)
if setheading == "right": if setheading == "right":
x+=30 x+=30
elif setheading=="left": elif setheading=="left":
...@@ -62,18 +62,16 @@ while True: ...@@ -62,18 +62,16 @@ while True:
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
screen.blit(right, (x, y)) screen.blit(snake_haed, (x, y))
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
# screen.blit(body, (210, 120)) # screen.blit(body, (210, 120))
# screen.blit(body, (180, 120)) # screen.blit(body, (180, 120))
# screen.blit(body, (180, 90)) # screen.blit(body, (180, 90))
for i in range(len(yuhotui)-1): for i in range(len(position)-1):
screen.blit(body,yuhotui[i]) screen.blit(body,position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
x+=30 OKCLOCK.tick(3)
yuhotui.append((x,y))
yuhotui.pop(0)
\ No newline at end of file
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