public void CreateInitialLevel() { const short lSize = 12; var realLevelChunks = new List<Chunk>(); _level = new Level(); var startPosition = new Vector2s(0,0); { var firstChunk = new Chunk(startPosition, ChunkData.SquareRoomEmpty()); _level[startPosition] = firstChunk; realLevelChunks.Add(firstChunk); } var previousPosition = startPosition; const int Num_Walks = 12; for (int number = 0; number < Num_Walks; number++) { Vector2s newPos; if (Random.value > 0.5f) newPos = new Vector2s((short)(previousPosition.x + 1), previousPosition.y); else newPos = new Vector2s(previousPosition.x, (short)(previousPosition.y + 1)); Chunk testChunk; if (number == Num_Walks - 1) testChunk = new Chunk(newPos, ChunkData.TreasureRoom()); else testChunk = new Chunk(newPos, ChunkData.SquareRoomRandom()); _level[newPos] = testChunk; realLevelChunks.Add(testChunk); previousPosition = new Vector2s(newPos.x, newPos.y); } foreach (var chunk in realLevelChunks.ToArray()) { chunk.Place(); var neighbours = _level.GetNeighbours(chunk.position); foreach (var keyValuePair in neighbours) { if (keyValuePair.Value == null) { if (Random.value > 0.6f) { var newNeighbour = new Chunk(keyValuePair.Key, ChunkData.SquareRoomRandom()); _level[keyValuePair.Key] = newNeighbour; newNeighbour.Place(); realLevelChunks.Add(newNeighbour); } } } } foreach (var chunk in realLevelChunks.ToArray()) { chunk.Place(); var neighbours = _level.GetNeighbours(chunk.position); foreach (var keyValuePair in neighbours) { if (keyValuePair.Value == null) { if (Random.value > 0.7f) { var newNeighbour = new Chunk(keyValuePair.Key, ChunkData.SquareRoomRandom()); _level[keyValuePair.Key] = newNeighbour; newNeighbour.Place(); realLevelChunks.Add(newNeighbour); } } } } foreach (var chunk in realLevelChunks.ToArray()) { chunk.Place(); var neighbours = _level.GetNeighbours(chunk.position); foreach (var keyValuePair in neighbours) { if (keyValuePair.Value == null) { var newNeighbour = new Chunk(keyValuePair.Key, ChunkData.SolidRoom()); _level[keyValuePair.Key] = newNeighbour; newNeighbour.Place(); } } } /* for (short i = -lSize; i < lSize; i++) { for (short j = -lSize; j < lSize; j++) { var testPosition = new Vector2s(i, j); var testChunk = new Chunk(testPosition, ChunkData.SquareRoomRandom()); _level[testPosition] = testChunk; testChunk.Place(); } } */ }
public KeyValuePair<Vector2s, Chunk>[] GetNeighbours(Chunk chunk) { return GetNeighbours(chunk.position); }