Пример #1
0
        public CSquareGrid(int[,] tMap, float tSquareSize)
        {
            int tNodeCountX = tMap.GetLength(0);
            int tNodeCountY = tMap.GetLength(1);

            float tMapWidth  = tNodeCountX * tSquareSize;
            float tMapHeight = tNodeCountY * tSquareSize;

            CControlNode[,] tControlNodes = new CControlNode[tNodeCountX, tNodeCountY];

            Vector3 tPos;

            for (int tx = 0; tx < tNodeCountX; tx++)
            {
                for (int ty = 0; ty < tNodeCountY; ty++)
                {
                    tPos = new Vector3(-tMapWidth / 2 + tx * tSquareSize + tSquareSize / 2, 0, -tMapHeight / 2 + ty * tSquareSize + tSquareSize / 2);
                    tControlNodes[tx, ty] = new CControlNode(tPos, tMap[tx, ty] == 1, tSquareSize);
                }
            }

            mSquares = new CSquare[tNodeCountX - 1, tNodeCountY - 1];
            for (int tx = 0; tx < tNodeCountX - 1; tx++)
            {
                for (int ty = 0; ty < tNodeCountY - 1; ty++)
                {
                    mSquares[tx, ty] = new CSquare(tControlNodes[tx, ty + 1], tControlNodes[tx + 1, ty + 1], tControlNodes[tx + 1, ty], tControlNodes[tx, ty]);
                }
            }
        }
Пример #2
0
        public CSquare(CControlNode tTopLeft, CControlNode tTopRight, CControlNode tBottomRight, CControlNode tBottomLeft)
        {
            mTopLeft     = tTopLeft;
            mTopRight    = tTopRight;
            mBottomRight = tBottomRight;
            mBottomLeft  = tBottomLeft;

            mCenterTop    = mTopLeft.mRight;
            mCenterRight  = mBottomRight.mAbove;
            mCenterBottom = mBottomLeft.mRight;
            mCenterLeft   = mBottomLeft.mAbove;
        }