Exemple #1
0
        public bool setBlock(int x, int y, Block block, float deg = 0)
        {
            if (grid == null)
            {
                clear();
            }
            hasChanged = true;

            removeBlock(block);

            Vector2 start = new Vector2(x, y);
            Vector2 least = getLeast(block, deg);

            foreach (Vector2 col in block.getCollision())
            {
                Vector2 temp = getGridPoint(col, start, least, deg);
                grid [(int)temp.x, (int)temp.y] = block;
            }

            placedBlocks.Add(block);

            block
            .setPos(start)
            .setRotation(deg);

            return(true);
        }
Exemple #2
0
        public bool canSet(int x, int y, Block block, float deg = 0)
        {
            Vector2 start = new Vector2(x, y);

            if (grid == null)
            {
                clear();
            }

            Vector2 calc = VectorCalculation.revertToOrigin(start, this);

            if (calc.x >= getWidth() || calc.y >= getHeight())
            {
                return(false);
            }


            Vector2 least = getLeast(block, deg);

            foreach (Vector2 col in block.getCollision())
            {
                Vector2 temp = getGridPoint(col, start, least, deg);
                if (temp.x >= getWidth() || temp.y >= getHeight() || getPos(temp) != null)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #3
0
        private Vector2 getLeast(Block block, float deg)
        {
            Vector2 least      = new Vector2();
            bool    calculated = false;

            foreach (Vector2 col in block.getCollision())
            {
                Vector2 temp = VectorCalculation.rotateVector(col, deg);
                if (!calculated)
                {
                    least      = temp;
                    calculated = true;
                }
                if (temp.x < least.x)
                {
                    least.x = temp.x;
                }
                if (temp.y < least.y)
                {
                    least.y = temp.y;
                }
            }
            least.x = Mathf.Abs(least.x);
            least.y = Mathf.Abs(least.y);
            return(least);
        }