Beispiel #1
0
        public static GroundMap BuildEndingMap(GroundBlockMap leftBlock, GroundBlockMap rightBlock, GroundBlockMap middleBlock)
        {
            int depthsDiff = -leftBlock.GetDepth();

            GroundMap endingMap = new GroundMap();

            GroundBlockMap endingBlockLeft = new GroundBlockMap();

            endingBlockLeft.position = leftBlock.position + new IntVector2(0, leftBlock.size.y + depthsDiff);
            endingBlockLeft.size     = new IntVector2(leftBlock.size.x, middleBlock.position.y + middleBlock.size.y - leftBlock.position.y - leftBlock.size.y);
            endingBlockLeft.AddBorder(BorderDirction.West);
            endingMap.AddBlock(endingBlockLeft);

            GroundBlockMap endingBlockRight = new GroundBlockMap();

            endingBlockRight.position = rightBlock.position + new IntVector2(0, rightBlock.size.y + depthsDiff);
            endingBlockRight.size     = new IntVector2(rightBlock.size.x, middleBlock.position.y + middleBlock.size.y - rightBlock.position.y - rightBlock.size.y);
            endingBlockRight.AddBorder(BorderDirction.East);
            endingMap.AddBlock(endingBlockRight);

            GroundBlockMap endingBlock = new GroundBlockMap();

            endingBlock.position = endingBlockLeft.position + new IntVector2(0, endingBlockLeft.size.y);
            endingBlock.size     = new IntVector2(endingBlockLeft.size.x + middleBlock.size.x + endingBlockRight.size.x, 1);
            endingMap.AddBlock(endingBlock);
            return(endingMap);
        }
Beispiel #2
0
        public static GroundMap GenerateRandom(int blocksCount = 40)
        {
            GroundMap newGround = new GroundMap();

            while (newGround.count < blocksCount)
            {
                GroundBlockMap newBlock  = GroundBlockMap.GenerateRandom();
                GroundBlockMap lastBlock = newGround.GetLastBlock();
                if (lastBlock != null)
                {
                    int xR = Random.Range(-newBlock.size.x + 3, lastBlock.size.x - 3);
                    newBlock.position = lastBlock.position + new IntVector2(xR, lastBlock.size.y);
                }
                newBlock.AddBorder(BorderDirction.South);
                newGround.AddBlock(newBlock);
            }
            return(newGround);
        }
Beispiel #3
0
        public GroundMap GetRightMould()
        {
            GroundMap newGround = new GroundMap();

            foreach (GroundBlockMap block in blocksList)
            {
                int            minSizeX  = 1;
                GroundBlockMap prevBlock = GetPrevBlock(block);
                GroundBlockMap nextBlock = GetNextBlock(block);

                if (prevBlock != null && nextBlock != null)
                {
                    int prevX = Mathf.Abs(prevBlock.position.x + prevBlock.size.x - block.position.x - block.size.x);
                    int nextX = Mathf.Abs(nextBlock.position.x + nextBlock.size.x - block.position.x - block.size.x);
                    if (block.position.x + block.size.x >= prevBlock.position.x + prevBlock.size.x &&
                        block.position.x + block.size.x >= nextBlock.position.x + nextBlock.size.x)
                    {
                        minSizeX = 1;
                    }
                    else
                    {
                        if (prevBlock.position.x + prevBlock.size.x > nextBlock.position.x + nextBlock.size.x)
                        {
                            minSizeX = prevX;
                        }
                        else
                        {
                            minSizeX = nextX;
                        }
                    }
                }
                else if (prevBlock != null)
                {
                    if (block.position.x + block.size.x >= prevBlock.position.x + prevBlock.size.x)
                    {
                        minSizeX = 1;
                    }
                    else
                    {
                        minSizeX = Mathf.Abs(prevBlock.position.x + prevBlock.size.x - block.position.x - block.size.x);
                    }
                }
                else if (nextBlock != null)
                {
                    if (block.position.x + block.size.x >= nextBlock.position.x + nextBlock.size.x)
                    {
                        minSizeX = 1;
                    }
                    else
                    {
                        minSizeX = Mathf.Abs(nextBlock.position.x + nextBlock.size.x - block.position.x - block.size.x);
                    }
                }

                GroundBlockMap newBlock = new GroundBlockMap();
                int            sizeX    = Random.Range(minSizeX, minSizeX + 5);
                newBlock.size     = new IntVector2(sizeX, block.size.y);
                newBlock.position = new IntVector2(block.position.x + block.size.x, block.position.y);

                newBlock.AddBorder(BorderDirction.East);
                newBlock.AddBorder(BorderDirction.South);
                newGround.AddBlock(newBlock);
            }
            return(newGround);
        }
Beispiel #4
0
        public GroundMap GetLeftMould()
        {
            GroundMap newGround = new GroundMap();

            for (int i = 0; i < count; i++)
            {
                GroundBlockMap block     = blocksList[i];
                int            minSizeX  = 1;
                GroundBlockMap prevBlock = GetPrevBlock(block);
                GroundBlockMap nextBlock = GetNextBlock(block);
                if (prevBlock != null && nextBlock != null)
                {
                    int prevX = Mathf.Abs(prevBlock.position.x - block.position.x);
                    int nextX = Mathf.Abs(nextBlock.position.x - block.position.x);
                    if (block.position.x <= prevBlock.position.x && block.position.x <= nextBlock.position.x)
                    {
                        minSizeX = 1;
                    }
                    else
                    {
                        if (prevBlock.position.x < nextBlock.position.x)
                        {
                            minSizeX = prevX;
                        }
                        else
                        {
                            minSizeX = nextX;
                        }
                    }
                }
                else if (prevBlock != null)
                {
                    if (block.position.x <= prevBlock.position.x)
                    {
                        minSizeX = 1;
                    }
                    else
                    {
                        minSizeX = Mathf.Abs(prevBlock.position.x - block.position.x);
                    }
                }
                else if (nextBlock != null)
                {
                    if (block.position.x <= nextBlock.position.x)
                    {
                        minSizeX = 1;
                    }
                    else
                    {
                        minSizeX = Mathf.Abs(nextBlock.position.x - block.position.x);
                    }
                }

                GroundBlockMap newBlock = new GroundBlockMap();
                int            sizeX    = Random.Range(minSizeX, minSizeX + 5);
                newBlock.size     = new IntVector2(sizeX, block.size.y);
                newBlock.position = new IntVector2(block.position.x - newBlock.size.x, block.position.y);

                newBlock.AddBorder(BorderDirction.West);
                newBlock.AddBorder(BorderDirction.South);
                newGround.AddBlock(newBlock);
            }
            return(newGround);
        }