private IEnumerator createRoom(List <TezDungeonBlock> total) { int count = 2000; while (count > 0) { count -= 1; bool find = true; int width = m_Random.nextInt(2, 10); int height = m_Random.nextInt(2, 10); var x = m_Random.nextInt(0, (m_Width - width) / 2) * 2 + 1; var y = m_Random.nextInt(0, (m_Height - height) / 2) * 2 + 1; for (int i = 0; i < m_RoomList.Count; i++) { if (m_RoomList[i].collision(x, y, width, height)) { find = false; break; } } if (!find) { continue; } else { var room = new TezDungeonRoom() { ox = x, oy = y, width = width, height = height }; m_RoomList.Add(room); room.foreachRoom( (int ox, int oy) => { if ((ox >= 0 && ox < m_Width) && (oy >= 0 && oy < m_Height)) { m_BlockArray[ox, oy].isInited = true; m_BlockArray[ox, oy].state = TezDungeonBlock.State.CanPass; total.Remove(m_BlockArray[ox, oy]); onCanPassCreated?.Invoke(ox, oy); } }, (int ox, int oy) => { if ((ox >= 0 && ox < m_Width) && (oy >= 0 && oy < m_Height)) { m_BlockArray[ox, oy].isInited = true; m_BlockArray[ox, oy].state = TezDungeonBlock.State.CanNotPass; total.Remove(m_BlockArray[ox, oy]); onCanNotPassCreated?.Invoke(ox, oy); } }); } yield return(null); } }
public bool collision(TezDungeonRoom room) { return(!(room.maxX < this.ox - 1 || room.ox > this.maxX + 1 || room.maxY < this.oy - 1 || room.oy > this.maxY + 1)); }