def load_map(self, map_file): self.__map_file = map_file print "load_map: Loading map_file" + str(map_file) self.slmap = SpyLightMap() self.slmap.load_map(map_file) # Go through the whole map to find for special things to register, like actionable items... for row in xrange(0, self.slmap.height): for col in xrange(0, self.slmap.width): if self.slmap.map_tiles[row][col] == self.slmap.TERMINAL_KEY: terminal = TerminalAI(row * const.CELL_SIZE, col * const.CELL_SIZE) self.push_new_item(terminal) self.__total_time = 120 # TODO: Update with the real time read from the map file. self.__max_player_number = self.slmap.nb_players[Player.SPY_TEAM] + self.slmap.nb_players[Player.MERC_TEAM] # TODO: Update with the true player number # read from the map file. # Loading players start_merc_pids = 0 # firt merc pid to be assigned end_merc_pids = max(0, self.slmap.nb_players[0]-1) # Last mercernary pid to be assigned start_spy_pids = end_merc_pids+1 # firt spy pid to be assigned end_spy_pids = max(start_merc_pids, start_spy_pids + self.slmap.nb_players[1]-1) # Last spy pid to be assigned self.__players = [MercenaryPlayer(i) for i in xrange(start_merc_pids, end_merc_pids+1)] # TODO: replace that by the actual player loading self.__players.extend([SpyPlayer(i) for i in xrange(start_spy_pids, end_spy_pids+1)]) # TODO: replace that by the actual player loading # Move players to their respective spawn location for p in self.__players: spawn = self.slmap.get_spawn_point(p.team, p.player_id) dx, dy = spawn[1] * const.CELL_SIZE, spawn[0] * const.CELL_SIZE self.__move_player(p, dx, dy) # Do some things like settings the weapon for each player... return self # allow chaining
def __init__(self, serverip, serverport, team, nick, screenMgr): super(SpylightGame, self).__init__() self.screenMgr = screenMgr # Register to the server self._ni = NetworkInterface(serverip, serverport) init_response = self._ni.connect(MessageFactory.init(team, nick)) # Parse server init message self.team = init_response['team'] self.playerid = init_response['id'] # Init environment loaded_map = SpyLightMap(init_response['map']) Logger.info("SL|SLGame: Map loaded: %s", loaded_map.title) Logger.info("SL|SLGame: Map size: %s", loaded_map.size) if init_response['map_hash'] != loaded_map.get_hash(): Logger.error("SL|SLGame: Wrong map hash. Expected %s", loaded_map.get_hash()) sys.exit() self.init_game_view(loaded_map, init_response) self.hud = SpylightHUD(self, max_hp=init_response['max_hp']) self.add_widget(self.hud) # Register input listeners kbMgr = KeyboardManager() kbMgr.bind(quit=screenMgr.goToPauseScreen) self._am = ActionManager(self._ni, kbMgr, self) # Game client ready self._ni.on_message_recieved = self.update self._ni.ready()