diff --git a/Assets/Src/Maze/BSP.meta b/Assets/Src/Maze/BSP.meta new file mode 100644 index 0000000..50597ea --- /dev/null +++ b/Assets/Src/Maze/BSP.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: af9e9bcb93baf4c74acd2bb27de886b7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Src/Maze/BSP/BSPGenerator.cs b/Assets/Src/Maze/BSP/BSPGenerator.cs new file mode 100644 index 0000000..d0d8952 --- /dev/null +++ b/Assets/Src/Maze/BSP/BSPGenerator.cs @@ -0,0 +1,110 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; + +public class BSPGenerator : Generator +{ + + private bool isCheeseArea(int x, int y) + { + return x > 90 && y > 90; + } + + private bool isSpawnArea(int x, int y) + { + return x < 10 && y < 10; + } + + private bool isEdge(int x, int y, int size) + { + return x == 0 || y == 0 || x == size - 1 || y == size - 1; + } + + public override Vector2Int GenerateCheese(Maze maze, Vector3[] playerPositions, Vector2Int? currentCheese) + { + return new Vector2Int(95, 95); + } + + private List BreakDown(List breakdown) { + List breakdownList = new List(); + foreach (Particle particle in breakdown) { + if (Math.Abs(particle.x0 - particle.x1) < 4) { + breakdownList.Add(particle); + continue; + }; + int x = UnityEngine.Random.Range(particle.x0, particle.x1); + breakdownList.Add(new Particle(particle.x0, x, particle.y0, particle.y1)); + breakdownList.Add(new Particle(x, particle.x1, particle.y0, particle.y1)); + } + + List breakdownListFinal = new List(); + foreach (Particle particle in breakdownList) { + if (Math.Abs(particle.y0 - particle.y1) < 4) { + breakdownListFinal.Add(particle); + continue; + } + int y = UnityEngine.Random.Range(particle.y0, particle.y1); + breakdownListFinal.Add(new Particle(particle.x0, particle.x1, particle.y0, y)); + breakdownListFinal.Add(new Particle(particle.x0, particle.x1, y, particle.y1)); + } + return breakdownListFinal; + } + + private void SliceMaze(Maze maze) { + var particles = new List() { + new Particle(0, maze.Size, 0, maze.Size) + }; + + while (particles.Count < 1000) { + particles = BreakDown(particles); + } + + for(int i = 0; i < particles.Count; i++) { + if (i%2 == 0) continue; + var particle = particles[i]; + for (int x = particle.x0; x < particle.x1; x++) + { + for (int y = particle.y0; y < particle.y1; y++) + { + maze.Set(x, y, true); + } + } + } + } + + + public override Maze GenerateMaze(int size) + { + var maze = new Maze(size); + // BSP algorithm + + SliceMaze(maze); + + + + // End of BSP algorithm + + + // DO NOT CHANGE + // Set walls and free spawn and cheese areas + for (int x = 0; x < size; x++) + { + for (int y = 0; y < size; y++) + { + if (isEdge(x, y, size)) + { + maze.Set(x, y, true); + continue; + } + if (isSpawnArea(x, y) || isCheeseArea(x, y)) + { + maze.Set(x, y, false); + continue; + } + } + } + + return maze; + } +} diff --git a/Assets/Src/Maze/BSP/BSPGenerator.cs.meta b/Assets/Src/Maze/BSP/BSPGenerator.cs.meta new file mode 100644 index 0000000..483a000 --- /dev/null +++ b/Assets/Src/Maze/BSP/BSPGenerator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 44c0d6ba59d584c7bbe7540a7fa3f988 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Src/Maze/BSP/Particle.cs b/Assets/Src/Maze/BSP/Particle.cs new file mode 100644 index 0000000..f2a8d8b --- /dev/null +++ b/Assets/Src/Maze/BSP/Particle.cs @@ -0,0 +1,15 @@ +class Particle +{ + public int x0; + public int x1; + public int y0; + public int y1; + + public Particle(int x0, int x1, int y0, int y1) + { + this.x0 = x0; + this.x1 = x1; + this.y0 = y0; + this.y1 = y1; + } +} diff --git a/Assets/Src/Maze/BSP/Particle.cs.meta b/Assets/Src/Maze/BSP/Particle.cs.meta new file mode 100644 index 0000000..095605c --- /dev/null +++ b/Assets/Src/Maze/BSP/Particle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6d239d635b7654189bd692265397075e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: