Commit c94f94a9 by BellCodeEditor

save project

parent b4da62d0
Showing with 8 additions and 18 deletions
File added
...@@ -8,6 +8,7 @@ pygame.init() ...@@ -8,6 +8,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时钟,控制游戏速度(帧数)
text = pygame.font.Font("Mojangles.ttf",18)
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
...@@ -25,6 +26,7 @@ apple_x , apple_y = 360 , 330 ...@@ -25,6 +26,7 @@ apple_x , apple_y = 360 , 330
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():
...@@ -57,8 +59,9 @@ while True: ...@@ -57,8 +59,9 @@ while True:
position.append((x, y)) position.append((x, y))
#贪吃蛇被吃了 #贪吃蛇被吃了
if x == apple_x and y == apple_y: if x == apple_x and y == apple_y:
apple_x = random.randint(0,22) * 30 - 30 apple_x = random.randint(1,22) * 30 - 30
apple_y = random.randint(0,16) * 30 - 30 apple_y = random.randint(1,16) * 30 - 30
score += 10
else: else:
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -70,22 +73,8 @@ while True: ...@@ -70,22 +73,8 @@ while True:
screen.blit(body, position[i]) screen.blit(body, position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y screen.blit(food, (apple_x, apple_y))
screen.blit(text.render("Score:" + str(score),True,(0,0,0)),(540,10))
))
# 刷新画面 # 刷新画面
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