public void placeLG_Rooms_rand(int minW, int maxW, int minH, int maxH, int numLG_Rooms) { int maxHorz = (int)Mathf.Floor(width / (maxW+6)); int maxVert = (int)Mathf.Floor(height / (maxH+6)); int maxNumLG_Rooms = maxHorz * maxVert; numLG_Rooms = Mathf.Min(numLG_Rooms, maxNumLG_Rooms); System.Collections.Generic.List<RandomRoom> tempLG_RoomList = new System.Collections.Generic.List<RandomRoom>(); RandomRoom theLG_Room; for(int i = 0; i < numLG_Rooms; i++) { int xx = r.getIntInRange(0, width-maxW); int yy = r.getIntInRange(0,height-maxH); theLG_Room = new RandomRoom(xx,yy, minW, maxW, minH, maxH, r); theLG_Room.garbage = r.getIntInRange(int.MinValue, int.MaxValue); tempLG_RoomList.Add(theLG_Room); //int widthDiff = maxW - theLG_Room.width; //int heightDiff = maxH - theLG_Room.height } for(int j = 0; j < numLG_Rooms; j++) { theLG_Room = tempLG_RoomList[j]; Rect roomRect = new Rect(theLG_Room.x * tileWidth, theLG_Room.y * tileHeight, theLG_Room.width * tileWidth, theLG_Room.height * tileHeight); Vector2 center = new Vector2(roomRect.x + Mathf.Floor(roomRect.width/2), roomRect.y + Mathf.Floor(roomRect.height/2)); roomCenterPoints.Add(center); this.addLG_Room(theLG_Room); rooms_sorted[center] = theLG_Room; }//for tempLG_RoomList.Sort(sortLG_Rooms); //Using the data in the acutal level, figure out all the room connections roomTree = new MinimumSpan(roomCenterPoints); roomConnections = roomTree.createMinimumSpan(); }
//NEED TO REPLACE THIS WITH A SYSTEM THAT DOESN'T MAKE AS MANY OVERLAPPING ROOMS public void placeLG_Rooms(int minW, int maxW, int minH, int maxH, int numLG_Rooms) { int maxLG_RoomsHorz = (int)Mathf.Floor(width/(maxW+3)); int maxLG_RoomsVert = (int)Mathf.Floor(height/(maxH+3));; int maxNumLG_Rooms = maxLG_RoomsHorz * maxLG_RoomsVert; numLG_Rooms = Mathf.Min(numLG_Rooms, maxNumLG_Rooms); System.Collections.Generic.List<RandomRoom> tempLG_RoomList = new System.Collections.Generic.List<RandomRoom>(); RandomRoom theRoom; //Track all the "buckets" that the "screen" can hold. bool[,] screenBuckets = createEmptyScreenBucketsArray(maxLG_RoomsHorz, maxLG_RoomsVert); //Loop until you've spawned all the rooms (numLG_Rooms) for(var i=0; i<numLG_Rooms; i++) { //Choose a random bucket int x = r.getIntInRange(0, maxLG_RoomsHorz-1); int y = r.getIntInRange(0, maxLG_RoomsVert-1); int maxTimesLooped = numLG_Rooms+r.getIntInRange(0, 5); while(screenBuckets[x,y] == true && maxTimesLooped > 0) { //If the bucket is false set it to true and add a room within the bucket bounds if(x < maxLG_RoomsHorz-1) { x++; }//if else { y++; if(y > maxLG_RoomsVert-1) { y=0; //loop back around }//if x=0; //loop back around }//else maxTimesLooped--; }//if screenBuckets[x,y] = true; theRoom = new RandomRoom(x*(maxW+3)+1,y*(maxH+3)+1, minW, maxW, minH, maxH, r); theRoom.garbage = r.getIntInRange(int.MinValue, int.MaxValue); tempLG_RoomList.Add(theRoom); } //tempLG_RoomList.Sort(sortLG_Rooms); for(int j = 0; j < numLG_Rooms; j++) { theRoom = tempLG_RoomList[j]; Rect roomRect = new Rect(theRoom.x * tileWidth, theRoom.y * tileHeight, theRoom.width * tileWidth, theRoom.height * tileHeight); Vector2 center = new Vector2(roomRect.x + Mathf.Floor(roomRect.width/2), roomRect.y + Mathf.Floor(roomRect.height/2)); roomCenterPoints.Add(center); this.addLG_Room(theRoom); rooms_sorted[center] = theRoom; }//for //Using the room placement data, figure out all the room connections roomTree = new MinimumSpan(roomCenterPoints); roomConnections = roomTree.createMinimumSpan(); }