예제 #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);
        }
예제 #2
0
        public void removeBlock(Block block)
        {
            if (grid == null)
            {
                clear();
            }
            if (!placedBlocks.Contains(block))
            {
                return;
            }
            placedBlocks.Remove(block);
            for (int y = 0; y < blockHeight; y++)
            {
                for (int x = 0; x < blockWidth; x++)
                {
                    if (grid [x, y] != null && grid [x, y].Equals(block))
                    {
                        grid [x, y] = null;
                    }
                }
            }

            block
            .setPos(null)
            .setRotation(0);

            hasChanged = true;
        }