Commit a5a876bd by BellCodeEditor

save project

parent 49f33337
Showing with 8 additions and 3 deletions
...@@ -7,7 +7,7 @@ pygame.init() ...@@ -7,7 +7,7 @@ pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
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') # 头 朝右
...@@ -23,7 +23,7 @@ apple_x=300 ...@@ -23,7 +23,7 @@ apple_x=300
apple_y=360 apple_y=360
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:
...@@ -58,7 +58,9 @@ while True: ...@@ -58,7 +58,9 @@ while True:
apple_x=random.randrange(0,300,30) apple_x=random.randrange(0,300,30)
apple_y=random.randrange(0,300,30) apple_y=random.randrange(0,300,30)
position.pop(0) score+=1
else:
position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
...@@ -70,6 +72,8 @@ while True: ...@@ -70,6 +72,8 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
text=font.render("score:"+str(score),True,(0,0,0))
screen.blit(text,(540,20))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(5) FPSCLOCK.tick(5)
\ 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