public Square(ControlNode topLeft, ControlNode topRight, ControlNode bottomLeft, ControlNode bottomRight) { TopLeft = topLeft; TopRight = topRight; BottomLeft = bottomLeft; BottomRight = bottomRight; CenterTop = topLeft.Right; CenterRight = bottomRight.Above; CenterBottom = bottomLeft.Right; CenterLeft = bottomLeft.Above; Configuration += Convert.ToInt32(TopLeft.Active) << 3; Configuration += Convert.ToInt32(TopRight.Active) << 2; Configuration += Convert.ToInt32(BottomRight.Active) << 1; Configuration += Convert.ToInt32(BottomLeft.Active); }
public SquareGrid(int[,] map, float squareSize) { var nodeCountX = map.GetLength(0); var nodeCountY = map.GetLength(1); var mapWidth = nodeCountX * squareSize; var mapHeight = nodeCountY * squareSize; var controlNodes = new ControlNode[nodeCountX, nodeCountY]; for (var x = 0; x < nodeCountX; x++) { for (var y = 0; y < nodeCountY; y++) { var pos = new Vector3(-mapWidth / 2 + x * squareSize + squareSize / 2, 0, -mapHeight / 2 + y * squareSize + squareSize / 2); controlNodes[x, y] = new ControlNode(pos, map[x, y] == 1, squareSize); } } Squares = new Square[nodeCountX - 1, nodeCountY - 1]; for (var x = 0; x < nodeCountX - 1; x++) { for (var y = 0; y < nodeCountY - 1; y++) { Squares[x, y] = new Square(controlNodes[x, y + 1], controlNodes[x + 1, y + 1], controlNodes[x, y], controlNodes[x + 1, y]); } } }
public Square(ControlNode _topLeft, ControlNode _topRight, ControlNode _bottomRight, ControlNode _bottomLeft) { topLeft = _topLeft; topRight = _topRight; bottomRight = _bottomRight; bottomLeft = _bottomLeft; centreTop = topLeft.right; centreRight = bottomRight.above; centreBottom = bottomLeft.right; centreLeft = bottomLeft.above; if (topLeft.active) configuration += 8; if (topRight.active) configuration += 4; if (bottomRight.active) configuration += 2; if (bottomLeft.active) configuration += 1; }