def handle_chat_events(self): if pygame.K_t in wotsuievents.keys_pressed: self.chatting = True if versusclient.local_player_is_in_match(): players[versusclient.get_local_player_position()].handle_input_events = False if (pygame.K_RETURN in wotsuievents.keys_pressed or pygame.K_ESCAPE in wotsuievents.keys_pressed): self.chatting = False if versusclient.local_player_is_in_match(): players[versusclient.get_local_player_position()].handle_input_events = True
def build_player_command_types(self): keys_pressed = { PlayerPositions.PLAYER1 : InputCommandTypes( [], InputActionTypes.NO_MOVEMENT, [], [], [] ), PlayerPositions.PLAYER2 : InputCommandTypes( [], InputActionTypes.NO_MOVEMENT, [], [], [] ) } if versusclient.local_player_is_in_match(): player_position = versusclient.get_local_player_position() keys_pressed[player_position] = self.player_key_handlers[ player_position ].get_command_data(wotsuievents.keys_pressed) if keys_pressed[player_position] == None: print(wotsuievents.keys_pressed) return keys_pressed
def update_player_data(): global player_status_ui_dictionary for player_position in player_status_ui_dictionary: if (player_position == versusclient.get_local_player_position() or (versusclient.is_dummy(player_position) and gamestate.hosting)): player_status_ui = player_status_ui_dictionary[player_position] if pygame.MOUSEBUTTONUP in wotsuievents.event_types: if player_status_ui.moveset_select.contains(wotsuievents.mouse_pos): versusclient.listener.set_moveset(player_status_ui.get_moveset().name, player_position) if player_status_ui.player_color_select.contains(wotsuievents.mouse_pos): versusclient.listener.set_color(player_status_ui.get_color(), player_position) if player_status_ui.player_stats_widget.contains(wotsuievents.mouse_pos): versusclient.listener.set_size(player_status_ui.get_size(), player_position) if player_status_ui.player_difficulty_select.contains(wotsuievents.mouse_pos): versusclient.listener.set_difficulty(player_status_ui.get_difficulty(), player_position) if player_status_ui.player_type_select.contains(wotsuievents.mouse_pos): versusclient.listener.set_player_type(player_status_ui.get_player_type(), player_position)
def init_simulation_objects(self): #for player_position in self.player_dictionary: # self.player_key_handlers[player_position] = KeyToCommandTypeConverter( # dict([(entry[1], entry[0]) for entry in get_controls().iteritems()]) # ) self.simulation_connection, input_connection = multiprocessing.Pipe() player_position = versusclient.get_local_player_position() if gamestate.hosting: self.match_simulation = ServerSimulation( input_connection, player_dictionary=self.player_dictionary, player_type_dictionary=self.player_type_dictionary, player_position=player_position ) else: self.match_simulation = ClientSimulation( input_connection, player_dictionary=self.player_dictionary, player_type_dictionary=self.player_type_dictionary, player_position=player_position )
def handle_events(): global loaded global exit_button global start_match_label global player_status_ui_dictionary global join_match_button global local_player_container_created global local_player_position if loaded == False: load() if pygame.MOUSEBUTTONDOWN in wotsuievents.event_types: if exit_button.contains(wotsuievents.mouse_pos): exit_button.handle_selected() if start_match_label.active: if start_match_label.contains(wotsuievents.mouse_pos): start_match_label.handle_selected() if join_match_button.active: if join_match_button.contains(wotsuievents.mouse_pos): join_match_button.handle_selected() if spectate_button.active: if spectate_button.contains(wotsuievents.mouse_pos): spectate_button.handle_selected() if pygame.MOUSEBUTTONUP in wotsuievents.event_types: if exit_button.selected: exit_button.handle_deselected() if exit_button.contains(wotsuievents.mouse_pos): gamestate.mode = gamestate.Modes.ONLINEMENUPAGE unload() elif start_match_label.selected: if start_match_label.contains(wotsuievents.mouse_pos): start_match_label.handle_deselected() versusclient.listener.load_match_data() #TODO - inactivate join if selected and same for spectate elif join_match_button.selected: if join_match_button.contains(wotsuievents.mouse_pos): versusclient.listener.join_match() join_match_button.handle_deselected() join_match_button.inactivate() spectate_button.activate() elif spectate_button.selected: if spectate_button.contains(wotsuievents.mouse_pos): versusclient.listener.spectate_match() spectate_button.handle_deselected() spectate_button.inactivate() join_match_button.activate() if loaded: if versusclient.dummies_only() and start_match_label.active == False: start_match_label.activate() if local_player_container_created: players_ready = True local_player_position = versusclient.get_local_player_position() if player_status_ui_dictionary[local_player_position].player_ready() and \ not versusclient.listener.player_positions_ready_dictionary[local_player_position]: versusclient.listener.player_ready() for player_status_ui in player_status_ui_dictionary.values(): if hasattr(player_status_ui, "player_ready"): players_ready = (getattr(player_status_ui, "player_ready")() and players_ready) else: players_ready = False if players_ready: if start_match_label.active == False: start_match_label.activate() else: if start_match_label.active: start_match_label.inactivate() for player_status_ui in player_status_ui_dictionary.values(): player_status_ui.handle_events() player_status_ui.draw(gamestate.screen) join_match_button.draw(gamestate.screen) exit_button.draw(gamestate.screen) start_match_label.draw(gamestate.screen) spectate_button.draw(gamestate.screen) #Network Dependent Event Handling if (versusclient.listener.connection_status == versusclient.ConnectionStatus.DISCONNECTED): unload() gamestate.mode = gamestate.Modes.ONLINEMENUPAGE if versusclient.connected() or gamestate.hosting: if not versusclient.local_player_is_in_match(): if not join_match_button.active: join_match_button.activate() if spectate_button.active: spectate_button.inactivate() else: if not spectate_button.active: spectate_button.activate() if join_match_button.active: join_match_button.inactivate() update_player_data() if (versusclient.listener.server_mode == versusserver.ServerModes.LOADING_MATCH_DATA) or \ (versusclient.listener.server_mode == versusserver.ServerModes.MATCH): gamestate.mode = gamestate.Modes.ONLINEMATCHLOADER versusclient.get_network_messages() versusclient.listener.Pump()