Commit bb76e838 by BellCodeEditor

save project

parent cf24c066
Showing with 9 additions and 2 deletions
...@@ -9,6 +9,8 @@ screen = pygame.display.set_mode((660, 480)) ...@@ -9,6 +9,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') # 食物 苹果
...@@ -55,8 +57,9 @@ while True: ...@@ -55,8 +57,9 @@ while True:
y += 30 y += 30
position.append((x, y)) position.append((x, y))
if x==apple_x and y==apple_y: if x==apple_x and y==apple_y:
a=random.randint(0,22) score+=1
b=random.randint(0,16) a=random.randint(1,22)
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
else: else:
...@@ -71,6 +74,9 @@ while True: ...@@ -71,6 +74,9 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
info="Score:"+str(score)
text=my_font.render(info,True,(9,9,9))
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