starshipmeteors pygame displaying the game over message pygame does not come with an easy way of creating popup dialog box to display messages such as 'you won'or 'you lostwhich is why we have used print statements so far howeverwe could use gui framework such as wxpython to do this or we could display message on the display surface to indicate whether the player has won or lost we can display message on the display surface using the pygame font font class this can be used to create font object that can be rendered onto surface that can be displayed onto the main display surface we can therefore add method _display_message(to the game class that can be used to display appropriate messagesdef _display_message(selfmessage)""displays message to the user on the screen ""print(messagetext_font pygame font font('freesansbold ttf' text_surface text_font render(messagetruebluewhitetext_rectangle text_surface get_rect(text_rectangle center (display_width display_height self display_surface fill(whiteself display_surface blit(text_surfacetext_rectangleagain the leading underbar in the method name indicates that it should not be called from outside the game class we can now modify the main loop such that appropriate messages are displayed to the userfor examplecheck to see if meteor has hit the ship if self _check_for_collision()starship_collided true self _display_message('collisiongame over'