Organize custom scripts and Shared under Assets/Scripts, and delete assembly definition files
This commit is contained in:
88
Assets/Scripts/Baba_yaga/GameSetup/Maze/CrawlerAlgorithm.cs
Normal file
88
Assets/Scripts/Baba_yaga/GameSetup/Maze/CrawlerAlgorithm.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Baba_yaga.GameSetup.Maze
|
||||
{
|
||||
[UnityEngine.Scripting.APIUpdating.MovedFrom(true, sourceNamespace: "Hallucinate.GameSetup.Maze", sourceAssembly: "Opsive.UltimateCharacterController")]
|
||||
public class CrawlerAlgorithm : IMazeAlgorithm
|
||||
{
|
||||
private const int CrawlChance = 50;
|
||||
private const int MinBoundary = 1;
|
||||
private const int VerticalCrawlerCount = 3;
|
||||
private const int HorizontalCrawlerCount = 3;
|
||||
|
||||
public void Generate(MazeGrid grid)
|
||||
{
|
||||
for (int i = 0; i < VerticalCrawlerCount; i++) CrawlV(grid, 0);
|
||||
for (int i = 0; i < HorizontalCrawlerCount; i++) CrawlH(grid, 0);
|
||||
}
|
||||
|
||||
public IEnumerator GenerateStepByStep(MazeGrid grid, int cellsPerFrame)
|
||||
{
|
||||
for (int i = 0; i < VerticalCrawlerCount; i++) yield return CrawlV(grid, cellsPerFrame);
|
||||
for (int i = 0; i < HorizontalCrawlerCount; i++) yield return CrawlH(grid, cellsPerFrame);
|
||||
}
|
||||
|
||||
private IEnumerator CrawlV(MazeGrid grid, int cellsPerFrame)
|
||||
{
|
||||
bool done = false;
|
||||
int x = Random.Range(MinBoundary, grid.Width - MinBoundary);
|
||||
int z = MinBoundary;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
grid.SetCell(x, z, MazeCellType.Processing);
|
||||
MazeManager.cellsProcessedThisFrame++;
|
||||
if (MazeManager.cellsProcessedThisFrame >= cellsPerFrame)
|
||||
{
|
||||
MazeManager.cellsProcessedThisFrame = 0;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
grid.SetCell(x, z, MazeCellType.Corridor);
|
||||
|
||||
if (Random.Range(0, 100) < CrawlChance)
|
||||
{
|
||||
x += Random.Range(-1, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
z += Random.Range(0, 2);
|
||||
}
|
||||
|
||||
done |= (x < MinBoundary || x >= grid.Width - MinBoundary || z < MinBoundary || z >= grid.Depth - MinBoundary);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator CrawlH(MazeGrid grid, int cellsPerFrame)
|
||||
{
|
||||
bool done = false;
|
||||
int x = MinBoundary;
|
||||
int z = Random.Range(MinBoundary, grid.Depth - MinBoundary);
|
||||
|
||||
while (!done)
|
||||
{
|
||||
grid.SetCell(x, z, MazeCellType.Processing);
|
||||
MazeManager.cellsProcessedThisFrame++;
|
||||
if (MazeManager.cellsProcessedThisFrame >= cellsPerFrame)
|
||||
{
|
||||
MazeManager.cellsProcessedThisFrame = 0;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
grid.SetCell(x, z, MazeCellType.Corridor);
|
||||
|
||||
if (Random.Range(0, 100) < CrawlChance)
|
||||
{
|
||||
x += Random.Range(0, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
z += Random.Range(-1, 2);
|
||||
}
|
||||
|
||||
done |= (x < MinBoundary || x >= grid.Width - MinBoundary || z < MinBoundary || z >= grid.Depth - MinBoundary);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user