class MenuState(GameState): """ Game state where the menu is displayed """ def __init__(self): super(MenuState, self).__init__() self.menu = MainMenu() def handle_event(self, event, gameengine): if event.type == QUIT: # Quit event pygame.quit() sys.exit() elif event.type == KEYDOWN: if event.key == K_ESCAPE: # Close the menu and switch back to playing state gameengine.currentState = gameengine.playState elif event.type == MOUSEBUTTONDOWN: # Check if the mouse click position collides with any menu # item, meaning the user clicked a menu item for menuItem in self.menu.menuItems: if menuItem.rect.collidepoint(event.pos): menuItem.action() def displayMenu(self, screen): self.menu.display(screen)
def __init__(self): super(MenuState, self).__init__() self.menu = MainMenu()