public ChunkBuilder(IntVector2 chunkWorldCenterpoint, int chunkSize) { ChunkSize = chunkSize; Position = new IntVector2(chunkWorldCenterpoint); BottomLeftCorner = new IntVector2(chunkWorldCenterpoint.X - _halfChunkSize, chunkWorldCenterpoint.Y - _halfChunkSize); TopRightCorner = new IntVector2(chunkWorldCenterpoint.X + _halfChunkSize - 1, chunkWorldCenterpoint.Y + _halfChunkSize - 1); Depth = Position.Y / ChunkSize; Remoteness = Mathf.Abs(Position.X / ChunkSize) + Mathf.Abs(Position.Y / ChunkSize); // Initialize all blocks in chunk to the default value for (var row = 0; row < ChunkSize; row++) { for (var column = 0; column < ChunkSize; column++) { var offset = new IntVector2(row, column); var blockBuilder = new BlockBuilder(BottomLeftCorner + offset); _blockBuilders.Add(blockBuilder); _blockMap.Add(blockBuilder.Position, blockBuilder); } } OnChunkBuilderChanged.Raise(this); }
public ChunkBuilder AddBlocks(params BlockTypes[] blocksToAdd) { // Randomly order the blocks (without actually changing their order, // because that would be unnecessarily expensive and may change other // effects. var selectionOrder = Chance.ExclusiveRandomOrder(_blockBuilders.Count); var addedBlocks = 0; for (var blockIndex = 0; blockIndex < _blockBuilders.Count; blockIndex++) { // Foreach block, if it the randomized order shows it as one of the // first blocks, assign it to the blockType specified in the matching // index of blocks to add. if (selectionOrder[blockIndex] < blocksToAdd.Length) { _blockBuilders[blockIndex].SetType(blocksToAdd[selectionOrder[blockIndex]]); addedBlocks++; // If we have added all blocks, break. if (addedBlocks >= blocksToAdd.Length) { break; } } } OnChunkBuilderChanged.Raise(this); return(this); }
public ChunkBuilder SetFill(BlockTypes fillBlock) { FillBlock = fillBlock; OnChunkBuilderChanged.Raise(this); return(this); }
public ChunkBuilder AddEnemy(EnemyHealth enemy) { _enemies.Add(enemy); enemy.gameObject.SetActive(false); OnChunkBuilderChanged.Raise(this); return(this); }
public ChunkBuilder AddSpace(Space spaceToAdd) { _spaces.Add(spaceToAdd); foreach (var bBuilder in _blockBuilders) { if (spaceToAdd.Contains(bBuilder.Position)) { bBuilder.SetSpace(spaceToAdd); } } OnChunkBuilderChanged.Raise(this); return(this); }