public override void boardSetup() { boardHolder = new GameObject ("Board").transform; // Generate a map from Cellular Automata. // CellularAutomata foo = new CellularAutomata(rows, columns); //PureRandom foo = new PureRandom(rows, columns); GameObject playerChar = GameObject.FindGameObjectWithTag("Player"); selectedRule.initializeMap (); selectedRule.generateMap (); Tile[,] mapConvert = selectedRule.map; MapValidationFunctions mvf = new MapValidationFunctions(); Coord startPoint = new Coord(floodStartX,floodStartY); Coord endPoint = new Coord(floodGoalX, floodGoalY); mvf.FloodFillCheck(selectedRule.map, startPoint, endPoint); // This is the autotiler phase. // // Let's try this method of instantiating the prefab of our choice... GameObject tileInstance = Instantiate(tilesetToUse, new Vector3(0,0,0), Quaternion.identity) as GameObject; selectedTileset = tileInstance.GetComponent<Tileset>(); selectedTileset.autoTiler( mapConvert ); if(MapValidationFunctions.clearable) Debug.Log ("The goal has been found!"); else Debug.Log ("I can't find the goal."); //convertTiles( mapConvert ); }
public void pickWarpLocation(Coord playerLocation) { // GOOD LOC OK int counter = 0; MapValidationFunctions mvf = new MapValidationFunctions(); GameObject playerChar = GameObject.FindGameObjectWithTag ("Player"); bool mercyLength = false; int playerX = playerLocation.x; int playerY = playerLocation.y; int candidX = 0; int candidY = 0; while(true && counter < 200){ if(counter > 100 && !mercyLength) { Debug.Log ("Lasted too long, give a mercy kill for the distance metric."); mercyLength = true; } do { candidX = Random.Range(1, rows-1); candidY = Random.Range(1, columns-1); } while (candidX == playerX && candidY == playerY); Tile[,] candidMap = selectedRule.map; MapValidationFunctions.clearMapMark(candidMap); Debug.Log ("Proposing point " + candidX.ToString () + " and " + candidY.ToString()); mvf.FloodFillCheck( candidMap, new Coord(candidX, candidY), new Coord(playerX, playerY)); if((candidMap[candidX,candidY]).property == TileType.Floor1 && MapValidationFunctions.clearable && ( MapValidationFunctions.manhattanDistance( new Coord(candidX, candidY), new Coord(playerX, playerY) ) >= (int)(rows) || MapValidationFunctions.manhattanDistance( new Coord(candidX, candidY), new Coord(playerX, playerY) ) >= (int)(columns) || mercyLength)) { // We need to move the player to this position. Vector3 moveMe = new Vector3(candidX, candidY); GameObject warpObj = GameObject.FindGameObjectWithTag("Warp"); warpObj.transform.position = moveMe; Debug.Log ("Found. Warp is at (" + candidX + "," + candidY + ")"); return; } Debug.Log ("Failed for " + playerX.ToString () + " and " + playerY.ToString () + " to " + candidX.ToString () + " and " + candidY.ToString()); counter++; } // You really don't want to be at this spot. Debug.Log ("I give up. Default warp to the midpoint."); Vector3 findme = new Vector3(rows/2,columns/2); GameObject ok = GameObject.FindGameObjectWithTag("Warp"); ok.transform.position = findme; return; }