private void assignDoorways() { this.doorways.Add(new p2D(center.getX() + radius + 1, center.getY())); this.doorways.Add(new p2D(center.getX() - radius + 1, center.getY())); this.doorways.Add(new p2D(center.getX(), center.getY() + radius + 1)); this.doorways.Add(new p2D(center.getX(), center.getY() - radius - 1)); }
} //lineFree //Checks available space of a recangle, plus a row of space around it private bool rectangleFree(p2D coord, int direction, int rectangleWidthRadius, int rectangleLength) { int searchWidth = rectangleWidthRadius + 1; int x = coord.getX(); int y = coord.getY(); switch (direction) { case 0: case 2: //Cases whem you're on a horizontal wall int minX = x - searchWidth; int maxX = x + searchWidth; //Make sure you're looking within the available space if (minX <= 0 || maxX >= width - 1) { return(false); } //Check all lines starting at the wall for (int i = minX; i <= maxX; i++) { if (!lineFree(new p2D(i, y), direction, rectangleLength)) { return(false); } } break; case 1: case 3: //Cases when you're on a vertical wall int minY = y - searchWidth; int maxY = y + searchWidth; //Make sure you're looking within the available space if (minY <= 0 || maxY >= height - 1) { return(false); } //Check all lines starting at the wall for (int i = minY; i <= maxY; i++) { if (!lineFree(new p2D(x, i), direction, rectangleLength)) { return(false); } } break; default: //Debug.Log("Incorrect direction - not checked;"); return(false); } return(true); } //rectangleFree
} //pickdoorways //This function determines what the door is currently connected to public string findPrevious(KeyValuePair <p2D, int> doorway) { p2D door = doorway.Key; //Door coordinate int direction = doorway.Value; //Door direction p2D check1 = new p2D(width / 2, height / 2); p2D check2 = new p2D(width / 2, height / 2); p2D temp = p2D.translateDirectional2(door, 1, (direction + 2) % 4); check1 = p2D.translateDirectional2(temp, 1, (direction + 1) % 4); check2 = p2D.translateDirectional2(temp, 1, (direction + 1) % 4); /** * Check 1 and check 2 are now (x being the door coordinate, > the direction) * * 100 * 0X> * 200 */ //Check weither at least one of them is occupied; then it's a room //(or you at least won't be able to place a room next to it) if (dungeonMaze[check1.getX(), check1.getY()] == 1 || dungeonMaze[check2.getX(), check2.getY()] == 1) { return("room"); } else { return("corridor"); } } //findprevious
public bool Equals(p2D other) { if ((object)other == null) { return(false); } return(other.getX() == this.X && other.getY() == this.Y); }
void populatePuzzles() { int random = 0; //Make beginningRoom random = Random.Range(0, puzzleCenters.Count); p2D beginning = puzzleCenters [random]; startpoint = new Vector3(beginning.getX() * 6 + 1, 0, beginning.getY() * 6 + 1); startpoint += new Vector3(-4f, 0, -4f); Instantiate(BeginningRoom, startpoint, Quaternion.identity, Dungeon.transform); //Remove from list List <p2D> temp1 = new List <p2D> (); temp1.Add(beginning); p2D.myRemove(puzzleCenters, temp1); //Make endRoom random = Random.Range(0, puzzleCenters.Count); p2D ending = puzzleCenters [random]; endpoint = new Vector3(ending.getX() * 6 + 1, 0, ending.getY() * 6 + 1); endpoint += new Vector3(-4f, 0, -4f); Instantiate(EndingRoom, endpoint, Quaternion.Euler(new Vector3(0, Random.Range(0, 4) * 90, 0)), Dungeon.transform); //Remove from list List <p2D> temp2 = new List <p2D> (); temp2.Add(ending); p2D.myRemove(puzzleCenters, temp2); sbPuzzles.Append("\n\nPuzzles in this dungeon: "); foreach (p2D center in puzzleCenters) { Vector3 convCenter = new Vector3(center.getX() * 6 + 1, 0, center.getY() * 6 + 1); convCenter += new Vector3(-4f, 0, -4f); int x = DeterminePuzzleRoom(); GameObject thispuzzle = Instantiate(puzzleRooms [x], convCenter, Quaternion.identity, Dungeon.transform) as GameObject; GameObject thesedoors = Instantiate(PuzzleDoors, convCenter, Quaternion.identity, thispuzzle.transform) as GameObject; if (thispuzzle.GetComponent <myLever> () != null) { thispuzzle.GetComponent <myLever> ().Reread(); } thesedoors.GetComponent <puzzleDoors> ().RoomType = thispuzzle.name; buildDoors(center, convCenter, thesedoors); Instantiate(PuzzleMist, convCenter, Quaternion.identity, thispuzzle.transform); } sbPuzzles.Append("\n\n"); Debug.Log(sbPuzzles.ToString()); }
public int[] roomDoorLocations(Room room) { int[] locations = new int[4] { 0, 0, 0, 0 }; for (int i = 0; i < room.getDoorways().Count; i++) { p2D door = room.getDoorways()[i]; locations[i] = maze[door.getX(), door.getY()]; } return(locations); }
//Build a room using only the center of the room private void buildRoom(p2D center) { Room room = new Room(center, roomRadius); int minX = center.getX() - roomRadius; int maxX = center.getX() + roomRadius + 1; int minY = center.getY() - roomRadius; int maxY = center.getY() + roomRadius + 1; for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { dungeonMaze [x, y] = 1; } } this.rooms.Add(room); //I keep a list of all the rooms for game purposes //Add the doorways of this room to the list //The doors are on all 4 walls in the center this.doorways.Add(new p2D(center.getX() + roomRadius + 1, center.getY())); this.doorways.Add(new p2D(center.getX() - roomRadius - 1, center.getY())); this.doorways.Add(new p2D(center.getX(), center.getY() + roomRadius + 1)); this.doorways.Add(new p2D(center.getX(), center.getY() - roomRadius - 1)); } //buildRoom
} //buildRoom //Builds a corridor private void buildCorridor(p2D start, int direction) { //The start and end coordinates are saved p2D end = new p2D(0, 0); int x = start.getX(); int y = start.getY(); switch (direction) { case 1: //East for (int i = x; i <= x + corridorLength; i++) { dungeonMaze[i, y] = 1; end.setP(i, y); } break; case 3: //West for (int i = x; i >= x - corridorLength; i--) { dungeonMaze[i, y] = 1; end.setP(i, y); } break; case 0: //North for (int i = y; i <= y + corridorLength; i++) { dungeonMaze[x, i] = 1; end.setP(x, i); } break; case 2: //South for (int i = y; i >= y - corridorLength; i--) { dungeonMaze[x, i] = 1; end.setP(x, i); } break; default: //System.err.println("BuildCorridor end 0,0 added"); break; } //The start and end are added to the list or doorwayss doorways.Add(end); doorways.Add(start); } //buildCorridor
} //chooseBuild //This function looks at the entourage of a coordinate, and outputs an array //with the maze values at those coordinates in N-E-S-W order public int[] getSurrounding(p2D point) { int x = point.getX(); int y = point.getY(); //If you are within the boundaries of the maze, do the normal thing if (x > 0 && y > 0 && x < width - 1 && y < height - 1) { int[] array = { dungeonMaze [x, y + 1], //North dungeonMaze [x + 1, y], //East dungeonMaze [x, y - 1], //South dungeonMaze [x - 1, y] //West }; return(array); } //As a catchnet - returning all 4 as built coordinates else { return(new int[] { 1, 1, 1, 1 }); } } //getSurrounding
} //noDupes //Checks available space from selected point private bool lineFree(p2D coord, int direction, int lineLength) { int x = coord.getX(); int y = coord.getY(); int searchLength = lineLength; switch (direction) { case 1: //East //If the coordinate is not within the available space; stop the procedure //This happens for all four cases if (x + searchLength >= width - 2) { return(false); } for (int i = x; i <= x + searchLength; i++) { if (dungeonMaze [i, y] == 1) { return(false); } } break; case 3: //West if (x - searchLength <= 1) { return(false); } for (int i = x; i >= x - searchLength; i--) { if (dungeonMaze[i, y] == 1) { return(false); } } break; case 0: //North if (y + searchLength >= height - 2) { return(false); } for (int i = y; i <= y + searchLength; i++) { if (dungeonMaze[x, i] == 1) { return(false); } } break; case 2: //South if (y - searchLength <= 1) { return(false); } for (int i = y; i >= y - searchLength; i--) { if (dungeonMaze[x, i] == 1) { return(false); } } break; default: //Debug.Log("Linefree didn't receive a correct direction"); break; } return(true); } //lineFree