Chapter 23Finishing Touches

Image

Our Crazy Driver game is fully functional. Not bad for 100 or so lines of code! In this chapter, we’ll add some finishing touches—some little details that will make the game shine.

Game Over Revisited

When our game ends, it just ends: no display, no message, no anything. You can’t even view your score. Let’s change that. We created a GameOver() function that gets called when the game is over. Right now, it just does cleanup, like this:

# Game over function
def GameOver():
    # Quit Pygame
    pygame.quit()
    sys.exit()

We’ll update this function to display a text message for a few seconds before the game ends, like this: ...

Get Captain Code: Unleash Your Coding Superpower with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.