I am making a game that shows game over on screen at the end of the game and if the player presses any key, the game starts again.
Game over screen is displayed but the problem is that when I am pressing any key, the game is not starting. I suspect function gameOverScreen() is not returning out of while loop, I could not understand why.
This function is called when the game is over, and it's continuously running until the player press any key:
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)
Function to check key press is:
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
Main function which call all functions is:
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()and what code comes immediately after? - micsthepickgameOverScreenshould finish, how can you tell code does not execute after? - micsthepick