void Start () { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator (Rows, Columns); break; } mMazeGenerator.GenerateMaze (); for (int row = 0; row < Rows; row++) { for(int column = 0; column < Columns; column++){ float x = column*(CellWidth+(AddGaps?.2f:0)); float z = row*(CellHeight+(AddGaps?.2f:0)); MazeCell cell = mMazeGenerator.GetMazeCell(row,column); GameObject tmp; tmp = Instantiate(Floor,new Vector3(x,0,z), Quaternion.Euler(0,0,0)) as GameObject; tmp.transform.parent = transform; if(cell.WallRight){ tmp = Instantiate(Wall,new Vector3(x+CellWidth/2,0,z)+Wall.transform.position,Quaternion.Euler(0,90,0)) as GameObject;// right tmp.transform.parent = transform; } if(cell.WallFront){ tmp = Instantiate(Wall,new Vector3(x,0,z+CellHeight/2)+Wall.transform.position,Quaternion.Euler(0,0,0)) as GameObject;// front tmp.transform.parent = transform; } if(cell.WallLeft){ tmp = Instantiate(Wall,new Vector3(x-CellWidth/2,0,z)+Wall.transform.position,Quaternion.Euler(0,270,0)) as GameObject;// left tmp.transform.parent = transform; } if(cell.WallBack){ tmp = Instantiate(Wall,new Vector3(x,0,z-CellHeight/2)+Wall.transform.position,Quaternion.Euler(0,180,0)) as GameObject;// back tmp.transform.parent = transform; } if (row == Rows-1 && column == Columns-1) { if (cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } } gameObject.transform.Rotate(0f, -45f, 0f); }
void Start() { _waypointsHolder = new GameObject("_waypointsHolder"); _waypointsHolder.transform.SetParent(transform); GameObject coinsHolder = new GameObject("_coinsHolder"); coinsHolder.transform.SetParent(transform); GameObject wallsHolder = new GameObject("_wallsHolder"); wallsHolder.transform.SetParent(transform); GameObject floorHolder = new GameObject("_floorHolder"); floorHolder.transform.SetParent(transform); GameObject pillarsHolder = new GameObject("_pillarsHolder"); pillarsHolder.transform.SetParent(transform); if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } int coinsPlaced = 0; mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = transform.position.x + column * (CellWidth + (AddGaps ? .2f : 0)); float z = transform.position.z + row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = floorHolder.transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = wallsHolder.transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = wallsHolder.transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = wallsHolder.transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = wallsHolder.transform; } if (cell.IsGoal && _coinPrefab != null && Coin.NumOfCoinsCreated < numOfCoinToPass) { Coin coin = Instantiate(_coinPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)); coin.transform.SetParent(coinsHolder.transform); Coin.NumOfCoinsCreated++; } else { if (!_keyExists && _keyPrefab != null) { Key key = Instantiate(_keyPrefab, new Vector3(x, _waypointHeight, z), _keyPrefab.transform.rotation); key.transform.SetParent(transform); _keyExists = true; } else if (_waypointPrefab != null) { Waypoint wp = Instantiate(_waypointPrefab, new Vector3(x, _waypointHeight, z), Quaternion.identity); wp.transform.SetParent(_waypointsHolder.transform); } } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = transform.position.x + column * (CellWidth + (AddGaps ? .2f : 0)); float z = transform.position.z + row * (CellHeight + (AddGaps ? .2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity); tmp.transform.parent = pillarsHolder.transform; if (row != 0 && column != 0 && row != Rows && column != Columns) { tmp.transform.GetChild(1).gameObject.SetActive(false); } } } } }
void Start() { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps ? 0.2f : 0)); float z = row * (CellHeight + (AddGaps ? 0.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } /* * if (cell.IsGoal && GoalPrefab != null) { * tmp = Instantiate (GoalPrefab, new Vector3 (x, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * } * if (cell.IsGoal && GoalPrefab2 != null) { * tmp = Instantiate (GoalPrefab2, new Vector3 (1, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * } * if (cell.IsGoal && GoalPrefab3 != null) { * tmp = Instantiate (GoalPrefab3, new Vector3 (2, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * } * if (cell.IsGoal && GoalPrefab4 != null) { * tmp = Instantiate (GoalPrefab4, new Vector3 (3, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * } * if (cell.IsGoal && GoalPrefab5 != null) { * tmp = Instantiate (GoalPrefab5, new Vector3 (4, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * } * if (cell.IsGoal && GoalPrefab6 != null) { * tmp = Instantiate (GoalPrefab6, new Vector3 (5, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * } * if (cell.IsGoal && GoalPrefab7 != null) { * tmp = Instantiate (GoalPrefab7, new Vector3 (6, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * } * if (cell.IsGoal && GoalPrefab8 != null) { * tmp = Instantiate (GoalPrefab8, new Vector3 (7, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * } */ } } bool[] usado = new bool[Columns * Rows + 9]; usado [0] = true; for (int i = 0; i < 8; i++) { for (int j = 0; j < 1; j++) { int c = Random.Range(0, Columns); int r = Random.Range(0, Rows); while (usado [c * Rows + r]) { c = Random.Range(0, Columns); // + CellWidth / 2.0f; r = Random.Range(0, Rows); // + CellHeight / 2.0f; } int w = (int)(c * CellWidth); // + CellWidth / 2.0f; int h = (int)(r * CellHeight); // + CellHeight / 2.0f; usado [(int)(c * Rows + r)] = true; GameObject tmp = Instantiate(Monedas [i], new Vector3(h, 1, w), Quaternion.Euler(0, 0, 0)) as GameObject; } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?0.2f:0)); float z = row * (CellHeight + (AddGaps?0.2f:0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }
void Awake() { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; tmp.transform.localScale = new Vector3(6.5f, 0.10f, 6.5f); Wall.transform.localScale = new Vector3(1.72f, 2.5f, 1.6f); if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + 0.1f + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + 0.1f + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - 0.1f - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - 0.1f - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; tmp.transform.localScale = new Vector3(1.5f, 2.0f, 1.5f); tmp.SetActive(false); } } } this.transform.localScale = new Vector3(2.0f, 1.0f, 2.0f); this.transform.position = new Vector3(-58.6f, 0.0f, -61.0f); GameObject initWall = FindAt(new Vector3(-64.8f, 2.5f, -61.0f)); if (initWall != null) { initWall.SetActive(false); } GameObject finishWall = FindAt(new Vector3(59.2f, 2.5f, 50.6f)); if (finishWall != null) { finishWall.tag = "finish"; Renderer rend = finishWall.GetComponent <Renderer>(); MeshCollider myMesh = finishWall.GetComponent <MeshCollider>(); myMesh.convex = true; myMesh.isTrigger = true; rend.enabled = false; //finishWall.SetActive(false); } }
public void SpawnMaze() { switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); floorTiles = new GameObject[Rows, Columns]; for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); //cell.RemoveByChance(.8f); MazeNode node = new MazeNode(cell, row, column); GameObject tmp; floorTiles[row, column] = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; floorTiles[row, column].name = "Floor_R" + row + "C" + column; floorTiles[row, column].transform.parent = transform; OnMazeCellCreated?.Invoke(node, floorTiles[row, column].GetComponent <TileInteraction>()); if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }
// Update is called once per frame public void SpawnMaze(int Columns, int Rows) { m_SoGoc = 0; isSaved = false; //m_NumOfBanaka = LevelController.GetComponent<LevelController>().m_Level; isBakanaSpawned = false; if (!FullRandom) { Random.seed = RandomSeed; } switch (esc) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = Parent.transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;// right tmp.transform.parent = Parent.transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;// front tmp.transform.parent = Parent.transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;// left tmp.transform.parent = Parent.transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;// back tmp.transform.parent = Parent.transform; } if (cell.IsGoal && GoalPrefab != null && !isBakanaSpawned) { m_SoGoc++; if (m_SoGoc > caseSummon()) { summonBakana(GoalPrefab, x, z); } } } } //if (Pillar != null) //{ // for (int row = 0; row < Rows + 1; row++) // { // for (int column = 0; column < Columns + 1; column++) // { // float x = column * (CellWidth + (AddGaps ? .2f : 0)); // float z = row * (CellHeight + (AddGaps ? .2f : 0)); // GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; // tmp.transform.parent = Parent.transform; // } // } //} if (!isBakanaSpawned) { Debug.Log("Re-Spawn!"); deleteAllChild(); SpawnMaze(Columns, Rows); } spawnOutDoor(m_BasicColumns, m_BasicRows, GoalPrefab); }
void Start() { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;// right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;// front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;// left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;// back tmp.transform.parent = transform; } if (cell.IsSeaweed && SeaweedPrefab != null) { tmp = Instantiate(SeaweedPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } if (cell.IsLantern && LanternPrefab != null) { tmp = Instantiate(LanternPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } if (cell.IsRock && RockPrefab != null) { tmp = Instantiate(RockPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } /*if (Pillar != null) * { * for (int row = 0; row < Rows + 1; row++) * { * for (int column = 0; column < Columns + 1; column++) * { * float x = column * (CellWidth + (AddGaps ? .2f : 0)); * float z = row * (CellHeight + (AddGaps ? .2f : 0)); * GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; * tmp.transform.parent = transform; * } * } * }*/ }
void Awake() { _GoalSlotCount = 0; List <Vector3> _GoalPosList = new List <Vector3>(); List <OpenPort> _GoalDirList = new List <OpenPort>(); if (!FullRandom) { Random.InitState(RandomSeed); } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); int _OpenPortMagicNum = 0; MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; _OpenPortMagicNum += 1; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; _OpenPortMagicNum += 3; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; _OpenPortMagicNum += 5; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; _OpenPortMagicNum += 7; } if (cell.IsGoal) { _GoalSlotCount += 1; _GoalPosList.Add(new Vector3(x, 1, z)); if (_OpenPortMagicNum == (3 + 5 + 7)) { _GoalDirList.Add(OpenPort.Right); } else if (_OpenPortMagicNum == (1 + 5 + 7)) { _GoalDirList.Add(OpenPort.Front); } else if (_OpenPortMagicNum == (1 + 3 + 7)) { _GoalDirList.Add(OpenPort.Left); } else if (_OpenPortMagicNum == (1 + 3 + 5)) { _GoalDirList.Add(OpenPort.Back); } else { _GoalDirList.Add(OpenPort.Front); } } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } var actor_index_list = Utilities.GetRandomIntList(0, ActorList.Count); var goal_slot_index_list = Utilities.GetRandomIntList(0, _GoalPosList.Count); for (int i = 0; i < actor_index_list.Count; i++) { int actor_index = actor_index_list[i]; int goal_slot_index = goal_slot_index_list[i]; GameObject tmp; Quaternion quat = Quaternion.identity; if (_GoalDirList[goal_slot_index] == OpenPort.Back) { quat = Quaternion.Euler(0, 180f, 0); } else if (_GoalDirList[goal_slot_index] == OpenPort.Front) { quat = Quaternion.Euler(0, 0, 0); } else if (_GoalDirList[goal_slot_index] == OpenPort.Left) { quat = Quaternion.Euler(0, -90f, 0); } else if (_GoalDirList[goal_slot_index] == OpenPort.Right) { quat = Quaternion.Euler(0, 90f, 0); } tmp = Instantiate(ActorList[actor_index], _GoalPosList[goal_slot_index], quat) as GameObject; tmp.transform.parent = transform; } mGameStateManager.StartGame(); }
void Start() { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; // tmp = Instantiate(Floor,new Vector3(x,0,z), Quaternion.Euler(0,0,0)) as GameObject; // tmp.transform.parent = transform; if (cell.WallRight) { if (column == Columns - 1) { tmp = Instantiate(OuterWall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } else { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } } if (cell.WallFront) { if (row == Rows - 1) { tmp = Instantiate(OuterWall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } else { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } } if (cell.WallLeft) { if (column == 0) { tmp = Instantiate(OuterWall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } else { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } } if (cell.WallBack) { if (row == 0) { tmp = Instantiate(OuterWall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } else { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } } if (cell.IsGoal) { var pick = Random.value; if (pick > .6) { tmp = Instantiate(BombPrefab, new Vector3(x, 1, z), Quaternion.Euler(90, 0, 0)) as GameObject; tmp.transform.parent = transform; } else if (pick > .4) { tmp = Instantiate(PlayerWallPrefab, new Vector3(x, 1, z), Quaternion.Euler(90, 0, 0)) as GameObject; tmp.transform.parent = transform; } else if (pick > .2) { tmp = Instantiate(HourglassPrefab, new Vector3(x, 1, z), Quaternion.Euler(90, 0, 0)) as GameObject; tmp.transform.parent = transform; } else if (pick > 0 && bhCount == 0) { tmp = Instantiate(BlackholePrefab, new Vector3(x, 1, z), Quaternion.Euler(90, 0, 0)) as GameObject; tmp.transform.parent = transform; bhCount++; } // switch (Random.Range(0,3)) { // case 0: // tmp = Instantiate(HourglassPrefab,new Vector3(x,1,z), Quaternion.Euler(90,0,0)) as GameObject; // tmp.transform.parent = transform; // break; // case 1: // tmp = Instantiate(BombPrefab,new Vector3(x,1,z), Quaternion.Euler(90,0,0)) as GameObject; // tmp.transform.parent = transform; // break; // case 2: // tmp = Instantiate(PlayerWallPrefab,new Vector3(x,1,z), Quaternion.Euler(90,0,0)) as GameObject; // tmp.transform.parent = transform; // break; // case 3: // if(bhCount == 0) { // tmp = Instantiate(BlackholePrefab,new Vector3(x,1,z), Quaternion.Euler(90,0,0)) as GameObject; // tmp.transform.parent = transform; // bhCount++; // } // break; // } } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } StartCoroutine(MazeChange()); }
public void aaa(int Columns, int Rows, bool FullRandom, int RandomSeed, MazeGenerationAlgorithm Algorithm, BasicMazeGenerator mazeGenerator, float CellWidth, float CellHeight, bool AddGaps, GameObject Floor, GameObject Wall, GameObject Pillar, GameObject goalPrefabs) { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;// right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;// front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;// left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;// back tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }
void Start() { // enteredLabyrinth let us know, whether the player enters the maze for the first time. if (PlayerPrefs.GetInt("enteredLabyrinth", 0) != null) { enteredLabyrinth = PlayerPrefs.GetInt("enteredLabyrinth", 0) != 0; } // If the player enters the maze for the first time, the new maze will be generated, after iterative entering the previous generated model will be presented. if (!enteredLabyrinth) { if (!FullRandom) { Random.seed = RandomSeed; } mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); mMazeGenerator.GenerateMaze(); } for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps? .2f : 0)); float z = row * (CellHeight + (AddGaps? .2f : 0)); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; tmp.name = "Floor_Column" + column.ToString() + "_Row" + row.ToString(); string wallDirection = "Wall_At_Column" + column.ToString() + "_Row" + row.ToString(); if (!enteredLabyrinth) // this is required to save directions of walls per cell. { MazeCell cell = mMazeGenerator.GetMazeCell(row, column); PlayerPrefs.SetInt(wallDirection + "_Right", cell.WallRight ? 1 : 0); PlayerPrefs.SetInt(wallDirection + "_Front", cell.WallFront ? 1 : 0); PlayerPrefs.SetInt(wallDirection + "_Left", cell.WallLeft ? 1 : 0); PlayerPrefs.SetInt(wallDirection + "_Back", cell.WallBack ? 1 : 0); } WallPlacement wallPlacement; // so once directions of walls per cell are saved, next time the player enters the maze, the same maze with the same wall directions per cell will be generated. wallPlacement.WallRight = PlayerPrefs.GetInt(wallDirection + "_Right", 0) != 0; wallPlacement.WallFront = PlayerPrefs.GetInt(wallDirection + "_Front", 0) != 0; wallPlacement.WallLeft = PlayerPrefs.GetInt(wallDirection + "_Left", 0) != 0; wallPlacement.WallBack = PlayerPrefs.GetInt(wallDirection + "_Back", 0) != 0; if (wallPlacement.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; tmp.GetComponent <Renderer> ().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; tmp.GetComponent <Renderer> ().receiveShadows = false; } if (wallPlacement.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; tmp.GetComponent <Renderer> ().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; tmp.GetComponent <Renderer> ().receiveShadows = false; } if (wallPlacement.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; tmp.GetComponent <Renderer> ().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; tmp.GetComponent <Renderer> ().receiveShadows = false; } if (wallPlacement.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; tmp.GetComponent <Renderer> ().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; tmp.GetComponent <Renderer> ().receiveShadows = false; } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps? .2f : 0)); float z = row * (CellHeight + (AddGaps? .2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; tmp.GetComponent <Renderer> ().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; tmp.GetComponent <Renderer> ().receiveShadows = false; } } } enteredLabyrinth = true; PlayerPrefs.SetInt("enteredLabyrinth", enteredLabyrinth ? 1 : 0); if (PlayerPrefs.GetInt("RowsCount", 0) == 0 && PlayerPrefs.GetInt("ColumnsCount", 0) == 0) { PlayerPrefs.SetInt("RowsCount", Rows); PlayerPrefs.SetInt("ColumnsCount", Columns); } }
void Start() { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); int typeOfBot = 0; for (int row = 0; row < Rows; row++) { int randomColumn = Random.Range(3, 5); int randomColumn1 = Random.Range(8, 10); for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z - 0.9f), Quaternion.Euler(-90, 0, 0)) as GameObject; tmp.transform.parent = transform; tmp = Instantiate(Ceiling, new Vector3(x, 3.01f, z - 1), Quaternion.Euler(-90, 0, 0)) as GameObject; tmp.transform.parent = transform; tmp = Instantiate(Ceiling, new Vector3(x, 3.01f, z + 1), Quaternion.Euler(-90, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 1.5f, z) + Wall.transform.position, Quaternion.Euler(-90, 270, 0)) as GameObject;// right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 1.5f, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(-90, 180, 0)) as GameObject;// front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 1.5f, z) + Wall.transform.position, Quaternion.Euler(-90, 90, 0)) as GameObject;// left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 1.5f, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(-90, 0, 0)) as GameObject;// back tmp.transform.parent = transform; } if (row == Rows - 1 && column == Columns - 1) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(90, 0, 0)) as GameObject; tmp.transform.parent = transform; GoalPosition = tmp.transform.position; } if (typeOfBot % 3 == 0) { if (randomColumn == column) { tmp = Instantiate(ZombiePrefab, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } if (randomColumn1 == column) { tmp = Instantiate(SpiderPrefab, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } typeOfBot++; } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 1.5f, z - CellHeight / 2), Quaternion.Euler(-90, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } }
void Start() { CollectableManagerObject = GameObject.Find("Collectable Manager"); CollectableManagerScript = (CollectableManager)CollectableManagerObject.GetComponent(typeof(CollectableManager)); if (FullRandom) { Random.InitState(System.DateTime.Now.Millisecond); } else { Random.InitState(RandomSeed); } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (AddRoof) { tmp = Instantiate(Roof, new Vector3(x, 4, z), Quaternion.Euler(-90, 0, 0)) as GameObject; tmp.transform.parent = transform; } if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } else { int neighborColumn = column + 1; if (neighborColumn < Columns) { MazeCell neighborCell = mMazeGenerator.GetMazeCell(row, neighborColumn); if (!neighborCell.WallLeft) { PossibleDoorPositions.Add(new DoorPosition(new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0))); } } } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } else { int neighborRow = row + 1; if (neighborRow < Rows) { MazeCell neighborCell = mMazeGenerator.GetMazeCell(neighborRow, column); if (!neighborCell.WallBack) { PossibleDoorPositions.Add(new DoorPosition(new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0))); } } } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } else { int neighborColumn = column - 1; if (neighborColumn >= 0) { MazeCell neighborCell = mMazeGenerator.GetMazeCell(row, neighborColumn); if (!neighborCell.WallRight) { PossibleDoorPositions.Add(new DoorPosition(new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0))); } } } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } else { int neighborRow = row - 1; if (neighborRow >= 0) { MazeCell neighborCell = mMazeGenerator.GetMazeCell(neighborRow, column); if (!neighborCell.WallFront) { PossibleDoorPositions.Add(new DoorPosition(new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0))); } } } if (cell.IsGoal) { PossibleGoalCells.Add(new Vector3(x, 1.5f, z)); } else if (x > 2 && z > 2) { PossibleEnemyCells.Add(new Vector3(x, 1.5f, z)); } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } Random.InitState(System.DateTime.Now.Millisecond); for (int GoalCount = 0; GoalCount < 5; GoalCount++) { int rand = Random.Range(0, PossibleGoalCells.Count); Vector3 vector3 = PossibleGoalCells[rand]; PossibleGoalCells.RemoveAt(rand); //Add Goals GameObject GoalPrefab; switch (GoalCount) { case 0: GoalPrefab = CollectablePrefab1; break; case 1: GoalPrefab = CollectablePrefab2; break; case 2: GoalPrefab = CollectablePrefab3; break; case 3: GoalPrefab = CollectablePrefab4; break; case 4: GoalPrefab = CollectablePrefab5; break; default: GoalPrefab = CollectablePrefab1; break; } GameObject tmp = Instantiate(GoalPrefab, vector3, Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; CollectableManagerScript.Add(tmp); } if (DoorCount > 0) { for (int i = 0; i < DoorCount; i++) { int rand = Random.Range(0, PossibleDoorPositions.Count); DoorPosition doorPosition = PossibleDoorPositions[rand]; PossibleDoorPositions.RemoveAt(rand); GameObject tmp = Instantiate(DoorPrefab, doorPosition.Position, doorPosition.Rotation) as GameObject; tmp.transform.parent = transform; } } if (EnemyCount > 0) { for (int i = 0; i < EnemyCount; i++) { int rand = Random.Range(0, PossibleEnemyCells.Count); Vector3 vector3 = PossibleEnemyCells[rand]; PossibleEnemyCells.RemoveAt(rand); GameObject tmp = Instantiate(EnemyPrefab, vector3, Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } ParticleSystem fireWork1 = Instantiate(FireWorksParticleSystem, new Vector3(0, 0, 0), Quaternion.Euler(-90, 0, 0)) as ParticleSystem; fireWork1.transform.parent = transform; ParticleSystem fireWork2 = Instantiate(FireWorksParticleSystem, new Vector3(Rows * CellWidth, 0, 0), Quaternion.Euler(-90, 0, 0)); fireWork2.transform.parent = transform; ParticleSystem fireWork3 = Instantiate(FireWorksParticleSystem, new Vector3(0, 0, Columns * CellHeight), Quaternion.Euler(-90, 0, 0)); fireWork3.transform.parent = transform; ParticleSystem fireWork4 = Instantiate(FireWorksParticleSystem, new Vector3(Rows * CellWidth, 0, Columns * CellHeight), Quaternion.Euler(-90, 0, 0)); fireWork4.transform.parent = transform; FireWorks.Add(fireWork1); FireWorks.Add(fireWork2); FireWorks.Add(fireWork3); FireWorks.Add(fireWork4); }
void createMaze() { if (!FullRandom) { //Random.seed = RandomSeed; Random.InitState(RandomSeed); } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; if (row == SafeZone_Row && column == SafeZone_Col) { cell.floor = Instantiate(SafeZone, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; cell.IsGoal = true; } else { cell.floor = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; } cell.floor.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } /*if(cell.IsGoal && GoalPrefab != null){ * tmp = Instantiate(GoalPrefab,new Vector3(x,1,z), Quaternion.Euler(0,0,0)) as GameObject; * tmp.transform.parent = transform; * }*/ if (row == Child_Start_Row && column == Child_Start_Col) { agentA = Instantiate(ChildPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; } //if(row == Zombie_Start_Row && column == Zombie_Start_Col) // agentB = Instantiate(ZombiePrefab,new Vector3(x,1,z), Quaternion.Euler(0,0,0)) as GameObject; } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }
void Start() { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { // Modified by mohanad to choose if (Random.Range(1, 20) % 2 != 0) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; Num_Points++; } else { // 23 is an arbtrary value used as temp solution here. if (Num_Enemies == 0 || Num_Points < 23) { // Temp solution to prevent the enemy from spawning under the player at start of the game! tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; Num_Points++; Num_Enemies++; //print(Num_Goals); } else { Num_Enemies++; tmp = Instantiate(enemyPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; } //----------------------------- mohanad UpdateUITexts.instance.UpdatePointsText(Num_Points); //---------------------------------------------------- tmp.transform.parent = transform; } } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } navS.BuildNavMesh(); }
// Event on Button public void GenerateMaze() { buttonGenerate.interactable = false; allTargets.Clear(); DestroyAllChildren(); // Debug.Log("Started! "); var timer = System.Diagnostics.Stopwatch.StartNew(); if (!FullRandom) { // Random.seed = RandomSeed; Random.InitState(RandomSeed); } // Rows = Random.Range(10, 50); Columns = Rows; switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); Debug.Log("<Color=Red> This alghorithm is not supported for Dijkstra or Genetic ! </Color>"); break; } mMazeGenerator.GenerateMaze(); wholeMaze = mMazeGenerator.GetWholeMaze(); XfloatDistanceCellWidth = (CellWidth + (AddGaps ? .2f : 0)); ZfloatDistanceCellHeight = (CellHeight + (AddGaps ? .2f : 0)); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * XfloatDistanceCellWidth; // gaps between the walls and floor float z = row * ZfloatDistanceCellHeight; MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; cell.myMonoCell = tmp.GetComponent <NodeMono>(); tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;// right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;// front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;// left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;// back tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (tmp != null) { allTargets.Add(tmp); } } } } float differenceBetween = Vector3.Distance(mMazeGenerator.GetMazeCell(0, 0).myMonoCell.transform.position, mMazeGenerator.GetMazeCell(0, 1).myMonoCell.transform.position); diff = differenceBetween; usedGraph.nodes.Clear(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { MazeCell cell = mMazeGenerator.GetMazeCell(row, column); usedGraph.nodes.Add(cell.myMonoCell.MyNode); foreach (var item in cell.neighbor) { cell.myMonoCell.connections.Add(item.myMonoCell); } } } for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { MazeCell cell = mMazeGenerator.GetMazeCell(row, column); cell.myMonoCell.UpdateList(); } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } timer.Stop(); long elapsedMs = timer.ElapsedMilliseconds; Debug.Log(" All New! " + elapsedMs + "ms (1/1000 sec)"); // 4 ms switch (Algorithm) { case MazeGenerationAlgorithm.RecursiveDivision: return; // break; } StartCoroutine(waitAbit(buttonGenerate)); }
void Start() { CellHeight = CellWidth = Util.rowColumnHeightWidth; Rows = Mathf.Max(PlayerPrefs.GetInt("rowCount"), 3); Columns = Mathf.Max(PlayerPrefs.GetInt("colCount"), 3); Screen.orientation = ScreenOrientation.LandscapeLeft; Random.InitState(Random.Range(0, 10000)); switch (Algorithm) { case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * CellWidth; float z = row * CellHeight; MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; if (row == Rows - 1 && column == Columns - 1) { Util.initialCameraPosition = new Vector3(x, -yOffset - 0.16f, z) + new Vector3(0, 2, 0); Camera.main.transform.position = Util.initialCameraPosition; tmp = Instantiate(Floor, new Vector3(x, -yOffset - 0.16f, z), Quaternion.Euler(-180, 0, 0)) as GameObject; GameObject tmp1 = Instantiate(Target, new Vector3(x - 1f, yOffset - 0.5f, z + 0.5f), Quaternion.Euler(-75, -135, 0)) as GameObject; tmp1.transform.parent = transform; Util.lastFloorPosition = new Vector3(x - 1f, 0, z + 0.5f); } else if (Random.Range(10, 20) > 12 || (row == 0 & column == 0)) { if (Random.Range(0, 100) > 75 && row != 0 && column != 0) { powerUpSerial++; powerUpSerial %= 7; GameObject tmpPowerUp = Instantiate(PowerUpObject, new Vector3(x, yOffset - 0.5f, z), new Quaternion(0, 0, 0, 0)); tmpPowerUp.GetComponent <PowerUp>().powerUpCode = powerUpSerial; tmpPowerUp.transform.parent = transform; tmpPowerUp.GetComponent <MeshRenderer>().material.color = Util.powerUpColor[powerUpSerial]; } tmp = Instantiate(Floor, new Vector3(x, yOffset, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.name = row + "," + column; } else { tmp = Instantiate(FloorWithHole, new Vector3(x, -yOffset - 0.16f, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.localEulerAngles = new Vector3(0, 0, 180); tmp.transform.name = row + "," + column; } float colorRange = (float)(row + column) / (float)(Rows + Columns); tmp.GetComponent <MeshRenderer>().material.color = Color.HSVToRGB(colorRange, 0.73f, 0.96f); tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, -0.1f, z) + Wall.transform.position + Util.wallOffset, Quaternion.Euler(0, 90, 0)) as GameObject;// right tmp.transform.parent = transform; tmp.GetComponent <MeshRenderer>().material.color = Color.HSVToRGB(colorRange, 0.73f, 0.96f); } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, -0.1f, z + CellHeight / 2) + Wall.transform.position + Util.wallOffset, Quaternion.Euler(0, 0, 0)) as GameObject;// front tmp.transform.parent = transform; tmp.GetComponent <MeshRenderer>().material.color = Color.HSVToRGB(colorRange, 0.73f, 0.96f); } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, -0.1f, z) + Wall.transform.position + Util.wallOffset, Quaternion.Euler(0, 270, 0)) as GameObject;// left tmp.transform.parent = transform; tmp.GetComponent <MeshRenderer>().material.color = Color.HSVToRGB(colorRange, 0.73f, 0.96f); } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, -0.1f, z - CellHeight / 2) + Wall.transform.position + Util.wallOffset, Quaternion.Euler(0, 180, 0)) as GameObject;// back tmp.transform.parent = transform; tmp.GetComponent <MeshRenderer>().material.color = Color.HSVToRGB(colorRange, 0.73f, 0.96f); } } } }
void Start() { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { secondWallDelete++; float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; int randDel = Random.Range(0, 20); if (((randDel % randomWallDelete) != 0) && (secondWallDelete > 2)) { if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;// right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;// front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;// left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;// back tmp.transform.parent = transform; } } if (cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } surface.BuildNavMesh(); }
private void Start() { if (!FullRandom) { Random.InitState(RandomSeed); } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } var spawnedGoals = 0; mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; ++row) { for (int column = 0; column < Columns; ++column) { var x = column * (CellWidth + (AddGaps?.2f : 0)); var z = row * (CellHeight + (AddGaps?.2f : 0)); var cell = mMazeGenerator.GetMazeCell(row, column); var tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)); tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)); tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)); tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)); tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)); tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { ++spawnedGoals; tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)); tmp.transform.parent = transform; } } } if (Pillar != null) { for (var row = 0; row <= Rows; ++row) { for (int column = 0; column <= Columns; ++column) { var x = column * (CellWidth + (AddGaps?.2f : 0)); var z = row * (CellHeight + (AddGaps?.2f : 0)); var tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity); tmp.transform.parent = transform; } } } }
private void Start() { if (!FullRandom) { Random.InitState(RandomSeed); } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; default: throw new ArgumentOutOfRangeException(); } mMazeGenerator.GenerateMaze(); for (var row = 0; row < Rows; row++) { for (var column = 0; column < Columns; column++) { var x = column * (CellWidth + (AddGaps ? .2f : 0)); var z = row * (CellHeight + (AddGaps ? .2f : 0)); var cell = mMazeGenerator.GetMazeCell(row, column); var tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)); tmp.transform.parent = transform; Transform fogItem = null; if (IsVisibleFog && fog != null) { fogItem = Instantiate(fog, new Vector3(x, 1.2f, z), Quaternion.identity); fogItem.transform.parent = transform; } if (IsVisibleLine) { DrawLineRenderer(tmp, cell, fogItem); } if (IsVisibleGoal && cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 0.1f, z), Quaternion.Euler(0, 0, 0)); tmp.transform.parent = transform; tmp.transform.localRotation = GoalPrefab.transform.localRotation; } if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)); tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)); tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)); tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)); tmp.transform.parent = transform; if (column == Columns - 1 && !_isExit) { _isExit = true; tmp.GetComponent <MeshRenderer>().enabled = false; tmp.AddComponent <MeshCollider>(); } } } } if (Pillar != null) { for (var row = 0; row < Rows + 1; row++) { for (var column = 0; column < Columns + 1; column++) { var x = column * (CellWidth + (AddGaps ? .2f : 0)); var z = row * (CellHeight + (AddGaps ? .2f : 0)); var tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity); tmp.transform.parent = transform; } } } }
Start() { if ((Playground.transform.localScale.x != 40f) || (Playground.transform.localScale.z != 40f)) { Debug.LogError( "Donot change the localScale.x and localScale.z of Playground in PlaygroundWithMaze, as it is matched with WallPrefab. Instead, change the localScale of PlaygroundWithMaze if needed."); } if (Wall.transform.localScale.x != 10f) { Debug.LogError( "Donot change the localScale.x of WallPrefab, as it is matched with Playground in PlaygroundWithMaze."); } CellWidth = Playground.transform.lossyScale.x / Columns; CellHeight = Playground.transform.lossyScale.z / Rows; PlaygroundOffset = new Vector3( Playground.transform.position.x - Playground.transform.lossyScale.x / 2f + CellWidth / 2f, Playground.transform.position.y + 0.038f, Playground.transform.position.z - Playground.transform.lossyScale.z / 2f + CellHeight / 2f ); Pillars = new GameObject[Rows + 1, Columns + 1]; if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2) + PlaygroundOffset, Quaternion.identity) as GameObject; tmp.transform.parent = transform; Pillars[row, column] = tmp; } } } Walls = new GameObject[Rows, Columns, 4]; for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp; if (true) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + PlaygroundOffset, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; tmp.transform.localScale = new Vector3( tmp.transform.localScale.x / Rows * gameObject.transform.localScale.z, tmp.transform.localScale.y, tmp.transform.localScale.z ); Walls[row, column, 0] = tmp; } if (true) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + PlaygroundOffset, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; tmp.transform.localScale = new Vector3( tmp.transform.localScale.x / Columns * gameObject.transform.localScale.x, tmp.transform.localScale.y, tmp.transform.localScale.z ); Walls[row, column, 1] = tmp; } if (true) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + PlaygroundOffset, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; tmp.transform.localScale = new Vector3( tmp.transform.localScale.x / Rows * gameObject.transform.localScale.z, tmp.transform.localScale.y, tmp.transform.localScale.z ); Walls[row, column, 2] = tmp; } if (true) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + PlaygroundOffset, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; tmp.transform.localScale = new Vector3( tmp.transform.localScale.x / Columns * gameObject.transform.localScale.x, tmp.transform.localScale.y, tmp.transform.localScale.z ); Walls[row, column, 3] = tmp; } } } if (RandomSeed > 0) { Random.InitState(RandomSeed); } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } Reinitialize(); } // Start
void Start() { done = false; if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } numCoins = 0; mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;// right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;// front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;// left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;// back tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; numCoins += 1; tmp.transform.parent = transform; } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } agentInstance = Instantiate(agentPrefab, transform); agentInstance.setNumCoins(this.getNumCoins()); }
void Start() { Consts.Seed = rand.Next(0, 50); print(Consts.Seed); Random.InitState(Consts.Seed); seedText.text = $"Maze: {Consts.Seed + 1}"; // Consts.Seed = Random.Range(0, 49); // Random.InitState(Consts.Seed); switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }
// Start the creation void Start () { if (!FullRandom) { Random.seed = RandomSeed; } // Switch between different generation algorithms to build the maze randomly and more effectively switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator (Rows, Columns); break; }// End of switch // Generate the maze mMazeGenerator.GenerateMaze (); for (int row = 0; row < Rows; row++) { for(int column = 0; column < Columns; column++){ float x = column*(CellWidth+(AddGaps?.2f:0)); float z = row*(CellHeight+(AddGaps?.2f:0)); MazeCell cell = mMazeGenerator.GetMazeCell(row,column); GameObject tmp; tmp = Instantiate(Floor,new Vector3(x,0,z), Quaternion.Euler(0,0,0)) as GameObject; tmp.transform.parent = transform; if(cell.WallRight){ tmp = Instantiate(Wall,new Vector3(x+CellWidth/2,0,z)+Wall.transform.position,Quaternion.Euler(0,90,0)) as GameObject;// right tmp.transform.parent = transform; } if(cell.WallFront){ tmp = Instantiate(Wall,new Vector3(x,0,z+CellHeight/2)+Wall.transform.position,Quaternion.Euler(0,0,0)) as GameObject;// front tmp.transform.parent = transform; } if(cell.WallLeft){ tmp = Instantiate(Wall,new Vector3(x-CellWidth/2,0,z)+Wall.transform.position,Quaternion.Euler(0,270,0)) as GameObject;// left tmp.transform.parent = transform; } if(cell.WallBack){ tmp = Instantiate(Wall,new Vector3(x,0,z-CellHeight/2)+Wall.transform.position,Quaternion.Euler(0,180,0)) as GameObject;// back tmp.transform.parent = transform; } if(cell.IsGoal && GoalPrefab != null){ tmp = Instantiate(GoalPrefab,new Vector3(x,1,z), Quaternion.Euler(0,0,0)) as GameObject; tmp.transform.parent = transform; } } } if(Pillar != null){ for (int row = 0; row < Rows+1; row++) { for (int column = 0; column < Columns+1; column++) { float x = column*(CellWidth+(AddGaps?.2f:0)); float z = row*(CellHeight+(AddGaps?.2f:0)); GameObject tmp = Instantiate(Pillar,new Vector3(x-CellWidth/2,0,z-CellHeight/2),Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }
void Start() { if (!FullRandom) { Random.seed = Random.Range(0, 20000); } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); int countSpawn = 0; int zombieCount = 0; int bruteCount = 0; int minionCount = 0; int trapCount = 0; for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { countSpawn++; float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { if (Wall.tag == "Fence") { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;// right } else { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;// right } tmp.transform.parent = transform; } if (cell.WallFront) { if (Wall.tag == "Fence") { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;// front } else { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;// front } tmp.transform.parent = transform; } if (cell.WallLeft) { if (Wall.tag == "Fence") { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;// left } else { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;// left } tmp.transform.parent = transform; } if (cell.WallBack) { if (Wall.tag == "Fence") { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;// back } else { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;// back } tmp.transform.parent = transform; } if (cell.IsGoal && GoalPrefab != null) { int enemySpawner = Random.Range(0, 13); if (Wall.tag == "Fence") { enemySpawner = Random.Range(0, 40); if (Random.Range(0, 10) == 0) { tmp = Instantiate(PotionPrefabs[Random.Range(0, 2)], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 0, 0)) as GameObject; } else if (enemySpawner < 15 && countSpawn > 20 && countSpawn != 900) { if (Random.Range(0, 2) == 0) { tmp = Instantiate(TrapPrefab, new Vector3(x - 0.5f, -2f, z + 0.5f), Quaternion.Euler(0, 0, 0)) as GameObject; trapCount++; } else { tmp = Instantiate(EnemyPrefabs[2], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 180, 0)) as GameObject; minionCount++; tmp.GetComponent <AIPath>().target = hero; } } else if (enemySpawner < 25 && countSpawn > 200 && countSpawn != 900) { tmp = Instantiate(EnemyPrefabs[1], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 180, 0)) as GameObject; tmp.GetComponent <AIPath>().target = hero; zombieCount++; } else if (enemySpawner < 30 && countSpawn > 600 && countSpawn != 900) { tmp = Instantiate(EnemyPrefabs[0], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 180, 0)) as GameObject; tmp.GetComponent <AIPath>().target = hero; bruteCount++; } else { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; } tmp.transform.parent = transform; } else if (Random.Range(0, 4) == 0) { tmp = Instantiate(PotionPrefabs[Random.Range(0, 2)], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 0, 0)) as GameObject; } else if (enemySpawner < 4 && countSpawn > 30 && countSpawn != 900) { tmp = Instantiate(EnemyPrefabs[2], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 180, 0)) as GameObject; tmp.GetComponent <AIPath>().target = hero; minionCount++; } else if (enemySpawner < 6 && countSpawn > 300 && countSpawn != 900) { tmp = Instantiate(EnemyPrefabs[1], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 180, 0)) as GameObject; tmp.GetComponent <AIPath>().target = hero; zombieCount++; } else if (enemySpawner < 7 && countSpawn > 700 && countSpawn != 900) { tmp = Instantiate(EnemyPrefabs[0], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 180, 0)) as GameObject; tmp.GetComponent <AIPath>().target = hero; bruteCount++; } else { tmp = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; } tmp.transform.parent = transform; } if (countSpawn == 900) { tmp = Instantiate(EnemyPrefabs[Random.Range(0, 2)], new Vector3(x, -0.2f, z), Quaternion.Euler(0, 180, 0)) as GameObject; tmp.GetComponent <AIPath>().target = hero; bruteCount++; } } } Debug.Log("Minions: " + minionCount); Debug.Log("Trap: " + trapCount); Debug.Log("Zombies: " + zombieCount); Debug.Log("Brute: " + bruteCount); Debug.Log("Total Enemies: " + (minionCount + zombieCount + bruteCount + trapCount)); if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps ? .2f : 0)); float z = row * (CellHeight + (AddGaps ? .2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }
void Start () { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator (Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator (Rows, Columns); break; } mMazeGenerator.GenerateMaze (); for (int row = 0; row < Rows; row++) { for(int column = 0; column < Columns; column++){ float x = column*(CellWidth+(AddGaps?.2f:0)); float z = row*(CellHeight+(AddGaps?.2f:0)); MazeCell cell = mMazeGenerator.GetMazeCell(row,column); GameObject tmp; if(cell.WallRight){ tmp = Instantiate(Wall,new Vector3(x+CellWidth/2,0,z)+Wall.transform.position,Quaternion.Euler(0,90,0)) as GameObject;// right tmp.transform.parent = transform; } if(cell.WallFront){ tmp = Instantiate(Wall,new Vector3(x,0,z+CellHeight/2)+Wall.transform.position,Quaternion.Euler(0,0,0)) as GameObject;// front tmp.transform.parent = transform; } if(cell.WallLeft){ tmp = Instantiate(Wall,new Vector3(x-CellWidth/2,0,z)+Wall.transform.position,Quaternion.Euler(0,270,0)) as GameObject;// left tmp.transform.parent = transform; } if(cell.WallBack){ tmp = Instantiate(Wall,new Vector3(x,0,z-CellHeight/2)+Wall.transform.position,Quaternion.Euler(0,180,0)) as GameObject;// back tmp.transform.parent = transform; } if(cell.IsGoal && GoalPrefab != null){ tmp = Instantiate(GoalPrefab,new Vector3(x,1,z), Quaternion.Euler(0,0,0)) as GameObject; tmp.transform.parent = transform; } } } if(Pillar != null){ for (int row = 0; row < Rows+1; row++) { for (int column = 0; column < Columns+1; column++) { float x = column*(CellWidth+(AddGaps?.2f:0)); float z = row*(CellHeight+(AddGaps?.2f:0)); GameObject tmp = Instantiate(Pillar,new Vector3(x-CellWidth/2,0,z-CellHeight/2),Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }
public void SpawnMaze() { if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; tmp.name = "Floor" + new Vector3(x, 0, z); if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; tmp.name = "Wall" + new Vector3(x + CellWidth / 2, 0, z); } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; tmp.name = "Wall" + new Vector3(x, 0, z + CellHeight / 2); } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; tmp.name = "Wall" + new Vector3(x - CellWidth / 2, 0, z); } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; tmp.name = "Wall" + new Vector3(x, 0, z - CellHeight / 2); } if (cell.IsGoal && GoalPrefab.Length > 0 && GoalSpawnPercentage > Random.Range(0, 101)) { tmp = Instantiate(GoalPrefab[Random.Range(0, GoalPrefab.Length)], new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; tmp.tag = "Pickup"; } } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } SelectTarget(); }
public void init() { Cursor.visible = false; player.CellWidth = CellWidth; player.CellHeight = CellHeight; if (!FullRandom) { Random.seed = RandomSeed; } switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } var maze = mMazeGenerator.GenerateMaze(); player.cell = maze[0, 0]; mMazeFiller = new MazeFiller(maxCubeCount, basicEnemyCount, trapCount, smallEnemyCount); mMazeFiller.fill(maze); float y = 0f; if (Pillar != null) { for (int row = Rows; row >= 0; row--) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth); float z = row * (CellHeight); GameObject tmp = Instantiate(Pillar, new Vector3(x, y, z), Quaternion.identity); tmp.transform.parent = transform; levelObjects.Add(tmp); } } } for (int row = Rows - 1; row >= 0; row--) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth); float z = row * (CellHeight); if (Wall != null) { MazeCell cell = mMazeGenerator.GetMazeCell(row, column); if (cell.WallRight) { var tmp = Instantiate(Wall, new Vector3(x + CellWidth, y, z + CellHeight / 2f), Quaternion.Euler(0, 0, 0)); levelObjects.Add(tmp); } if (cell.WallFront) { var tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2f, y, z + CellHeight), Quaternion.Euler(0, 90, 0)); levelObjects.Add(tmp); } if (cell.WallLeft) { var tmp = Instantiate(Wall, new Vector3(x, y, z + CellHeight / 2f), Quaternion.Euler(0, 0, 0)); levelObjects.Add(tmp); } if (cell.WallBack) { var tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2f, y, z), Quaternion.Euler(0, 90, 0)); levelObjects.Add(tmp); } } if (Floor != null) { var tmp = Instantiate(Floor, new Vector3(x + CellWidth / 2f, y - 2.5f, z + CellHeight / 2f), Quaternion.Euler(0, 0, 90)); levelObjects.Add(tmp); } if (WayPoint != null) { var instantiate = Instantiate(WayPoint, new Vector3(x + CellWidth / 2f, y, z + CellHeight / 2f), Quaternion.identity); var waypointModified = instantiate.GetComponent <Waypoint_Modified>(); waypointModified.Cell = maze[row, column]; levelObjects.Add(instantiate); } if (ExitDoor != null) { MazeCell cell = mMazeGenerator.GetMazeCell(row, column); Vector3 position = new Vector3(); var rotation = Quaternion.identity; var wallDiff = 0.5f; var doorDiff = 0.2f; switch (cell.ExitSide) { case ExitSide.LEFT: position = new Vector3(x + wallDiff, y, z + CellHeight / 2f); rotation = Quaternion.Euler(0, 90f, 0); doorText.transform.position = new Vector3(position.x + doorDiff, position.y, position.z); break; case ExitSide.RIGHT: position = new Vector3(x + CellWidth - wallDiff, y, z + CellHeight / 2f); rotation = Quaternion.Euler(0, -90f, 0); doorText.transform.position = new Vector3(position.x - doorDiff, position.y, position.z); break; case ExitSide.BOTTOM: position = new Vector3(x + CellWidth / 2f, y, z + wallDiff); doorText.transform.position = new Vector3(position.x, position.y, position.z + doorDiff); break; case ExitSide.TOP: position = new Vector3(x + CellWidth / 2f, y, z + CellHeight - wallDiff); rotation = Quaternion.Euler(0, 180f, 0); doorText.transform.position = new Vector3(position.x, position.y, position.z - doorDiff); break; } if (cell.ExitSide != ExitSide.NONE) { doorText.transform.rotation = rotation; var instantiate = Instantiate(ExitDoor, position, rotation); var exitScript = instantiate.GetComponent <ExitScript>(); exitScript.Player = player; exitScript.doorText = doorText; levelObjects.Add(instantiate); } } if (Cube != null && maze[row, column].hasCube) { var randomX = Random.Range(CellWidth / 2f - 1, CellWidth / 2f + 1); var randomY = Random.Range(CellHeight / 2f - 1, CellHeight / 2f + 1); var instantiate = Instantiate(Cube, new Vector3(x + randomX, y - 2, z + randomY), Quaternion.identity); var component = instantiate.GetComponent <Cube>(); component.player = player; levelObjects.Add(instantiate); } if (MeduimEnemy != null && maze[row, column].enemyType == EnemyType.Medium) { var instantiate = Instantiate(MeduimEnemy, new Vector3(x + CellWidth / 2f, y - 2, z + CellHeight / 2f), Quaternion.identity); var component = instantiate.GetComponent <Enemy>(); component.cell = maze[row, column]; component.maze = maze; component.player = player; component.CellWidth = CellWidth; component.CellHeight = CellHeight; levelObjects.Add(instantiate); } if (SmallEnemy != null && maze[row, column].enemyType == EnemyType.Small) { var instantiate = Instantiate(SmallEnemy, new Vector3(x + CellWidth / 2f, y - 2, z + CellHeight / 2f), Quaternion.identity); var component = instantiate.GetComponent <Enemy>(); component.cell = maze[row, column]; component.maze = maze; component.player = player; component.CellWidth = CellWidth; component.CellHeight = CellHeight; levelObjects.Add(instantiate); } if (Trap != null && maze[row, column].enemyType == EnemyType.Trap) { var instantiate = Instantiate(Trap, new Vector3(x + CellWidth / 2f, y - 2, z + CellHeight / 2f + 0.5f), Quaternion.identity); var component = instantiate.GetComponent <Trap>(); component.Cell = maze[row, column]; component.player = player; levelObjects.Add(instantiate); } } } }
void Start() { Random.seed = mapSeed; //Debug.Log("dddddddddddddddddddddddddd "+ mapSeed+" "+Random.seed) switch (Algorithm) { case MazeGenerationAlgorithm.PureRecursive: mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveTree: mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RandomTree: mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.OldestTree: mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns); break; case MazeGenerationAlgorithm.RecursiveDivision: mMazeGenerator = new DivisionMazeGenerator(Rows, Columns); break; } /////// sukurt i viena gameObject ir tada atspawnint.....prie sienu grindu pakeist server only, gal seervas uzkrauna ir nusiuncia klientam mMazeGenerator.GenerateMaze(); for (int row = 0; row < Rows; row++) { for (int column = 0; column < Columns; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); MazeCell cell = mMazeGenerator.GetMazeCell(row, column); GameObject tmp; tmp = Instantiate(Floor, new Vector3(x, 0.1f, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; if (cell.WallRight) { tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject; // right tmp.transform.parent = transform; } if (cell.WallFront) { tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject; // front tmp.transform.parent = transform; } if (cell.WallLeft) { tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject; // left tmp.transform.parent = transform; } if (cell.WallBack) { tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject; // back tmp.transform.parent = transform; } if (cell.IsGoal) //arba isvest lauk masyva su kordinatem arba bbz registruot tik kelis { tmp = Instantiate(SpawnPoint, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; tmp.transform.parent = transform; } /* kamerai tikrint zaidejo vardo primas dvi raides * /////padaryt kad galetum kokius keturis dadet skirtingus zmones * if ((cell.IsGoal && play2 != null)) //pridet laukimo atstumaaaaaaa * {/////padaryt kad skaiciuotu atstuma mmmmmmasmdasbjfgvadshfs * if (play1 != null) * { * tmp = Instantiate(play1, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * play1 = null; * } * if (range >= 2) { * tmp = Instantiate(play2, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject; * tmp.transform.parent = transform; * play2 = null; * } * range += 1; * }*/ } } if (Pillar != null) { for (int row = 0; row < Rows + 1; row++) { for (int column = 0; column < Columns + 1; column++) { float x = column * (CellWidth + (AddGaps?.2f : 0)); float z = row * (CellHeight + (AddGaps?.2f : 0)); GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject; tmp.transform.parent = transform; } } } }