Commit 42b25d3d by BellCodeEditor

auto save

parent 8bd07c2d
Showing with 7 additions and 1 deletions
...@@ -17,6 +17,7 @@ body = pygame.image.load('body.png') # 身体 ...@@ -17,6 +17,7 @@ body = pygame.image.load('body.png') # 身体
left = pygame.image.load('left.png') # 头 朝左 left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上 up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下 down = pygame.image.load('down.png') # 头 朝下
my=pygame.font.Font('neuropol.ttf',20)
apple_x=360 apple_x=360
apple_y=300 apple_y=300
x, y = 240, 120 x, y = 240, 120
...@@ -24,7 +25,7 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)] ...@@ -24,7 +25,7 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading = "right" setheading = "right"
snake_head = right snake_head = right
score=0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -57,15 +58,20 @@ while True: ...@@ -57,15 +58,20 @@ while True:
if x==apple_x and y==apple_y: if x==apple_x and y==apple_y:
apple_x=30*random.randint(0,21) apple_x=30*random.randint(0,21)
apple_y=30*random.randint(0,15) apple_y=30*random.randint(0,15)
score+=1
else: else:
position.pop(0) position.pop(0)
position.append((x, y)) position.append((x, y))
info="Score"+str(score)
a=my.render(info,True,(0,0,0))
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(a,(300,10))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1]) screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body, position[i]) screen.blit(body, position[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