// Update is called once per frame void Update() { if (generate) { celAuto.Simulate(); } }
private void GenerateCave() { CellularAutomaton cave = new CellularAutomaton(WidthFull, HeightFull); cave.Simulate(ExplorerConstants.Generation.CaveSurviveStates, ExplorerConstants.Generation.CaveBornStates, CellularAutomaton.BorderType.Solid, ExplorerConstants.Generation.CaveDensity, ExplorerConstants.Generation.CaveSimulations); byte[,] caveData = cave.GetGrid(); //First, convert basic cave data to actual map data for (int i = 0; i < WidthFull; i++) { for (int j = 0; j < HeightFull; j++) { ForcePut(ExplorerConstants.Items.IDS.CaveFloor, i, j); if (caveData[i, j] > 0) ForcePut(ExplorerConstants.Items.IDS.CaveStone, i, j); } } //Gather up the 3x3 empty spaces List<Tuple<int, int>> emptyBlocks = GetEmptyBlocks(2); //Not empty enough yo if (emptyBlocks.Count == 0) { GenerateCave(); return; } //Now find a nice place to put the spawn and jam it there. Tuple<int, int> spawnTuple = emptyBlocks[random.Next(emptyBlocks.Count)]; emptyBlocks.RemoveAll(x => Math.Abs(x.Item1 - spawnTuple.Item1) < 5 && Math.Abs(x.Item2 - spawnTuple.Item2) < 5); //Eww, we're repurposing the spawn parameters as block spawn! spawnAcreX = spawnTuple.Item1 + 1; spawnAcreY = spawnTuple.Item2 + 1; //Set up the area for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++) ForcePut(ExplorerConstants.Items.IDS.CaveFloor2, spawnTuple.Item1 + i, spawnTuple.Item2 + j); //Put the "ladder" ForcePut(ExplorerConstants.Items.IDS.CaveExit, spawnTuple.Item1, spawnTuple.Item2); //Now pick 2/3 of the random cave items and stick them in there too List<ExplorerConstants.Items.IDS> leftoverLoot = new List<ExplorerConstants.Items.IDS>(ExplorerConstants.Items.CaveLoot); for (int i = 0; i < ExplorerConstants.Items.CaveLoot.Count * 2 / 3; i++) { Tuple<int, int> lootTuple = emptyBlocks[random.Next(emptyBlocks.Count)]; emptyBlocks.RemoveAll(x => Math.Abs(x.Item1 - lootTuple.Item1) < 5 && Math.Abs(x.Item2 - lootTuple.Item2) < 5); if (emptyBlocks.Count == 0) { GenerateCave(); return; } //Set up the area for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) ForcePut(ExplorerConstants.Items.IDS.CaveFloor2, lootTuple.Item1 + x, lootTuple.Item2 + y); //Put the loot ExplorerConstants.Items.IDS loot = (i == 0 ? ExplorerConstants.Items.IDS.StarCrystal : leftoverLoot[random.Next(leftoverLoot.Count)]); ForcePut(loot, lootTuple.Item1,lootTuple.Item2); leftoverLoot.Remove(loot); } }
private void Update() { automaton.Simulate(); DrawCells(); UpdateSkybox(); }