IEnumerator FinishedRoom(RoomNode curNode, RoomInstance curRoomInstance) { yield return(new WaitUntil(() => curRoomInstance.getToDestination != MydirectionData.DirectionEnum.Notready)); var curDir = curRoomInstance.getToDestination; int x = curNode.gridX, y = curNode.gridY; MydirectionData.SetDirection(curDir, ref x, ref y); if (x < rMax * 2 && x >= 0 && y >= 0 && y < cMax * 2 && _roomDataGenerator.rooms[x, y] != null) { lastRoom = curNode; var nextNode = _roomDataGenerator.rooms[x, y]; if (true) { curRoomInstance.isCurrent = false; NextRoom(nextNode); } } else { StartCoroutine(FinishedRoom(currentRoom, curRoomInstance)); } }
public void NextRoom(RoomNode node) { var roomInstance = _levelGenerator.CreateNewRoomInstance(node); currentRoom = node; visitedSet.Add(node); StartCoroutine(FinishedRoom(node, roomInstance)); }
public void SetRoomInstanceInfo(RoomInstance roomInstance, RoomNode room) { if (roomConstructor.lastRoom != null) { roomInstance.lastNode = roomConstructor.lastRoom; } roomInstance.roomDoors |= room.doorTop != null ? MydirectionData.DirectionEnum.Up : MydirectionData.DirectionEnum.Notready; roomInstance.roomDoors |= room.doorBot != null ? MydirectionData.DirectionEnum.Down : MydirectionData.DirectionEnum.Notready; roomInstance.roomDoors |= room.doorRight != null ? MydirectionData.DirectionEnum.Right : MydirectionData.DirectionEnum.Notready; roomInstance.roomDoors |= room.doorLeft != null ? MydirectionData.DirectionEnum.Left : MydirectionData.DirectionEnum.Notready; }
void DrawMapper(RoomNode room) { Vector2 drawPos = new Vector2(room.gridX, room.gridY); drawPos.x *= gridSizeX;//aspect ratio of map sprite drawPos.y *= gridSizeY; //create map obj and assign its variables MapSpriteSelector mapper = Object.Instantiate(roomMapSprit, drawPos, Quaternion.identity).GetComponent <MapSpriteSelector>(); mapper.type = room.roomType; mapper.up = room.doorTop != null; mapper.down = room.doorBot != null; mapper.right = room.doorRight != null; mapper.left = room.doorLeft != null; mapper.gameObject.transform.parent = mapRoot; }
public void FromDimension(int gridHalfextentsX, int gridHalfextentsY, int numberOfRooms, int _PotentailDoors) { bool walkable = true; rooms = new RoomNode[gridHalfextentsX * 2, gridHalfextentsY * 2]; path = new HashSet <RoomNode>(); takenPositions = new List <Vector2>(); gridSizeX = gridHalfextentsX; gridSizeY = gridHalfextentsY; PotentailDoors = _PotentailDoors; takenPositions.Insert(0, Vector2.zero); rooms[gridHalfextentsX, gridHalfextentsY] = new RoomNode(walkable, gridHalfextentsX, gridHalfextentsY, new Vector3(gridHalfextentsX, gridHalfextentsY, 0)); rooms[gridHalfextentsX, gridHalfextentsY].roomType = RoomType.origin; path.Add(rooms[gridHalfextentsX, gridHalfextentsY]); Vector2 checkPos = Vector2.zero; //magic numbers float randomCompare = .2f, randomCompareStart = .2f, randomCompareEnd = .01f; for (int i = 0; i < numberOfRooms - 1; i++) { float randomPerc = ((float)i) / ((float)numberOfRooms - 1); randomCompare = Mathf.Lerp(randomCompareStart, randomCompareEnd, randomPerc); checkPos = NewPosition(); if (NumberOfNeighbors(checkPos) > 1 && Random.value > randomCompare) { int iteration = 0; do { checkPos = SelectiveNewPosition(); iteration++; } while (NumberOfNeighbors(checkPos) > 1 && iteration < 30); if (iteration >= 50) { Debug.Log("error: could not create with fewer neighbors than : " + NumberOfNeighbors(checkPos)); } } int gridX = (int)checkPos.x + gridHalfextentsX, gridY = (int)checkPos.y + gridHalfextentsY; rooms[gridX, gridY] = new RoomNode(walkable, gridX, gridY, new Vector3(gridX, gridY, 0)); takenPositions.Insert(0, checkPos); path.Add(rooms[gridX, gridY]); } }
void SetRoomDoors(RoomNode node) { int x = node.gridX, y = node.gridY; if (y - 1 >= 0) { node.doorBot = rooms[x, y - 1]; } if (y + 1 < gridSizeY * 2) { node.doorTop = rooms[x, y + 1]; } if (x - 1 >= 0) { node.doorLeft = rooms[x - 1, y]; } if (x + 1 < gridSizeX * 2) { node.doorRight = rooms[x + 1, y]; } }
public RoomInstance CreateNewRoomInstance(RoomNode node) { if (curRoom == null) { curRoom = Instantiate(roomObject, Vector3.zero, Quaternion.identity); curRoom.name = "room01"; curRoom.transform.parent = transform; } else { Destroy(curRoom); curRoom = Instantiate(roomObject, Vector3.zero, Quaternion.identity); curRoom.name = "room02"; curRoom.transform.parent = transform; } var roomInstance = curRoom.GetComponent <RoomInstance>(); SetRoomInstanceInfo(roomInstance, node); return(roomInstance); }