import pygame
import random
def show_text(text, pos, size, screen):
f = pygame.font.Font("庞门正道粗书体.ttf", size)
t = f.render(text, True, [0, 0, 0])
screen.blit(t, pos)
def game():
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("game")
running = True
circle_x = random.randint(50, 750)
circle_y = 0
rect_x = 310
rect_y = 560
ms = 3
fs = 0
speed = 3
while running == True:
screen.fill([105, 165, 184])
if ms > 0:
pygame.draw.circle(screen, [200, 200, 200], [circle_x, circle_y], 50, 0)
pygame.draw.rect(screen, [0, 0, 0], [rect_x, rect_y, 150, 40], 0)
show_text("命数:" + str(ms), (2, 2), 34, screen)
show_text("分数:" + str(fs), (650, 2), 34, screen)
circle_y = circle_y + speed
pygame.display.update()
if circle_y > 575:
circle_y = 0
circle_x = random.randint(50, 750)
ms = ms - 1
if 0 <= rect_y - circle_y <= 50 and rect_x - 50 <= circle_x <= rect_x + 200:
circle_y = 0
circle_x = random.randint(50, 750)
fs = fs + 1
if fs % 20 == 0:
speed = speed + 1
else:
show_text("GAME OVER", (3, 120), 180, screen)
show_text("获得分数" + str(fs), (310, 300), 50, screen)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEMOTION:
rect_x, rect_y = event.pos
rect_y = 560
game()