// Start Game public void init() { // map size level = new Level(); MapProperties prop = level.map.getProperties(); int mapWidth = prop.get("width", Integer.class); int mapHeight = prop.get("height", Integer.class); System.out.println("mapWidth: " + mapWidth + ", " + "mapHeight: " + mapHeight); tilePixelWidth = prop.get("tilewidth", Integer.class); tilePixelHeight = prop.get("tileheight", Integer.class); System.out.println( "tilePixelWidth: " + tilePixelWidth + ", " + "tilePixelHeight: " + tilePixelHeight); mapPixelWidth = mapWidth * tilePixelWidth; mapPixelHeight = mapHeight * tilePixelHeight; System.out.println( "mapPixelWidth: " + mapPixelWidth + ", " + "mapPixelHeight: " + mapPixelHeight); // set bounding boxes for tilemap sprites // stones TiledMapTileLayer layer = (TiledMapTileLayer) level.map.getLayers().get("stones"); System.out.println("Layer: " + layer); freeCells = new boolean[layer.getWidth()][layer.getHeight()]; mapCellWidth = layer.getWidth(); mapCellHeight = layer.getHeight(); for (int x = 0; x < layer.getWidth(); x++) { for (int y = 0; y < layer.getHeight(); y++) { freeCells[x][y] = true; if (layer.getCell(x, y) != null) { // Spawn Walls WallGameObject wall = new WallGameObject(x * tilePixelWidth + 25, y * tilePixelWidth + 25, 100, 100); this.objs.addObject(wall); // safe blocked cell coordinates for random player position freeCells[x][y] = false; } } } // bushs layer = (TiledMapTileLayer) level.map.getLayers().get("bushs"); for (int x = 0; x < layer.getWidth(); x++) { for (int y = 0; y < layer.getHeight(); y++) { if (layer.getCell(x, y) != null) { // Spawn Bush BushGameObject bush = new BushGameObject(x * tilePixelWidth + 25, y * tilePixelWidth + 25, 90, 90); this.objs.addObject(bush); } } } // checkpoints layer = (TiledMapTileLayer) level.map.getLayers().get("checkpoint"); int ci = 0; for (int x = 0; x < layer.getWidth(); x++) { for (int y = 0; y < layer.getHeight(); y++) { if (layer.getCell(x, y) != null) { // Spawn Checkpoint CheckpointGameObject checkpoint = new CheckpointGameObject(x * tilePixelWidth, y * tilePixelWidth, 125, 125); checkpoint.client = this.client; checkpoint.checkpointID = ci; this.objs.addObject(checkpoint); checkpointsNeeded++; ci++; } } } this.client.start(); // For consistency, the classes to be sent over the network are registered by the same method // for both the client and server TurirunNetwork.register(client); client.addListener( new ThreadedListener( new Listener() { public void connected(Connection connection) {} public void received(Connection connection, Object object) { WorldController.events.add(object); } public void disconnected(Connection connection) {} })); try { // Block for max. 3000ms // 172.18.12.25 client.connect(3000, this.game.host, this.game.port, TurirunNetwork.udpPort); // Server communication after connection can go here, or in Listener#connected() } catch (IOException e) { Gdx.app.error("Could not connect to server", e.getMessage()); // Create local player as fallback TouriCharacterObject playerObj = new TouriCharacterObject(10, 10); playerObj.setNick(game.nickname); objs.addObject(playerObj); controller.setPlayerObj(playerObj); } Register register = new Register(); register.nick = this.game.nickname; register.type = 0; client.sendTCP(register); }