def manage_menu(self): """ manage input and update menu if we are in the menu state """ # return of the menu update function may contain a new game # instance to switch to. start_loop = pygame.time.get_ticks() menu_was = self.menu.current_screen newgame, game_ = self.menu.update() if menu_was == 'keyboard' and self.menu.current_screen != 'keyboard': self.controls.load_keys() self.controls.load_sequences() if newgame: self.state = 'game' if game_ is not self.game: print "starting game" self.ai_instance = AI() del(self.game) self.game = game_ max_fps = 1000/CONFIG.general.MAX_GUI_FPS if self.menu.current_screen == 'about': self.music_state = 'credits' else: self.music_state = self.state if pygame.time.get_ticks() < max_fps + start_loop: pygame.time.wait(max_fps + start_loop - pygame.time.get_ticks())
def init_standalone(self): ''' start a non network instance of the game ''' self.init_screen() self.text_thread = "Loading sounds and musics..." thread = threading.Thread(None, self.loading_screen) thread.start() self.init_sound() self.ai_instance = AI() # if a level was provided and at least two players in the option # immediatly jump into game mode if len(self.players) > 1 and self.level is not None: self.game = Game(self.screen, self.level, self.players) self.state = "game" self.menu = Gui(self.screen) self.menu.handle_reply({'goto': 'configure'}) else: self.lock.acquire() self.text_thread = "Loading GUI..." self.lock.release() self.menu = Gui(self.screen) self.state = "menu" self.game = None self.level = None self.lock.acquire() self.stop_thread = True self.lock.release() thread.join()