void Start() { //For every node (room) on the map... for (int i = 0; i < MapMaker.mapThingy.getNodeList().Count; i++) { //...find its center x and y coordinates... int centerX = (int)(MapMaker.mapThingy.getNodeList()[i].positionX); int centerY = (int)(MapMaker.mapThingy.getNodeList()[i].positionY); //...set its carrying capacity for enemies... int weightMax = 15; //...if it's the last room, upgrade it to a boss room... try { Nodies.Node test = MapMaker.mapThingy.getNodeList()[i + 2]; } catch { weightMax = 20; } //...and call the FillRoom() method to actually put the enemies into it. FillRoom(weightMax, centerX, centerY); } }
// Start is called before the first frame update void Awake() { if (GameManager.instance != null && GameManager.instance.getLevel() % 3 == 0) { int chance = Random.Range(1, 20); if (chance >= 5) { bossRoom = true; } } if (bossRoom) { mapThingy = this; grid = new Node[worldSizex, worldSizey]; int id = 1; for (int i = 0; i < worldSizex; i++) { for (int j = 0; j < worldSizey; j++) { grid[i, j] = new Node(); grid[i, j].id = id; id++; } } int room = Random.Range(0, bossRooms.Count - 1); Node bossNode = grid[worldSizex / 2, worldSizey / 2]; bossNode.AddNodalPosition(worldSizex / 2, worldSizey / 2, tileSize); GameObject tmp = Instantiate(bossRooms[room], new Vector2(bossNode.positionX, bossNode.positionY), Quaternion.identity); nodalList.Add(bossNode); } else { if (getPieces) { FillOutRooms(); } mapThingy = this; grid = new Node[worldSizex, worldSizey]; int id = 1; for (int i = 0; i < worldSizex; i++) { for (int j = 0; j < worldSizey; j++) { grid[i, j] = new Node(); grid[i, j].id = id; id++; } } Source.id = 0; grid[worldSizex / 2, worldSizey / 2] = Source; grid[worldSizex / 2, worldSizey / 2].AddNodalPosition(worldSizex, worldSizey, tileSize); path.Push(Source); startWalk(); } }
void CreateMap(Stack <Node> path) { Target = path.Peek(); while (path.Count > 0) { Node tmp = path.Pop(); unFilterdNodalList.Add(tmp); Node[] parentArray = new Node[tmp.RetrieveParent().Length]; bool up, down, left, right; float dirX = 0; float dirY = 0; up = down = left = right = false; parentArray = tmp.RetrieveParent(); for (int i = 0; i < tmp.GetParentPos(); i++) { dirX = parentArray[i].nodalPositionX - tmp.nodalPositionX; dirY = parentArray[i].nodalPositionY - tmp.nodalPositionY; if (dirX > 0 && dirY == 0) { right = true; } if (dirX < 0 && dirY == 0) { left = true; } if (dirX == 0 && dirY > 0) { up = true; } if (dirX == 0 && dirY < 0) { down = true; } } if (right && left && up && down) { //intersection if (path.Count > 1) { Instantiate(intersection[Random.Range(0, intersection.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(intersection[intersection.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (right && left && up && !down) { //right left up if (path.Count > 1) { Instantiate(leftRightUpRooms[Random.Range(0, leftRightUpRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(leftRightUpRooms[leftRightUpRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (!right && left && !up && down) { //right left up if (path.Count > 1) { Instantiate(downLeftRooms[Random.Range(0, leftRightUpRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(downLeftRooms[leftRightUpRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (right && left && !up && down) { //right left down if (path.Count > 1) { Instantiate(leftRightDownRooms[Random.Range(0, leftRightDownRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(leftRightDownRooms[leftRightDownRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (right && !left && up && down) { //right up down if (path.Count > 1) { Instantiate(upRightDown[Random.Range(0, upRightDown.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(upRightDown[upRightDown.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (!right && left && up && down) { //left up down if (path.Count > 1) { Instantiate(upLeftDown[Random.Range(0, upLeftDown.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(upLeftDown[upLeftDown.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (right && left && !up && !down) { //right left if (path.Count > 1) { Instantiate(leftRightRooms[Random.Range(0, leftRightRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(leftRightRooms[leftRightRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (right && !left && !up && down) { //right down if (path.Count > 1) { Instantiate(downRightRooms[Random.Range(0, downRightRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(downRightRooms[downRightRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (right && !left && up && !down) { //right up if (path.Count > 1) { Instantiate(upRightRooms[Random.Range(0, upRightRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(upRightRooms[upRightRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (!right && left && up && !down) { //up left if (path.Count > 1) { Instantiate(upLeftRooms[Random.Range(0, upLeftRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(upLeftRooms[upLeftRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (!right && !left && up && down) { //up down if (path.Count > 1) { Instantiate(upDownRooms[Random.Range(0, upDownRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(upDownRooms[upDownRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (right && !left && !up && !down) { //right if (path.Count > 1) { Instantiate(rightRooms[Random.Range(0, rightRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(rightRooms[rightRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (!right && !left && !up && down) { //down if (path.Count > 1) { Instantiate(downRooms[Random.Range(0, downRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(downRooms[downRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (!right && left && !up && !down) { //left if (path.Count > 1) { Instantiate(leftRooms[Random.Range(0, leftRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(leftRooms[leftRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } else if (!right && !left && up && !down) { //up if (path.Count > 1) { Instantiate(upRooms[Random.Range(0, upRooms.Count - 1)], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } else { Instantiate(upRooms[upRooms.Count - 1], new Vector2(tmp.positionX, tmp.positionY), Quaternion.identity); } } } filterNodes(); }