Commit 456b7629 by BellCodeEditor

save project

parent b280b707
Showing with 8 additions and 0 deletions
...@@ -10,6 +10,8 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -10,6 +10,8 @@ screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景 # 背景
score=0
my_font=pygame.font.Font("neuropol.ttf",18)
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') # 头 朝右 right = pygame.image.load('right.png') # 头 朝右
food = pygame.image.load('apple.png') # 食物 苹果 food = pygame.image.load('apple.png') # 食物 苹果
...@@ -44,6 +46,7 @@ while True: ...@@ -44,6 +46,7 @@ while True:
setheading = 'down' setheading = 'down'
snake_head = down snake_head = down
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
x += 30 x += 30
...@@ -59,6 +62,7 @@ while True: ...@@ -59,6 +62,7 @@ while True:
b=random.randint(1,16) b=random.randint(1,16)
apple_x=a*30-30 apple_x=a*30-30
apple_y=b*30-30 apple_y=b*30-30
score+=1
else: else:
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -71,6 +75,9 @@ while True: ...@@ -71,6 +75,9 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x,apple_y)) screen.blit(food, (apple_x,apple_y))
into="score"+str(score)
text=my_font.render(into,True,(0,0,0))
screen.blit(text,(540,10))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(3)
\ 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