我是Pygame的新手。对于课堂作业,我决定从教程中制作Wormy游戏。在我完成基本游戏之后,我决定在其中实现一些新功能。
我想要实现的一个简单功能是在游戏开始时的一个非常基本的“加载”屏幕,它包含一个大的蓝色屏幕,上面印有“正在加载”。然后是棘手的部分:我希望在10秒后出现另一行文本,“加载”文本出现在屏幕上。我正在考虑在其中实现某种形式的计时器,但代码(见下文)将无效。你们有没有想法?任何想法都将受到高度赞赏。
FPS = 8 # Already declared at the beginning
.
.
.
def showStartScreen(): # Start screen function that is to be called in
main()
loadingFont = pygame.font.SysFont('centurygothic', 50)
loadingText = loadingFont.render('Loading...', True, WHITE)
tick_counter = 0
while True:
pygame.time.Clock.tick(FPS)
tick_counter += 1
DISPLAYSURF.fill(DEEPSKYBLUE)
DISPLAYSURF.blit(loadingText, (WINDOWWIDTH / 2 -
loadingText.get_width() // 2, 235))
if tick_counter >= 40:
drawPressKeyMsg()
pygame.display.update()
pygame.time.wait(1000)
checkForKeyPress() # clear out any key presses in the event
queue
if checkForKeyPress():
pygame.event.get() # clear event queue
return
pygame.display.update()