def gameStart(self): self.displayText.setText("Starting game...") if CLIENTS.__len__() > 1: ranValPkg = PyDatagram() ranValPkg.addUint16(GAME_INITIALIZE) ranValPkg.addUint32(self.playerCount) for client in CLIENTS: x = random.randint(1, 5) y = random.randint(1, 5) self.gameEngine.players.append( Player(x, y, 20, CLIENTS_ID[client])) self.gameEngine.world.attachCharacter(self.gameEngine.players[ CLIENTS_ID[client]].playerNP.node()) ranValPkg.addUint32(CLIENTS_ID[client]) ranValPkg.addFloat32(x) ranValPkg.addFloat32(y) for client in CLIENTS: temp = ranValPkg.__copy__() temp.addUint32(CLIENTS_ID[client]) self.cWriter.send(temp, client) taskMgr.add(self.update, 'update') else: self.broadcastMsg("/info no_clients") GameUI.createWhiteBgUI("Not enough clients connected.") self.displayText.destroy()
def game_start(self): base.oobe() self.display_text.setText("Begin") pkg = PyDatagram() pkg.addUint16(GAME_INITIALIZE) pkg.addUint32(self.network.playerCount) for client_id in self.network.CLIENTS_ID: x = random.randint(1, 5) y = random.randint(1, 5) self.gameEngine.players.append(Player(x, y, 20, client_id)) self.gameEngine.world.attachCharacter( self.gameEngine.players[client_id].playerNP.node()) pkg.addUint32(client_id) pkg.addFloat32(x) pkg.addFloat32(y) for client_id in self.network.CLIENTS_ID: temp = pkg.__copy__() temp.addUint32(client_id) self.network.cWriter.send(temp, self.network.RELATION_OBJ_ID[client_id]) # taskMgr.add(self.update, 'update') self.clientsAlive = self.network.CLIENTS_ID.copy() self.display_text.destroy()