// Create WorldGridChunks public void Build() { //ElevationGenerator.PrintHeightMap(this); for (int i = 0; i < WorldSegmentChunkSize.X; i++) { for (int j = 0; j < WorldSegmentChunkSize.Y; j++) { var worldGridChunkExists = WorldLoader.DoesWorldGridChunkExist(startChunkPosition.X + i, startChunkPosition.Y + j); if (worldGridChunkExists == true) { continue; } if (Blocks[i * WorldGrid.WorldChunkBlockSize.X, j *WorldGrid.WorldChunkBlockSize.Y].BlockId == BlockType.Invalid) { continue; } var chunkBlockPosition = new Point(startBlockPosition.X + i * WorldGrid.WorldChunkBlockSize.X, startBlockPosition.Y + j * WorldGrid.WorldChunkBlockSize.Y); WorldGridChunk worldGridChunk = new WorldGridChunk(WorldGrid.BlockSize.X * chunkBlockPosition.X, WorldGrid.BlockSize.Y * chunkBlockPosition.Y); WalkableGridChunk walkableGridChunk = WalkableGridChunk.CreateEmpty(startChunkPosition.X + i, startChunkPosition.Y + j); worldGridChunk.SetBiomeType(Biome); for (int x = 0; x < WorldGrid.WorldChunkBlockSize.X; x++) { for (int y = 0; y < WorldGrid.WorldChunkBlockSize.Y; y++) { var blockPosition = new Point(chunkBlockPosition.X + x, chunkBlockPosition.Y + y); var worldSegmentPosition = new Point(i * WorldGrid.WorldChunkBlockSize.X + x, j * WorldGrid.WorldChunkBlockSize.Y + y); worldGridChunk.SetBlockType(blockPosition.X, blockPosition.Y, Blocks[worldSegmentPosition.X, worldSegmentPosition.Y].BlockId); if (CollisionUtils.IsBlockBlocking(Blocks[worldSegmentPosition.X, worldSegmentPosition.Y].BlockId)) { walkableGridChunk.SetWalkable(blockPosition.X, blockPosition.Y, false); } } } WorldLoader.SaveWorldGridChunk(startChunkPosition.X + i, startChunkPosition.Y + j, worldGridChunk); WorldLoader.SaveWalkableGridChunk(startChunkPosition.X + i, startChunkPosition.Y + j, walkableGridChunk); } } }
public bool Init() { bool doesSegmentAlreadyExist = true; for (int i = 0; i < WorldSegmentChunkSize.X; i++) { for (int j = 0; j < WorldSegmentChunkSize.Y; j++) { var worldGridChunkExists = WorldLoader.DoesWorldGridChunkExist(startChunkPosition.X + i, startChunkPosition.Y + j); var chunkBlockPosition = new Point(i * WorldGrid.WorldChunkBlockSize.X, j * WorldGrid.WorldChunkBlockSize.Y); for (int x = 0; x < WorldGrid.WorldChunkBlockSize.X; x++) { for (int y = 0; y < WorldGrid.WorldChunkBlockSize.Y; y++) { var blockPositionWithin = new Point(chunkBlockPosition.X + x, chunkBlockPosition.Y + y); if (worldGridChunkExists) { Blocks[blockPositionWithin.X, blockPositionWithin.Y] = null; } else { doesSegmentAlreadyExist = false; Blocks[blockPositionWithin.X, blockPositionWithin.Y] = new BlockInformation() { BlockId = Biome.MainTilesIds[0] }; } } } } } return(!doesSegmentAlreadyExist); }