void CreateChest(Gameplay.Maze <Gameplay.Cell> maze, int row, int col) { Quaternion r = Quaternion.identity; Vector3 chestPosition = new Vector3((2 * row + 1) * maze.CellSize, 0.0f, (2 * col + 1) * maze.CellSize); Vector3 chestRotation = new Vector3(); // Check which direction the chest is facing (which direction of the cell is open). switch (maze[row, col].DeadEndOpening()) { case Gameplay.Wall.Left: chestRotation = new Vector3(0.0f, 180.0f, 0.0f); break; case Gameplay.Wall.Up: chestRotation = new Vector3(0.0f, -90.0f, 0.0f); break; case Gameplay.Wall.Right: chestRotation = new Vector3(0.0f, 0.0f, 0.0f); break; case Gameplay.Wall.Down: chestRotation = new Vector3(0.0f, 90.0f, 0.0f); break; } r.eulerAngles = chestRotation; GameObject chest = Instantiate(chestPrefab, chestPosition, r); chest.transform.parent = mazeObject.transform; }
void CreateFloor(Gameplay.Maze <Gameplay.Cell> maze) { GameObject floor = GameObject.CreatePrimitive(PrimitiveType.Plane); floor.transform.parent = mazeObject.transform; floor.transform.localScale = new Vector3(maze.Length * 0.2f * maze.CellSize, 1, maze.Width * 0.2f * maze.CellSize); floor.transform.position = new Vector3(maze.Length * maze.CellSize, 0, maze.Width * maze.CellSize); }
void CreateWall(Gameplay.Maze <Gameplay.Cell> maze, Vector3 position, Vector3 rotation) { Quaternion r = Quaternion.identity; r.eulerAngles = rotation; GameObject wall = Instantiate(wallPrefab, position, r) as GameObject; wall.transform.parent = mazeObject.transform; wall.transform.localScale *= maze.CellSize; }
void CreateFinish(Gameplay.Maze <Gameplay.Cell> maze) { GameObject finishTrigger = new GameObject("FinishTrigger"); finishTrigger.AddComponent <FinishPoint>(); finishTrigger.AddComponent <BoxCollider>().isTrigger = true; finishTrigger.transform.parent = mazeObject.transform; if (maze.Exit.Position.x >= maze.Exit.Position.y) { finishTrigger.transform.position = new Vector3((2 * maze.Exit.Position.x + 4) * maze.CellSize - 2 * maze.CellSize, 1.0f, (2 * maze.Exit.Position.y + 1) * maze.CellSize); finishTrigger.transform.localScale = new Vector3(.5f * maze.CellSize, 2.0f * maze.CellSize, 1.5f * maze.CellSize); } else { finishTrigger.transform.position = new Vector3((2 * maze.Exit.Position.x + 1) * maze.CellSize, 1.0f, (2 * maze.Exit.Position.y + 4) * maze.CellSize - 2 * maze.CellSize); finishTrigger.transform.localScale = new Vector3(1.5f * maze.CellSize, 2.0f * maze.CellSize, maze.CellSize * 0.5f); } }
void CreateMaze(Gameplay.Maze <Gameplay.Cell> maze) { mazeObject = new GameObject("Labyrinth"); mazeObject.AddComponent <Maze>(); CreateFloor(maze); // Create walls in the diagonal part of the maze. for (int i = 0; i < maze.Length; i++) { if (maze[i, i].HasWall(Gameplay.Wall.Left)) { CreateWall(maze, new Vector3((2 * i + 1) * maze.CellSize, 2.0f, 2 * i * maze.CellSize), new Vector3(90.0f, 90.0f, 0.0f)); } if (maze[i, i].HasWall(Gameplay.Wall.Down)) { CreateWall(maze, new Vector3((2 * i + 2) * maze.CellSize, 2.0f, (2 * i + 1) * maze.CellSize), new Vector3(90.0f, 0.0f, 0.0f)); } if (maze [i, i].HasWall(Gameplay.Wall.Up)) { CreateWall(maze, new Vector3(2 * i * maze.CellSize, 2.0f, (2 * i + 1) * maze.CellSize), new Vector3(90.0f, 0.0f, 180.0f)); } if (maze [i, i].HasWall(Gameplay.Wall.Right)) { CreateWall(maze, new Vector3((2 * i + 1) * maze.CellSize, 2.0f, (2 * i + 2) * maze.CellSize), new Vector3(90.0f, -90.0f, 0.0f)); } } for (int i = 0; i < maze.Length; i++) { for (int j = i + 1; j < maze.Width; j++) { // Create walls and chests in the lower triangular part of the maze. if (maze[j, i].HasWall(Gameplay.Wall.Left)) { CreateWall(maze, new Vector3((2 * j + 1) * maze.CellSize, 2.0f, 2 * i * maze.CellSize), new Vector3(90.0f, 90.0f, 0.0f)); } if (maze[j, i].HasWall(Gameplay.Wall.Down)) { CreateWall(maze, new Vector3((2 * j + 2) * maze.CellSize, 2.0f, (2 * i + 1) * maze.CellSize), new Vector3(90.0f, 0.0f, 0.0f)); } if (maze[j, i].HasChest) { CreateChest(maze, j, i); mazeObject.GetComponent <Maze>().NChests++; } // Create walls in the upper triangular part of the maze. if (maze [i, j].HasWall(Gameplay.Wall.Up)) { CreateWall(maze, new Vector3(2 * i * maze.CellSize, 2.0f, (2 * j + 1) * maze.CellSize), new Vector3(90.0f, 0.0f, 180.0f)); } if (maze [i, j].HasWall(Gameplay.Wall.Right)) { CreateWall(maze, new Vector3((2 * i + 1) * maze.CellSize, 2.0f, (2 * j + 2) * maze.CellSize), new Vector3(90.0f, -90.0f, 0.0f)); } if (maze[i, j].HasChest) { CreateChest(maze, i, j); mazeObject.GetComponent <Maze>().NChests++; } } } CreateFinish(maze); Core.EventManager.Instance.QueueEvent(new Events.MazeRendered(mazeObject.GetComponent <Maze>())); GameObject.Destroy(gameObject); }
static public void Render(Gameplay.Maze <Gameplay.Cell> maze, string display) { string [,] asciiMaze = new string[2 * maze.Length + 1, 2 * maze.Width + 1]; for (int i = 0; i <= 2 * maze.Length; i++) { for (int j = 0; j <= 2 * maze.Width; j++) { if (i % 2 == 0 && j % 2 == 0) { asciiMaze[i, j] = display; } else { asciiMaze[i, j] = " "; } } } for (int i = 0; i < maze.Length; i++) { if (maze[i, i].HasWall(Gameplay.Wall.Left)) { asciiMaze[2 * i + 1, 2 * i] = display; } if (maze[i, i].HasWall(Gameplay.Wall.Down)) { asciiMaze[2 * i + 2, 2 * i + 1] = display; } if (maze [i, i].HasWall(Gameplay.Wall.Up)) { asciiMaze[2 * i, 2 * i + 1] = display; } if (maze [i, i].HasWall(Gameplay.Wall.Right)) { asciiMaze[2 * i + 1, 2 * i + 2] = display; } } for (int i = 0; i < maze.Length; i++) { for (int j = i + 1; j < maze.Width; j++) { if (maze[j, i].HasWall(Gameplay.Wall.Left)) { asciiMaze[2 * j + 1, 2 * i] = display; } if (maze[j, i].HasWall(Gameplay.Wall.Down)) { asciiMaze[2 * j + 2, 2 * i + 1] = display; } if (maze[j, i].HasChest) { asciiMaze[2 * j + 1, 2 * i + 1] = "o"; } if (maze [i, j].HasWall(Gameplay.Wall.Up)) { asciiMaze[2 * i, 2 * j + 1] = display; } if (maze [i, j].HasWall(Gameplay.Wall.Right)) { asciiMaze[2 * i + 1, 2 * j + 2] = display; } if (maze[i, j].HasChest) { asciiMaze[2 * i + 1, 2 * j + 1] = "o"; } } } using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Directory.GetCurrentDirectory() + "\\maze.txt")) { for (int i = 0; i < 2 * maze.Length + 1; i++) { string line = ""; for (int j = 0; j < 2 * maze.Width + 1; j++) { line += asciiMaze[i, j]; } file.WriteLine(line); } } }