Commit 0924f10d by BellCodeEditor

save project

parent e6f2732e
Showing with 5 additions and 14 deletions
...@@ -6,8 +6,8 @@ pygame.init() ...@@ -6,8 +6,8 @@ pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock()
FPSCLOCK=pygame.time.Clock()
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') right = pygame.image.load('right.png')
...@@ -29,23 +29,23 @@ while True: ...@@ -29,23 +29,23 @@ while True:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
exit() exit()
elif event.type==locals.KEYDOWN: if 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_head = right snake_head = right
if event.key==locals.K_LEFT and setheading !="right": if event.key==locals.K_LEFT and setheading !="right":
setheading = 'left' setheading = 'left'
snake_head = left snake_head = left
if event.key==locals.K_DOWN and setheading !="down": if event.key==locals.K_UP and setheading !="down":
setheading = 'up' setheading = 'up'
snake_head = up snake_head = up
if event.key==locals.K_UP and setheading !="up": if event.key==locals.K_DOWN and setheading !="up":
setheading = 'down' setheading = 'down'
snake_head = down snake_head = down
if setheading=="right": if setheading=="right":
x+=30 x+=30
elif setheading=="lift": elif setheading=="left":
x-=30 x-=30
elif setheading=="up": elif setheading=="up":
y-=30 y-=30
...@@ -61,16 +61,7 @@ while True: ...@@ -61,16 +61,7 @@ while True:
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
# 将贪吃蛇画上去
screen.blit(right, position[-1])
for i in range(len(position)-1):
screen.blit(body,position[i])
# 将贪吃蛇的身体画上去
screen.blit(body, (210, 120))
screen.blit(body, (180, 120))
screen.blit(body, (180, 90))
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) 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