/* * Devuielve true si hay un muro desde la posicion position en la direccion direction * Devuelve false en caso contrario * * **/ private bool isWall(Vector2 position, Vector2 direction) { Map.tileInfo t = _tilesInfo[(int)position.y, (int)position.x]; if (!t.upWall && !t.downWall && !t.rightWall && !t.leftWall) { return(false); } if (direction.x == 0) { if (direction.y > 0) { return(t.upWall); } else if (direction.y < 0) { return(t.downWall); } } else if (direction.y == 0) { if (direction.x > 0) { return(t.rightWall); } else if (direction.x < 0) { return(t.leftWall); } } return(true); }
/* * Delvuelve el numero de paredes que hay en la posicion position * * **/ private int wallCount(Vector2 position) { Map.tileInfo t = _tilesInfo[(int)position.y, (int)position.x]; int paredes = 0; if (t.upWall) { paredes++; } if (t.downWall) { paredes++; } if (t.rightWall) { paredes++; } if (t.leftWall) { paredes++; } return(paredes); }
/* * Este metodo crea el board (mapa con los prefab y todo eso) * a partir de la informacion que se le pasa por parametro * * **/ public void SetMap(Map map) { this.map = map; int rows = map.tiles.GetLength(0); int cols = map.tiles.GetLength(1); _tiles = new Tile[rows, cols]; _tilesInfo = new Map.tileInfo[rows, cols]; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { // instanciamos el tile _tiles[i, j] = Instantiate(tilePrefab); _tiles[i, j].gameObject.transform.SetParent(this.gameObject.transform); _tilesInfo[i, j] = map.tiles[i, j]; // iniciamos los atributos del tile correspondiente _tiles[i, j].gameObject.transform.localPosition = new Vector2(j, i); _tiles[i, j].EnableIce(_tilesInfo[i, j].ice); if (j == cols - 1 || i == rows - 1) { _tiles[i, j].EnableWalls(new Tile.enabledWalls(_tilesInfo[i, j].upWall, _tilesInfo[i, j].downWall, _tilesInfo[i, j].leftWall, _tilesInfo[i, j].rightWall)); } else { _tiles[i, j].EnableWalls(new Tile.enabledWalls(false, _tilesInfo[i, j].downWall, _tilesInfo[i, j].leftWall, false)); } if (_tilesInfo[i, j].type == Map.TILETYPE.GOAL) { _tiles[i, j].EnableGoal(true); goalPos = new Vector2(j, i); } else { _tiles[i, j].EnableGoal(false); } if (_tilesInfo[i, j].type == Map.TILETYPE.START) { c = Instantiate(characterPrefab); c.gameObject.transform.SetParent(this.gameObject.transform); c.transform.localPosition = _tiles[i, j].gameObject.transform.localPosition; c.boardManager = this; //characterPos = new Vector2(j, i); } } } //if (characterPos == null) // characterPos = new Vector2(0, 0); // hacer el reescalado del mapa. MapRescaling(); }