// Start is called before the first frame update void Start() { rand = GameObject.Find("ObjectDropPoint").GetComponent <RandomGen>(); rb = GetComponentInParent <Rigidbody>(); if (rand.droppedNotSpawned == false) { x = rand.GetRandom() / 100.0f; y = rand.GetRandom() / 100.0f; z = rand.GetRandom() / 100.0f; if (x < 5.0f) { x -= 5.0f; } if (y < 5.0f) { y -= 5.0f; } if (z < 5.0f) { z -= 5.0f; } vel = new Vector3(x, y, z); rb.velocity = vel; } else if (rand.droppedNotSpawned == true) { Vector3 dropDir = rand.playerDropPoint.position - rand.playerPos.position; rb.velocity = new Vector3(dropDir.x * 50 * Time.deltaTime, 0.0f, dropDir.z * 50 * Time.deltaTime); } Destroy(this.gameObject, 60.0f); }
//public static Random rnd = new Random(1337); private static List <LayoutRoom> generateLayout(MapParams parameter) { LayoutRoom r = new LayoutRoom(new[] { new Point(0, 0), new Point(parameter.width, 0), new Point(parameter.width, parameter.height), new Point(0, parameter.height) }); List <LayoutRoom> rooms = new List <LayoutRoom>(); Queue <LayoutRoom> toCompute = new Queue <LayoutRoom>(); toCompute.Enqueue(r); LayoutRoom current; int spl; bool splitH = false; while (toCompute.Count != 0) { current = toCompute.Dequeue(); Tuple <LayoutRoom, LayoutRoom> ret; if (current.AvailableForSplitH(MIN_ROOM_SIZE, MAX_ROOM_SIZE) && current.AvailableForSplitV(MIN_ROOM_SIZE, MAX_ROOM_SIZE)) { spl = RandomGen.GetRandom(MIN_ROOM_SIZE, (splitH ? current.Bounds.Height : current.Bounds.Width) - MIN_ROOM_SIZE); ret = splitH ? current.SplitHorizontal(spl) : current.SplitVertical(spl); } else if (current.AvailableForSplitV(MIN_ROOM_SIZE, MAX_ROOM_SIZE)) { spl = RandomGen.GetRandom(MIN_ROOM_SIZE, current.Bounds.Width - MIN_ROOM_SIZE); ret = current.SplitVertical(spl); } else { spl = RandomGen.GetRandom(MIN_ROOM_SIZE, current.Bounds.Height - MIN_ROOM_SIZE); ret = current.SplitHorizontal(spl); } splitH = !splitH; if (ret.Item1.AvailableForSplit(MIN_ROOM_SIZE, MAX_ROOM_SIZE)) { toCompute.Enqueue(ret.Item1); } else { rooms.Add(ret.Item1); } if (ret.Item2.AvailableForSplit(MIN_ROOM_SIZE, MAX_ROOM_SIZE)) { toCompute.Enqueue(ret.Item2); } else { rooms.Add(ret.Item2); } } return(rooms); }
public Tuple <Corridor, Corridor, Room> ToGameplayObjects() { int val = RandomGen.GetRandom(0, 3); if (val == 0) //Only Up { Tuple <LayoutRoom, LayoutRoom> tmp = SplitVertical(Bounds.Width - MapGenerator.DOORWAY_SIZE); return(new Tuple <Corridor, Corridor, Room>(null, new Corridor(tmp.Item2.Vertices), new Room(tmp.Item1.Vertices))); } else if (val == 1) //Both Corridors { Tuple <LayoutRoom, LayoutRoom> tmp = SplitHorizontal(MapGenerator.DOORWAY_SIZE); Corridor c = new Corridor(tmp.Item1.Vertices); tmp = tmp.Item2.SplitVertical(tmp.Item2.Bounds.Width - MapGenerator.DOORWAY_SIZE); return(new Tuple <Corridor, Corridor, Room>(c, new Corridor(tmp.Item2.Vertices), new Room(tmp.Item1.Vertices))); } else //Only Right { Tuple <LayoutRoom, LayoutRoom> tmp = SplitHorizontal(MapGenerator.DOORWAY_SIZE); Corridor c = new Corridor(tmp.Item1.Vertices); return(new Tuple <Corridor, Corridor, Room>(c, null, new Room(tmp.Item2.Vertices))); } }
public static void Populate(Room input, Corridor up, Corridor right) { up?.Generate(); right?.Generate(); Color col = Color.Red; input.data = new Color[input.Bounds.Width, input.Bounds.Height]; for (int i = 0; i < input.Vertices.Length; i++) { MapGenerator.DrawLine(input.Vertices[i].X, input.Vertices[i].Y, input.Vertices[i % input.Vertices.Length].X, input.Vertices[i % input.Vertices.Length].Y, input.data, col); } //for (int w = 0; w < input.Data.GetLength(0); w++) //{ // for (int h = 0; h < input.Data.GetLength(1); h++) // { // input.Data[w, h] = col; // } //} int side = RandomGen.GetRandom(0, 2); if (up == null && side == 0) { side = 1; } if (right == null && side == 1) { side = 0; } //for (int i = 0; i < input.Data.GetLength(0); i++) //{ // for (int j = 0; j < input.Data.GetLength(1); j++) // { // if (i == 0 || (i == input.Data.GetLength(0) - 1 && right != null) || (j == 0 && up != null) || j == input.Data.GetLength(1) - 1) // { // if (WallDecoProbablity * 10000 >= RandomGen.GetRandom(0, 10000)) // { // input.Data[i, j] = Color.Gold; // } // } // } //} //Point doorPs; //Corridor c = null; //if (side == 0) //{ // int doorPos = RandomGen.GetRandom(0, input.Data.GetLength(side) - MapGenerator.DOOR_SIZE); // doorPs = new Point(doorPos, 0); // c = up; // for (int i = doorPos; i < doorPos + MapGenerator.DOOR_SIZE; i++) // { // for (int j = 0; j < MapGenerator.DOOR_SIZE; j++) // { // input.Data[i, j] = Color.Green; // } // } //} //else //{ // c = right; // int doorPos = RandomGen.GetRandom(MapGenerator.DOOR_SIZE, input.Data.GetLength(side) - MapGenerator.DOOR_SIZE); // doorPs = new Point(input.Data.GetLength(0) - MapGenerator.DOOR_SIZE, doorPos); // for (int i = input.Data.GetLength(0) - MapGenerator.DOOR_SIZE; i < input.Data.GetLength(0); i++) // { // for (int j = doorPos; j < doorPos + MapGenerator.DOOR_SIZE; j++) // { // input.Data[i, j] = Color.Green; // } // } //} //input.door = new Door(doorPs, input, c); }