Example #1
0
        private List <LevelBlock> GetMatchingBlocks(MatchBlock matchBlock)
        {
            var result = new List <LevelBlock>();

            foreach (var block in blocks)
            {
                var currentBlock = block;

                do
                {
                    if (matchBlock.Match(currentBlock))
                    {
                        result.Add(currentBlock);
                    }

                    currentBlock = currentBlock.GetNextRotation();
                } while (currentBlock.currentRotation != 0); // we are back at starting rotation
            }

            return(result);
        }
Example #2
0
        // yeah... this is quite dirty code, but I did not find any other way, we need to manually check
        // all corresponding side to their opposite
        private MatchBlock ComputeMatchBlockAtCoord(int x, int z, int y)
        {
            var match = new MatchBlock();

            if (y + 1 >= height) // if upper is outside of bounds, we need to close
            {
                for (var i = 0; i < 4; i++)
                {
                    match.topFaces[i] = NeededFace.Any;
                }
            }
            else if (_level[x, z, y + 1] == null) // if no block is there yet, we might put anything
            {
                for (var i = 0; i < 4; i++)
                {
                    match.topFaces[i] = NeededFace.Any;
                }
            }
            else // if there is a block we get what it needs
            {
                var upperBlock = _level[x, z, y + 1];
                for (var i = 0; i < 4; i++)
                {
                    match.topFaces[i] = upperBlock.botFaces[i].nextNeededFace;
                }
            }

            // same but opposite (lower block to bottom)
            if (y - 1 < 0)
            {
                for (var i = 0; i < match.botFaces.Length; i++)
                {
                    match.botFaces[i] = NeededFace.Close;
                }
            }
            else if (_level[x, z, y - 1] == null)
            {
                for (var i = 0; i < match.botFaces.Length; i++)
                {
                    match.botFaces[i] = NeededFace.Any;
                }
            }
            else
            {
                var lowerBlock = _level[x, z, y - 1];
                for (var i = 0; i < 4; i++)
                {
                    match.botFaces[i] = lowerBlock.topFaces[i].nextNeededFace;
                }
            }

            // same but on each side :
            // right
            if (x + 1 >= width)
            {
                match.sideFaces[6] = NeededFace.Close;
                match.sideFaces[7] = NeededFace.Close;
            }
            else if (_level[x + 1, z, y] == null)
            {
                match.sideFaces[6] = NeededFace.Any;
                match.sideFaces[7] = NeededFace.Any;
            }
            else
            {
                var sideBlock = _level[x + 1, z, y];
                match.sideFaces[6] = sideBlock.sideFaces[3].nextNeededFace;
                match.sideFaces[7] = sideBlock.sideFaces[2].nextNeededFace;
            }

            // left
            if (x - 1 < 0)
            {
                match.sideFaces[2] = NeededFace.Close;
                match.sideFaces[3] = NeededFace.Close;
            }
            else if (_level[x - 1, z, y] == null)
            {
                match.sideFaces[2] = NeededFace.Any;
                match.sideFaces[3] = NeededFace.Any;
            }
            else
            {
                var sideBlock = _level[x - 1, z, y];
                match.sideFaces[2] = sideBlock.sideFaces[7].nextNeededFace;
                match.sideFaces[3] = sideBlock.sideFaces[6].nextNeededFace;
            }

            // front
            if (z + 1 >= lenght)
            {
                match.sideFaces[0] = NeededFace.Close;
                match.sideFaces[1] = NeededFace.Close;
            }
            else if (_level[x, z + 1, y] == null)
            {
                match.sideFaces[0] = NeededFace.Any;
                match.sideFaces[1] = NeededFace.Any;
            }
            else
            {
                var sideBlock = _level[x, z + 1, y];
                match.sideFaces[0] = sideBlock.sideFaces[5].nextNeededFace;
                match.sideFaces[1] = sideBlock.sideFaces[4].nextNeededFace;
            }

            // back
            if (z - 1 < 0)
            {
                match.sideFaces[4] = NeededFace.Close;
                match.sideFaces[5] = NeededFace.Close;
            }
            else if (_level[x, z - 1, y] == null)
            {
                match.sideFaces[4] = NeededFace.Any;
                match.sideFaces[5] = NeededFace.Any;
            }
            else
            {
                var sideBlock = _level[x, z - 1, y];
                match.sideFaces[4] = sideBlock.sideFaces[1].nextNeededFace;
                match.sideFaces[5] = sideBlock.sideFaces[0].nextNeededFace;
            }

            return(match);
        }