import pygame
import random
pygame.init()
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
done = False
equations = ['2 + 2', '3 + 1', '4 + 4', '7 - 4']
font = pygame.font.SysFont("comicsansms", 72)
tks = pygame.time.get_ticks()
cloud1 = pygame.image.load('cloud.png')
cloud1_X, cloud1_Y = 100, 50
cloud1_Y_change = 0
def cloud1_display(x, y):
screen.blit(cloud1, (x, y))
def display_equation():
text = font.render(random.choice(list(equations)), True, (0, 128, 0))
screen.blit(text, (320 - text.get_width() // 2, 240 - text.get_height() // 2))
rocket_up = False
eq_done = False
while not done:
screen.fill((102, 178, 255))
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
done = True
tks = pygame.time.get_ticks()
if tks > 5000 and not eq_done:
display_equation()
eq_done = True # only render once
cloud1_display(cloud1_X, cloud1_Y)
pygame.display.update()
clock.tick(60)
您需要重新绘制每个帧的完整屏幕。
像绘制云一样绘制方程式。
if pygame.time.get_ticks() > 5000:
display_equation()
eq_done
while not done:
# [...]
tks = pygame.time.get_ticks()
if 5000 < tks < 6000:
display_equation()
# [...]