private void PutBlock(int blockX, int blockY, PredefinedBlock block) { var blockMap = block.Map; Debug.Log($"({blockX}, {blockY}) block={block}"); map.PutMap( blockX * PredefinedBlock.Width, blockY * PredefinedBlock.Height, blockMap ); }
private bool TryGetBlockMatchingMask(int mask, out PredefinedBlock predefinedBlock) { foreach (var block in predefinedBlocks) { if (block.Bitmask != mask) { continue; } predefinedBlock = block; return(true); } predefinedBlock = null; return(false); }
public Block(PredefinedBlock predefinedBlock) { PredefinedBlock = predefinedBlock; occupiedSpawnPoint = Enumerable.Repeat(false, 4).ToArray(); }
private void SpawnNode(Vector2Int pos) { int requirePresent = 0; int requireAbsent = GetRequireAbsentMask(pos); int bitmask; List <int> empty = new List <int>(); if (blocksBitmasks.TryGetValue(new Vector2Int(pos.x - 1, pos.y), out bitmask)) { if ((bitmask & Direction.Right.Bitmask) != 0) { requirePresent |= Direction.Left.Bitmask; } else { requireAbsent |= Direction.Left.Bitmask; } } else if ((requireAbsent & Direction.Left.Bitmask) == 0) { empty.Add(Direction.Left.Bitmask); } if (blocksBitmasks.TryGetValue(new Vector2Int(pos.x + 1, pos.y), out bitmask)) { if ((bitmask & Direction.Left.Bitmask) != 0) { requirePresent |= Direction.Right.Bitmask; } else { requireAbsent |= Direction.Right.Bitmask; } } else if ((requireAbsent & Direction.Right.Bitmask) == 0) { empty.Add(Direction.Right.Bitmask); } if (blocksBitmasks.TryGetValue(new Vector2Int(pos.x, pos.y - 1), out bitmask)) { if ((bitmask & Direction.Up.Bitmask) != 0) { requirePresent |= Direction.Down.Bitmask; } else { requireAbsent |= Direction.Down.Bitmask; } } else if ((requireAbsent & Direction.Down.Bitmask) == 0) { empty.Add(Direction.Down.Bitmask); } if (blocksBitmasks.TryGetValue(new Vector2Int(pos.x, pos.y + 1), out bitmask)) { if ((bitmask & Direction.Down.Bitmask) != 0) { requirePresent |= Direction.Up.Bitmask; } else { requireAbsent |= Direction.Up.Bitmask; } } else if ((requireAbsent & Direction.Up.Bitmask) == 0) { empty.Add(Direction.Up.Bitmask); } if (empty.Count > 0) { requirePresent |= empty[Random.Range(0, empty.Count)]; } PredefinedBlock block = GetRandomBlockMatchingMask(requirePresent, requireAbsent); PutBlock(pos.x, pos.y, block); blocksBitmasks[pos] = block.Bitmask; }
public BlockPassageChecker(int x, int y, PredefinedBlock block, Map map) { this.block = block; this.map = map; this.globalCoords = CalcBlockGlobalCoords(x, y); }