void SetPlayerNewPosition(Map lastMap, Vector2 _doorFromPosition) { Vector2 fromDoorIndex = lastMap.WorldPointToTileIndex(_doorFromPosition); // Change door tile to opened door :P int originalID = lastMap.GetTileLayer("Layer 0").Tiles[fromDoorIndex.x, fromDoorIndex.y].OriginalID; lastMap.GetTileLayer("Layer 0").SetTile(fromDoorIndex.x, fromDoorIndex.y, originalID + 2); int lastMapWidth = lastMap.Width; int lastMapHeight = lastMap.Height; // Position player MapObjectLayer mol = _currentMap.GetObjectLayer("Doors"); for (int i = 0; i < mol.Objects.Count; i++) { // This is a Left Door - X = 0 if (mol.Objects[i].Bounds.x < 1) { // And we came from a Right Door! if (fromDoorIndex.x >= lastMapWidth - 1) { _player.transform.localPosition = _currentMap.TiledPositionToWorldPoint(1.5f, mol.Objects[i].Bounds.y + 0.5f); } } // This is a Right Door - X = _currentMap.Width - 1 if (mol.Objects[i].Bounds.x >= _currentMap.Width - 1) { // And we came from a Left Door! if (fromDoorIndex.x < 1) { _player.transform.localPosition = _currentMap.TiledPositionToWorldPoint(mol.Objects[i].Bounds.x - 1, mol.Objects[i].Bounds.y + 0.5f); } } // This is an Up Door - Y = 0 if (mol.Objects[i].Bounds.y < 1) { // And we came from a Down Door! if (fromDoorIndex.y >= lastMapHeight - 1) { _player.transform.localPosition = _currentMap.TiledPositionToWorldPoint(mol.Objects[i].Bounds.x + 0.5f, 1.4f); } } // This is a Down Door - Y = _currentMap.Height - 1 if (mol.Objects[i].Bounds.y >= _currentMap.Height - 1) { // And we came from an Up Door! if (fromDoorIndex.y < 1) { _player.transform.localPosition = _currentMap.TiledPositionToWorldPoint(mol.Objects[i].Bounds.x, mol.Objects[i].Bounds.y - 0.5f); } } } _player.gameObject.GetComponent<X_UniTMX.Utils.SortingOrderAutoCalculator>().SetMap(_currentMap); }
// Use this for initialization void Start() { TiledMap = new Map(TileMap, true, MapsPath, this.gameObject, defaultMaterial, 0); TileLayer tileLayer = TiledMap.GetTileLayer("Background"); for (int i = 0; i < CoinsToAnimate.Length; i++) { AnimatedTile animTile = tileLayer.Tiles[(int)CoinsToAnimate[i].x, (int)CoinsToAnimate[i].y].TileObject.AddComponent<AnimatedTile>(); animTile.TiledMap = TiledMap; animTile.TileFramesGIDs = new int[] { 41, 42, 43, 44, 45, 46, 47, 48 }; animTile.AnimationFPS = 5; animTile.AnimationMode = TileAnimationMode.PING_PONG; } for (int i = 0; i < FacesToAnimate.Length; i++) { AnimatedTile animTile = tileLayer.Tiles[(int)FacesToAnimate[i].x, (int)FacesToAnimate[i].y].TileObject.AddComponent<AnimatedTile>(); animTile.TiledMap = TiledMap; animTile.TileFramesGIDs = new int[] { 2, 3, 19, 20, 22, 34 }; animTile.AnimationFPS = 5; animTile.AnimationMode = TileAnimationMode.LOOP; } }