public SquareGrid(int[,] map, float squareSize) { int nodeCountX = map.GetLength(0); int nodeCountY = map.GetLength(1); float mapWidth = nodeCountX * squareSize; float mapHeight = nodeCountY * squareSize; ControlJunction[,] controlJunction = new ControlJunction[nodeCountX,nodeCountY]; for (int x = 0; x < nodeCountX; x++){ for (int y =0; y <nodeCountY; y++){ Vector3 pos = new Vector3(-mapWidth/2 + x * squareSize + squareSize/2, 0, -mapHeight/2 + y * squareSize + squareSize/2); controlJunction[x,y] = new ControlJunction(pos, map[x,y] == 1, squareSize); } } squares = new Square[nodeCountX - 1, nodeCountY - 1]; for (int x = 0; x < nodeCountX-1; x++){ for (int y =0; y <nodeCountY-1; y++){ squares[x,y] = new Square(controlJunction[x,y+1], controlJunction[x+1,y+1], controlJunction[x+1,y], controlJunction[x,y]); } } }
public Square(ControlJunction _topLeft, ControlJunction _topRight, ControlJunction _bottomRight, ControlJunction _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; }