public Square(MainNode topLeft, MainNode topRight, MainNode bottomLeft, MainNode bottomRight) { this.topLeft = topLeft; this.topRight = topRight; this.bottomLeft = bottomLeft; this.bottomRight = bottomRight; //Assign secondary nodes now based on main nodes' position. this.centreTop = topLeft.right; this.centreRight = bottomRight.up; this.centreLeft = bottomLeft.up; this.centreBottom = bottomLeft.right; //Assign configuration no = which marching square configuration it should be. if (topLeft.ground) { configNo += 8; } if (topRight.ground) { configNo += 4; } if (bottomRight.ground) { configNo += 2; } if (bottomLeft.ground) { configNo += 1; } }
void CreateTriangle(SecondaryNode vert1, SecondaryNode vert2, SecondaryNode vert3) { triangles.Add(vert1.vertexIndex); triangles.Add(vert2.vertexIndex); triangles.Add(vert3.vertexIndex); Triangle triangle = new Triangle(vert1.vertexIndex, vert2.vertexIndex, vert3.vertexIndex); AddTriangleToDictionary(triangle.vertexIndexA, triangle); AddTriangleToDictionary(triangle.vertexIndexB, triangle); AddTriangleToDictionary(triangle.vertexIndexC, triangle); }
public SecondaryNode AddSecondaryNode() { List <int> validDistances = new List <int>(); if (Vector2.Distance(node1.mapPosition, node2.mapPosition) <= 50.0f) { return(null); } for (int i = 1; i < 10; i++) { bool tooClose = false; Vector2 lerp = Vector2.Lerp(node1.mapPosition, node2.mapPosition, i); foreach (SecondaryNode secNode in secondaryNodes) { if (Vector2.Distance(lerp, secNode.mapPosition) <= 25) { tooClose = true; } } if (tooClose == false) { validDistances.Add(i); } } if (validDistances.Count == 0) { return(null); } int distanceIndex = Rand.Range(0, validDistances.Count - 1, false); SecondaryNode newNode = new SecondaryNode(Vector2.Lerp(node1.mapPosition, node2.mapPosition, (float)validDistances[distanceIndex] / 10), this); secondaryNodes.Add(newNode); return(newNode); }
public MainNode(Vector3 position, bool isGround, float squareSize) : base(position) { ground = isGround; right = new SecondaryNode(position + Vector3.right * squareSize / 2f); up = new SecondaryNode(position + Vector3.up * squareSize / 2f); }