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) { // 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) { for (int i = 0; i < WalkersAmount; i++) { VGTile randomTile = mArea.GetRandomTile(); WalkerPaths.Add(new VGGWalkerPath(randomTile.X, randomTile.Y, WalkerMinimumSteps, WalkerMaximumSteps, WalkerDeathChance, WalkerDirectionChangeChance)); } bool running = true; while (running) { List<VGGWalkerPath> toRemove = new List<VGGWalkerPath>(); running = false; foreach (VGGWalkerPath path in WalkerPaths) { if (mArea.Contains(path.X, path.Y)) { for (int iY = -WalkerRadius; iY < WalkerRadius + 1; iY++) for (int iX = -WalkerRadius; iX < WalkerRadius + 1; iX++) if (mArea.Contains(path.X + iX, path.Y + iY)) mArea[path.X + iX, path.Y + iY].Set(ValuePassable); } else if (IsWrapped) { if (path.X >= mArea.Width) path.X = 0; else if (path.X < 0) path.X = mArea.Width - 1; if (path.Y >= mArea.Height) path.Y = 0; else if (path.Y < 0) path.Y = mArea.Height - 1; } path.Step(); if (path.Alive) running = true; else if (IsRoomCreatedOnDeath) { toRemove.Add(path); int roomWidth = VGUtils.GetRandomInt(RoomMinSize, RoomMaxSize); int roomHeight = VGUtils.GetRandomInt(RoomMinSize, RoomMaxSize); for (int iY = 0; iY < roomHeight; iY++) for (int iX = 0; iX < roomWidth; iX++) if (mArea.Contains(path.X - (roomWidth/2) + iX, path.Y - (roomHeight/2) + iY)) mArea[path.X - (roomWidth/2) + iX, path.Y - (roomHeight/2) + iY].Set(ValuePassable); } } foreach (VGGWalkerPath pathToRemove in toRemove) WalkerPaths.Remove(pathToRemove); } }
public override void Generate(VGArea mArea) { for (int i = 0; i < WalkersAmount; i++) { VGTile randomTile = mArea.GetRandomTile(); WalkerPaths.Add(new VGGWalkerPath(randomTile.X, randomTile.Y, WalkerMinimumSteps, WalkerMaximumSteps, WalkerDeathChance, WalkerDirectionChangeChance)); } bool running = true; while (running) { List <VGGWalkerPath> toRemove = new List <VGGWalkerPath>(); running = false; foreach (VGGWalkerPath path in WalkerPaths) { if (mArea.Contains(path.X, path.Y)) { for (int iY = -WalkerRadius; iY < WalkerRadius + 1; iY++) { for (int iX = -WalkerRadius; iX < WalkerRadius + 1; iX++) { if (mArea.Contains(path.X + iX, path.Y + iY)) { mArea[path.X + iX, path.Y + iY].Set(ValuePassable); } } } } else if (IsWrapped) { if (path.X >= mArea.Width) { path.X = 0; } else if (path.X < 0) { path.X = mArea.Width - 1; } if (path.Y >= mArea.Height) { path.Y = 0; } else if (path.Y < 0) { path.Y = mArea.Height - 1; } } path.Step(); if (path.Alive) { running = true; } else if (IsRoomCreatedOnDeath) { toRemove.Add(path); int roomWidth = VGUtils.GetRandomInt(RoomMinSize, RoomMaxSize); int roomHeight = VGUtils.GetRandomInt(RoomMinSize, RoomMaxSize); for (int iY = 0; iY < roomHeight; iY++) { for (int iX = 0; iX < roomWidth; iX++) { if (mArea.Contains(path.X - (roomWidth / 2) + iX, path.Y - (roomHeight / 2) + iY)) { mArea[path.X - (roomWidth / 2) + iX, path.Y - (roomHeight / 2) + iY].Set(ValuePassable); } } } } } foreach (VGGWalkerPath pathToRemove in toRemove) { WalkerPaths.Remove(pathToRemove); } } }