// Use this for initialization public void Initialize(int width, int height, Director director) { this.director = director; UniqueObjects = new bool[width, height]; features = new Dictionary <FeatureName, Feature>(); Width = width; Height = height; MazeGeneration generator = new MazeGeneration(width, height); Map = generator.Generation(); // Origin = transform.parent.position; Origin = new Vector3(-width / 2.0f, 0, -height / 2.0f); BallPrefab = (GameObject)Resources.Load("Prefabs/Maze/Ball"); //TilePrefab = (GameObject)Resources.Load("Prefabs/Maze/PlatformTile"); PlatformPrefab = (GameObject)Resources.Load("Prefabs/Maze/Platform"); Platform = Instantiate(PlatformPrefab, new Vector3(0, 0, 0), Quaternion.identity); Platform.transform.localScale = new Vector3(width, (float)0.1, height); Ceiling = Instantiate(PlatformPrefab, new Vector3(0, 1, 0), Quaternion.identity); Ceiling.transform.localScale = new Vector3(width, (float)0.1, height); Destroy(Ceiling.GetComponent <MeshRenderer>()); Platform.transform.SetParent(transform); Ceiling.transform.SetParent(transform); InitializeFeatures(); BuildFeatures(); Ball = Instantiate(BallPrefab, CoordsToPosition(StartX, StartY, 0.5f, 0.5f, 0.5f), Quaternion.identity); }
bool isValidWall(int[,] maze,int x,int y) { mazeFile = GameObject.FindGameObjectWithTag(Tags.maze).GetComponent<MazeGeneration>(); if(maze[y,x] == 0)//0 is for wall, 1 is for path return true; return false; }
void Start() { maze = GameObject.FindGameObjectWithTag("Maze").GetComponent <MazeGeneration> (); validNeighbors = new List <string> (); waitTime = 0f; currentDirection = NORTH; checkNeighbors(); }
// Use this for initialization void Start() { maze = GameObject.FindGameObjectWithTag("Maze").GetComponent <MazeGeneration> (); pathFound = false; validNeighbors = new List <string> (); pathHistory = new Stack(); //findPath (); //drawSolution (); }
private void Awake() { maze = FindObjectOfType <MazeGeneration>(); renderer = GetComponentInChildren <MeshRenderer>(); targetVisual = GameObject.CreatePrimitive(PrimitiveType.Cube); targetVisual.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); targetVisual.GetComponent <MeshRenderer>().material.color = renderer.material.color; line = GetComponent <LineRenderer>(); line.material.color = renderer.material.color; line.material.color = renderer.material.color; }
private int radius; //this will be the number of cells around the player get lit up void Start() { maze = GameObject.FindGameObjectWithTag("Maze").GetComponent <MazeGeneration>(); cells = GameObject.FindGameObjectsWithTag("VisitedCell"); iceColor = new Color32(109, 163, 249, 255); radius = 1; //the grid size will be radius+2. e.g. if radius is 1, the grid around the player will be a 3x3 lightNeighbors(); foreach (GameObject cell in cells) { cell.tag = "Cell"; SpriteRenderer cellSprite = cell.GetComponent <SpriteRenderer> (); cell.GetComponent <CellManagement> ().visited = false; cellSprite.color = Color.black; } }
public void GenerateLevels() { this.Reset(); List <MazeCell[, ]> levels = new List <MazeCell[, ]>(floors); for (int i = 0; i < floors; i++) { MazeCell[,] floor = MazeGeneration.GenerateMaze(width, height); levels.Add(floor); } MazeGeneration.GenerateFloorPassages(levels); this.InstantiateLevels(levels); }
void Start() { movementSpeed = 5; seconds = 1f; iceColor = new Color32(109, 163, 249, 255); markColor = new Color32(244, 188, 66, 255); maze = GameObject.FindGameObjectWithTag("Maze").GetComponent <MazeGeneration> (); hit = GetComponent <SpriteRenderer> (); GameObject[] bullets = new GameObject [10]; for (int i = 0; i < 10; i++) { bullets [i] = Instantiate(bulletPrefab, transform.position, Quaternion.identity, transform); bullets[i].tag = "ShieldFish"; bullets [i].transform.localScale = new Vector3(0.66f, 0.66f, 0.66f); Destroy(bullets [i].GetComponent <BulletMovement> ()); } StartCoroutine(spawnShield(bullets, 0.05f)); }
/// <summary> /// /// </summary> public override void OnStart() { Camera.Main.Position = Vector2.Zero; //检查资源文件数量 Resource.Init(); Debug.Log("查找目录Resouce,资源数量:" + Resource.Name_Path.Keys.Count); //开启贴图转换器 GDI渲染可用,使用贴图文件代替原字符显示 ImageConvertor.Init(); //创建角色 SRPGAgent wizardAgent = GameObject.CreateWith <SRPGAgent>(); wizardAgent.LocalPosition = new Vector2(12, 12); //创建系统监视器 SystemUIFactroy.GetSystemInspector(new Vector2(28, 13)); //创建迷宫地图 var maze = MazeGeneration.GetMaze(21, 21, new RenderPoint("■", Color.White, Config.DefaultBackColor, (int)Layer.Environment)); maze.Position = new Vector2(5, 5); }
//Works as a constructor void OnEnable() { //Set tooltips biasTooltip = new GUIContent("Bias Value", "Positive values bias towards horizontal, negative towards vertical"); wallRemovalTT = new GUIContent("Remove Selected Walls", "Remove the walls of a base layout that are selected in the scene window. \nCells either side of the wall can't be connected to the rest of the maze"); doorwayTT = new GUIContent("Designate Doorway", "Remove the walls of a base layout that are selected in the scene window. \nCells either side of the wall are able to be connected to the maze"); genWRoomsTT = new GUIContent("Generate With Rooms", "Generate a maze that includes user defined rooms. \nRequires Base Layout.\nUses width and depth defined during base layout creation"); generateTT = new GUIContent("Generate New Maze", "Creates a new maze, does not require a base layout to be created."); headerStyle = new GUIStyle(); showBiasFields = new AnimBool(); generator = new MazeGeneration(); param = new stats() { dBCurve = defineCurve(), useBias = false, wallMat = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Diffuse.mat"), floorMat = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Diffuse.mat") }; }
/// <summary> /// 在场景中创建对象 /// </summary> public override void OnStart() { //主角位于原点 GameObject player = TPSFactroy.CreateStandardPlayer("吊", new Vector2(0, 0)); GameObject.CreateWith <CameraController>().followTrans = player; player.AddComponent <Shooter>(); //创建迷宫地图 位于第三象限 var maze = MazeGeneration.GetMaze(21, 21, new RenderPoint("■", Color.White, Config.DefaultBackColor, (int)Layer.Environment)); maze.Position = new Vector2(-25, -25); //俄罗斯方块位于第一象限 for (int x = 5; x < 20; x += 5) { for (int y = 5; y < 20; y += 5) { TPSFactroy.CreateBox(new Vector2(x, y)); } } //系统指示器 位于右上角 SystemUIFactroy.GetSystemInspector(); //左侧的三个UI组件 TPSFactroy.CreateTestLable(new Vector2(0, 26)); ListBox gunBox = UIFactroy.CreateListBox(new Vector2(0, 15), 5, 10); gunBox.AddComponent <GunBox>(); var gunUI = UIFactroy.CreateTextBox(new Vector2(0, 21), 3, 10); gunUI.AddComponent <GunUI>(); }
void connectWalls(int[,] maze) { mazeFile = GameObject.FindGameObjectWithTag(Tags.maze).GetComponent<MazeGeneration>(); int maxLength = mazeFile.mazeLength * 2 + 1; int maxWidth = mazeFile.mazeWidth * 2 + 1; int j = (int)this.transform.position.y; int i = (int)this.transform.position.x; //You don't need down or left functions because you can clear everything with just up and right. if(j + 1 < maxLength && isValidWall(maze,i,(j + 1))) { createConnectMesh(direction.up); } if(i + 1 < maxWidth && isValidWall(maze,(i + 1),j)) { createConnectMesh(direction.right); } }
// Generates the maze procedurally private void generateMaze(MazeGeneration.Algorithm algorithm) { // Generate a maze Point exit, entrance; tiles = MazeGeneration.generateMaze(algorithm, mazeWidth, mazeHeight, out entrance, out exit); // Set the exit and entrance image Dispatcher.Invoke(() => { Grid.SetColumn(entranceImage, (int)entrance.X); Grid.SetRow(entranceImage, (int)entrance.Y); Grid.SetColumn(exitImage, (int)exit.X); Grid.SetRow(exitImage, (int)exit.Y); }); // Update the maze grid updateGrid(); }
void Start() { ScoreMaze = GetComponent <MazeGeneration>(); }
// Use this for initialization void Start() { currentX = (int)(transform.position.x + 0.5f); currentY = (int)(transform.position.y + 0.5f); maze = GameObject.FindGameObjectWithTag("Maze").GetComponent <MazeGeneration> (); }
// Use this for initialization void Awake() { mesh = GetComponent<MeshFilter>().mesh; mazeFile = GameObject.FindGameObjectWithTag(Tags.maze).GetComponent<MazeGeneration>(); scale = mazeFile.scale; int[,] mazeData = mazeFile.getMaze(); connectWalls(mazeData); if(mesh.vertices.Length > 6) { gameObject.AddComponent<PolygonCollider2D>(); PolygonCollider2D polyColl = gameObject.GetComponent<PolygonCollider2D>(); List<Vector2> verts = new List<Vector2>(); verts.Add(mesh.vertices[4]); verts.Add(mesh.vertices[5]); verts.Add(mesh.vertices[1]); verts.Add(mesh.vertices[6]); verts.Add(mesh.vertices[7]); verts.Add(mesh.vertices[0]); polyColl.SetPath(0,verts.ToArray()); } else gameObject.AddComponent<BoxCollider2D>(); }
void GenerateMazes() { if (rng.Seed == 1) { Mazes = new List <string[, ]> { new string[5, 5] { { "U L", "U", "N D R", "L U", "U R" }, { "L R", "D L ", "U", "D R", "L R" }, { "L D", "U R", "L D", "U R", "L D R" }, { "L U", "R", "L U R", "D L", "U R" }, { "D L R", "L D", "D R", "D U L", "R D" } }, new string[5, 5] { { "U D L", "U R", "N R L", "U L", "U R" }, { "U L", "D", "R D", "R L", "R D L" }, { "L", "U", "U D", "D", "U R" }, { "R L", "R D L", "U R L", "U D L", "R" }, { "D L", "U D", "R D", "U D L", "R D" } }, new string[5, 5] { { "U L", "U R D", "N L", "U R D", "L U R" }, { "L D", "U D", "D", "U D", "R" }, { "L U D", "U", "U", "U", "D R" }, { "L U R", "R L", "R L", "L D", "U R" }, { "D L", "D R", "L D", "U D R", "L R D" } }, new string[5, 5] { { "U L D", "U R", "L N D", "U", "U R" }, { "L U", "D", "D U", "D R", "L R" }, { "L", "U R", "U L", "U", "R D" }, { "L D R", "L R D", "R L", "L", "U R" }, { "D L U", "D U", " D R", "L D R", " L D R" } }, new string[5, 5] { { "U L", "U", "N D", "U R", "L U R" }, { "L D R", "L R", "L U R", "L D", "R" }, { "L U", "D", "D R", "L U", "D R" }, { "L R", "U D L", "R U", "D L", "R U" }, { "D L", "U D R", "D L", "U D", "R D" } }, new string[5, 5] { { "U L", "U R", "L D N", "U D", "U R" }, { "L R", "L", "U R D", "U L", "D R" }, { "L R", "L", "U D", "", "U R" }, { "L R D", "L R", "U L", "R D", "L R" }, { "D L U", "R D", "D L", "D U R", "L R D" } }, new string[5, 5] { { "U L", "U", "N D", "U D", "U R" }, { "L R", "L D R", "L U", "U R", "L R" }, { "L R", "U D L", "D R", "L", "R" }, { "L D", "U R", "U D L", "R D", "L R" }, { "D L U", "D", "D R U", "D L U", "R D" } }, new string[5, 5] { { "U L D", "U R", "R N L", "U L R", "L U R" }, { "L U", "R", "R L", "L", "D R" }, { "L R", "L D", "R", "L D", "U R" }, { "L R", "L R U", "L D", "U R", "L R" }, { "D L R", "L D", "U D", "D", "R D" } }, new string[5, 5] { { "U L", "U D", "N R", "U L", "U R D" }, { "L R", "U L", "D", "D", "U R" }, { "L R", "L D", "U R D", "U L D", "R" }, { "L D", "U R D", "U L", "U R", "L R" }, { "D L U", "U D", "D R", "L D", "R D" } }, new string[5, 5] { { "U L R", "L U D", "N R", "L U", "U R" }, { "L D", "U R", "L R", "L R", "L R D" }, { "L U R", "D L", "D", "", "D R" }, { "L", "U R", "U L", "", "U D R" }, { "D L R", "D L", "D R", "D", "U R D" } } }; } else { Mazes = new List <string[, ]>(); MazeGeneration.InitializeGeneration(); var cardinal = new[] { "N", "E", "W", "S" }; var direction = new[] { "U", "R", "L", "D" }; for (var i = 0; i < 10; i++) { Mazes.Add(Enumerable.Range(0, 5).SelectMany(r => Enumerable.Range(0, 5).Select(c => Enumerable.Range(0, 4).Select(d => (!MazeGeneration.Cells[i, r, c][cardinal[d]]) ? direction[d] : "").Join(" "))).ToArray().ToArray2D(5, 5)); } } }