Commit 0b0fe745 by BellCodeEditor

auto save

parent 087f679a
Showing with 13 additions and 4 deletions
...@@ -18,6 +18,9 @@ left = pygame.image.load('left.png') # 头 朝左 ...@@ -18,6 +18,9 @@ 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') # 头 朝下
font = pygame.font.Font('neuropol.ttf', 20)
score = 0
x, y = 240, 120 x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)] position = [(180, 90), (180, 120), (210, 120), (x, y)]
...@@ -56,11 +59,17 @@ while True: ...@@ -56,11 +59,17 @@ while True:
y += 30 y += 30
if x == apple_x and y == apple_y: if x == apple_x and y == apple_y:
apple_x,apple_y = r.randint(0,630), r.randint(0,450) apple_x,apple_y = r.randint(1,22) * 30 - 30, r.randint(1,16) * 30 - 30
score += 10
else:
position.pop(0)
position.append((x, y)) position.append((x, y))
position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
txt = '分数:'+str(score)
info = font.render(txt,True,(127,127,127))
screen.blit(info, (510, 10))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1]) screen.blit(snake_head, position[-1])
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
...@@ -69,4 +78,4 @@ while True: ...@@ -69,4 +78,4 @@ while True:
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(5)
\ No newline at end of file \ 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