Commit 2b153ee8 by BellCodeEditor

save project

parent 9b35335c
Showing with 11 additions and 5 deletions
...@@ -15,14 +15,16 @@ food = pygame.image.load('apple.png') # 食物 苹果 ...@@ -15,14 +15,16 @@ food = pygame.image.load('apple.png') # 食物 苹果
body = pygame.image.load('body.png') # 身体 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') # 头 朝
a = pygame.font.Font('neuropol.ttf',18)
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)]
x1,y1 = 360,300 x1,y1 = 360,300
b = 0
setheading = "right" setheading = "right"
snake_head = right snake_head = right
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:
...@@ -53,10 +55,12 @@ while True: ...@@ -53,10 +55,12 @@ while True:
y += 30 y += 30
position.append((x, y)) position.append((x, y))
if x == x1 and y1 == y: if x == x1 and y1 == y:
b += 99
x1 = random.randint(0,21) * 30 x1 = random.randint(0,21) * 30
y1 = random.randint(0,15) * 30 y1 = random.randint(0,15) * 30
else: else:
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
...@@ -64,9 +68,11 @@ while True: ...@@ -64,9 +68,11 @@ 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])
info = 'Score:' + str(b)
text = a.render(info,True,(0,0,0))
screen.blit(text,(540,10))
# 将果实画上去 # 将果实画上去
screen.blit(food, (x1, y1)) screen.blit(food, (x1, y1))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(10) FPSCLOCK.tick(7)
\ 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