0
我正在製作遊戲,在遊戲結束時在屏幕上顯示遊戲結束,如果玩家按任何關鍵遊戲再次開始。顯示屏幕上的遊戲,但問題是,當我按任意鍵時,遊戲沒有開始。我懷疑功能gameOverScreen()沒有返回了while循環的,我不明白爲什麼pygame遊戲沒有按鍵開始
此功能時,遊戲就結束了這個所謂的持續運行,直到玩家按下任意鍵:
def gameOverScreen():
textFont = pygame.font.Font('freesansbold.ttf',90)
while True:
overSurf = textFont.render('GAME OVER',True,RED)
overRect = overSurf.get_rect()
overRect.center = (WINDOWWIDTH/2,WINDOWHEIGHT/2)
DISPLAYSURF.blit(overSurf,overRect)
drawPressKeyMessage()
checkForKeyPress()
if checkForKeyPress():
pygame.event.get() #clear event queue
return
pygame.display.update()
FPSCLOCK.tick(FPS)
功能檢查按鍵是:
def checkForKeyPress():
if len(pygame.event.get(QUIT)) > 0:
terminate()
keyUpEvents = pygame.event.get(KEYUP)
if len(keyUpEvents) == 0:
return None
else:
return keyUpEvents[0].key
它調用所有功能
主要功能是:
def main():
global FPSCLOCK, DISPLAYSURF, BASICFONT
pygame.init()
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption('Wormy')
showStartScreen()
while True:
runGame()
showGameOverScreen()
什麼叫'gameOverScreen()',緊接着什麼代碼? – micsthepick
只要按下一個鍵,'gameOverScreen'應該完成,你怎麼能告訴代碼後不執行? – micsthepick
@micsthepick gameOverScreen()函數繼續運行,直到返回被反擊 – Tango