Any good procedural generated maze for 2d out there?
I have been following this tutorial on how to do a 2d procedurally generated maze. Everything works except the floor, Unity only generates one tile of flooring. The code is as follows: > using UnityEngine; using System.Collections; public class MazeGenerator : MonoBehaviour { public static MazeGenerator instance; public int mazeWidth; public int mazeHeight; public string mazeSeed; public Sprite floorSprite; public Sprite roofSprite; public Sprite wallSprite; public Sprite wallCornerSprite; %|1306176897_9|% System.Random mazeRG; %|-1616251492_11|% void Awake(){ instance = this; } // Use this for initialization void Start () { mazeRG = new System.Random (mazeSeed.GetHashCode ()); if (mazeWidth % 2 == 0) mazeWidth++; if (mazeHeight % 2 == 0) { mazeHeight++; } %|1992438454_23|% %|-2076574539_24|% DrawMaze (); } %|1889525127_27|% for (int x = 0; x < mazeWidth; x++) { for (int y = 0; y < mazeHeight; y++) { Vector3 position = new Vector3 (x, y); if (maze.Grid [x, y] == true) { CreateMazeSprite (position, floorSprite, transform, 0, mazeRG.Next (0, 3) * 90); } else { CreateMazeSprite (position, roofSprite, transform, 0, 0); DrawWalls (x, y); } } } } %|-1187971670_40|% bool top = GetMazeGridCell (x, y + 1); bool bottom = GetMazeGridCell (x, y - 1); bool right = GetMazeGridCell (x + 1, y); bool left = GetMazeGridCell (x - 1, y); Vector3 position = new Vector3 (x, y); if (top) { CreateMazeSprite (position, wallSprite, transform, 1, 0); } if (left) { CreateMazeSprite (position, wallSprite, transform, 1, 90); %|93463105_51|% if (bottom) { CreateMazeSprite (position, wallSprite, transform, 1, 180); } if (right) { CreateMazeSprite (position, wallSprite, transform, 1, 270); } if (!left && !top && x > 0 && y < mazeHeight - 1) { CreateMazeSprite (position, wallCornerSprite, transform, 2, 0); } if (!left && !bottom && x > 0 && y > 0) { CreateMazeSprite (position, wallCornerSprite, transform, 2, 90); } if (!right && !bottom && x < mazeWidth - 1 && y > 0) { CreateMazeSprite (position, wallCornerSprite, transform, 2, 180); } if (!right && !top && x < mazeWidth - 1 && y < mazeHeight - 1) { CreateMazeSprite (position, wallCornerSprite, transform, 2, 270); } } public bool GetMazeGridCell(int x, int y){ if (x >= mazeWidth || x < 0 || y >= mazeHeight || y < 0) { return false; } return maze.Grid [x, y]; %|107106601_76|% %|-47541969_77|% %|1152598341_78|% mazeSprite.SetSprite (sprite, sortingOrder); mazeSprite.transform.SetParent (parent); mazeSprite.transform.Rotate (0, 0, rotation); } // Update is called once per frame %|1493662969_84|% %|1783827749_85|% } }
Any suggestions on how to generate more of the floor?
Thanks,
Your answer
Follow this Question
Related Questions
Game lagging when the map generates a new chunk 0 Answers
Spawn Procedural Planet at parent's position 0 Answers
How to randomly create a tile based maze 0 Answers
How to spawn in loop like snail but in square 0 Answers
Unity hangs but code keeps running 1 Answer