public override void Generate(VGArea mArea) { // Randomly put solid tiles in the world int solidTilesAmount = (mArea.Width * mArea.Height) / 100 * InitialSolidPercent; for (int i = 0; i < solidTilesAmount; i++) { mArea.GetRandomTile().Set(ValueSolid); } // Iterate generation for (int iteration = 0; iteration < Iterations; iteration++) { // Create a clone of the world's map VGArea areaClone = mArea.Clone(); // Cellar automata rule 4-5 for (int iY = 0; iY < areaClone.Height; iY++) { for (int iX = 0; iX < areaClone.Width; iX++) { if (areaClone.GetTileNeighborsCountByValue(iX, iY, 1, ValueSolid) <= RequiredSolidToStarve) { mArea[iX, iY].Set(ValuePassable); } else if (areaClone.GetTileNeighborsCountByValue(iX, iY, 1, ValueSolid) >= RequiredSolidToSolidify) { mArea[iX, iY].Set(ValueSolid); } } } } }
public override void Generate(VGArea mArea) { // Create a clone of the world's map VGArea areaClone = mArea.Clone(); // Set all solids to walls for (int iY = 0; iY < areaClone.Height; iY++) { for (int iX = 0; iX < areaClone.Width; iX++) { if (areaClone[iX, iY].Value == ValueSolid) { mArea[iX, iY].Set(ValueWall); } } } // Create a clone of the world's map areaClone = mArea.Clone(); // Sets all walls with 9 wall neighbors to solid for (int iY = 0; iY < areaClone.Height; iY++) { for (int iX = 0; iX < areaClone.Width; iX++) { if (areaClone.GetTileNeighborsCountByValue(iX, iY, ValueWall) > 8) { mArea[iX, iY].Set(ValueSolid); } } } }