public Neighbor(DungeonSector sector, DungeonSector.SIDE side) { this.sector = sector; this.side = side; connected = false; }
// Connects a sector to one of its neighbors, chosen by indexing into the neighbor array public void connectSectortoNeighbor(DungeonSector a, int neighborIndex) { int sharedWallCoordinate; Vector2Int doorLocation; Door door; // Get both neighbor objects so that we can attach a reference to the door to each Neighbor n = a.neighbors[neighborIndex]; DungeonSector b = n.getSector(); Neighbor n2 = b.getNeighbor(a); // Decide the location of the door, making sure its on a shared wall between the two sectors DungeonSector.SIDE side = n.getSide(); if (side == DungeonSector.SIDE.BOTTOM || side == DungeonSector.SIDE.TOP) { sharedWallCoordinate = getRandomSharedWallCoordinate(a.position.x, a.size.x, b.position.x, b.size.x); doorLocation = new Vector2Int(sharedWallCoordinate, a.size.y); if (side == DungeonSector.SIDE.BOTTOM) { doorLocation.y = -1; } } else if (side == DungeonSector.SIDE.LEFT || side == DungeonSector.SIDE.RIGHT) { sharedWallCoordinate = getRandomSharedWallCoordinate(a.position.y, a.size.y, b.position.y, b.size.y); doorLocation = new Vector2Int(-1, sharedWallCoordinate); if (side == DungeonSector.SIDE.RIGHT) { doorLocation.x = a.size.x; } } else { return; } // Save the door info to the dungeon, as well as the neighbor objects of both sectors doorLocation = a.sectorToDungeonCoordinates(doorLocation); door = new Door(doorLocation, n, n2); if ((a.type == DungeonSector.TYPE.FILLED) && (b.type == DungeonSector.TYPE.FILLED)) { door.opened = true; } tiles[doorLocation.x][doorLocation.y] = new ShiblitzTile(ShiblitzTile.TYPE.DOOR); doors.Add(door); n.connect(door); n2.connect(door); }