public void Setup(Vector2 index, Room[][] map, Enum.Dir entrance, Enum.Path path) { Wall[] openings = CreateOpenings(index, map, entrance, path); foreach (Wall opening in openings) { _openings.Add(opening); switch (opening) { case Wall.Top: // _wallTop.SetActive(false); Destroy(_wallTop); break; case Wall.Right: // _wallRight.SetActive(false); Destroy(_wallRight); break; case Wall.Bottom: // _wallBottom.SetActive(false); Destroy(_wallBottom); break; case Wall.Left: // _wallLeft.SetActive(false); Destroy(_wallLeft); break; default: break; } } }
//X = rows //Y = cols void CreateRooms(Vector2 aPos, Enum.Dir lastDir, Enum.Path path = Enum.Path.Path) { //Create New Room Room room = Instantiate(_room, new Vector2(aPos.y * 8, aPos.x * 8), Quaternion.identity); room.Setup(aPos, _zones, lastDir, path); //Place New Room in X/Y pos Vector2 nextZoneIndex; switch (room.Direction) { case Enum.Dir.Start: case Enum.Dir.End: case Enum.Dir.East: nextZoneIndex = new Vector2(aPos.x, aPos.y + 1); break; case Enum.Dir.West: nextZoneIndex = new Vector2(aPos.x, aPos.y - 1); break; case Enum.Dir.North: nextZoneIndex = new Vector2(aPos.x + 1, aPos.y); break; case Enum.Dir.South: nextZoneIndex = new Vector2(aPos.x - 1, aPos.y); break; default: nextZoneIndex = new Vector2(99999, 99999); break; } //Create an other room if not reached the end if (_zones.Length - 1 > (int)nextZoneIndex.x && _zones[0].Length > (int)nextZoneIndex.y && (int)nextZoneIndex.y >= 0 && (int)nextZoneIndex.x >= 0) { if (_zones[0].Length - 1 != (int)nextZoneIndex.y && _zones.Length - 1 != (int)nextZoneIndex.x && (int)nextZoneIndex.y >= 0 && (int)nextZoneIndex.x >= 0) { CreateRooms(nextZoneIndex, room.Direction); } else { CreateRooms(nextZoneIndex, room.Direction, Enum.Path.End); } } else { Vector2 spawn = GameObject.Find("Spawn").transform.position; Instantiate(_playerPref, spawn, Quaternion.identity); } }
Wall[] CreateOpenings(Vector2 index, Room[][] map, Enum.Dir entrance, Enum.Path path) { //Declare paths Wall[] paths = new Wall[2]; //Removes entrance from random choices List <Enum.Dir> tempsDirList = new List <Enum.Dir>(); for (int i = _directions.Count - 1; i >= 0; i--) { tempsDirList.Add(_directions[i]); } for (int i = tempsDirList.Count - 1; i >= 0; i--) { if (tempsDirList[i] != entrance) { switch (tempsDirList[i]) { case Enum.Dir.North: tempsDirList.Add(Enum.Dir.South); break; case Enum.Dir.South: tempsDirList.Add(Enum.Dir.North); break; case Enum.Dir.Start: case Enum.Dir.East: tempsDirList.Add(Enum.Dir.West); break; case Enum.Dir.West: tempsDirList.Add(Enum.Dir.East); break; } tempsDirList.Remove(tempsDirList[i]); } } _directions = tempsDirList; //Create random path if (path == Enum.Path.Path) { int randPath = Random.Range(0, _directions.Count - 1); _direction = _directions[randPath]; // _spawn.SetActive(false); Destroy(_spawn); Destroy(_end); int randObstacles = Random.Range(0, 100); int highDiff = (GameManager.instance.Level >= 7) ? 5 : 0; if (randObstacles <= 80) { CreateIntels(); } if (randObstacles <= (GameManager.instance.Level == _plankLevel ? 20 : 10) + highDiff * 1 && GameManager.instance.Level >= _plankLevel)//10% { CreatePlankWall(entrance); } if (randObstacles <= (GameManager.instance.Level == _enemyLevel ? 25 : 15) + highDiff * 1 && GameManager.instance.Level >= _enemyLevel)//15% { CreateEnemies(); } else if (randObstacles <= 30 + highDiff * 2 && GameManager.instance.Level >= _sawLevel)//15% { CreateSaws(entrance); } else if (entrance == _direction && randObstacles <= (GameManager.instance.Level == _stomperLevel ? 65 : 45) + highDiff * 3 && GameManager.instance.Level >= _stomperLevel)//15% when to walls face each other { CreateStompers(entrance); } } //Create starting path else if (path == Enum.Path.Start) { _direction = Enum.Dir.Start; Destroy(_end); _spawn.SetActive(true); } //Close Path else if (path == Enum.Path.End) { _direction = Enum.Dir.End; Destroy(_spawn); _end.SetActive(true); } //Open entrance switch (entrance) { case Enum.Dir.North: paths[0] = Wall.Bottom; break; case Enum.Dir.Start: case Enum.Dir.East: paths[0] = Wall.Left; break; case Enum.Dir.South: paths[0] = Wall.Top; break; case Enum.Dir.West: paths[0] = Wall.Right; break; case Enum.Dir.Null: case Enum.Dir.End: default: paths[0] = Wall.Null; break; } //Open exit switch (_direction) { case Enum.Dir.North: paths[1] = Wall.Top; break; case Enum.Dir.Start: case Enum.Dir.East: paths[1] = Wall.Right; break; case Enum.Dir.South: paths[1] = Wall.Bottom; break; case Enum.Dir.West: paths[1] = Wall.Left; break; case Enum.Dir.Null: case Enum.Dir.End: default: paths[1] = Wall.Null; break; } return(paths); }