public static MarchDirections EdgeToSolutionDir(LevelEdge edge) { //This code is contained in the GetSolutionsForEdge function but i needed it elsewhere too //f**k this is messy. MarchDirections mdir = MarchDirections.positiveSlope_left; if (edge == LevelEdge.top) { mdir = MarchDirections.positiveSlope_left; } else if (edge == LevelEdge.topRight) { mdir = MarchDirections.positiveSlope_left; } else if (edge == LevelEdge.topLeft) { mdir = MarchDirections.horizontal_right; } else if (edge == LevelEdge.bottom) { mdir = MarchDirections.negativeSlope_left; } else if (edge == LevelEdge.bottomRight) { mdir = MarchDirections.negativeSlope_left; } else if (edge == LevelEdge.bottomLeft) { mdir = MarchDirections.horizontal_right; } return(mdir); }
public static Vector2Int March(Vector2Int from, MarchDirections dir) { if (dir == MarchDirections.horizontal_right) { return(MarchHorizontal(from, 1)); } else if (dir == MarchDirections.horizontal_left) { return(MarchHorizontal(from, -1)); } else if (dir == MarchDirections.positiveSlope_right) { return(MarchPositiveSlope(from, 1)); } else if (dir == MarchDirections.positiveSlope_left) { return(MarchPositiveSlope(from, -1)); } else if (dir == MarchDirections.negativeSlope_left) { return(MarchNegativeSlope(from, -1)); } else if (dir == MarchDirections.negativeSlope_right) { return(MarchNegativeSlope(from, 1)); } else { Debug.Log("Nani!?"); return(Vector2Int.zero); } }
//this is just a copy of OppositeMarchDir but i think that will have to change? public static MarchDirections GetHintDrawDir(MarchDirections indir) { if (indir == MarchDirections.horizontal_left) { return(MarchDirections.horizontal_right); } else if (indir == MarchDirections.horizontal_right) { return(MarchDirections.horizontal_left); } else if (indir == MarchDirections.negativeSlope_left) { return(MarchDirections.negativeSlope_right); } else if (indir == MarchDirections.negativeSlope_right) { return(MarchDirections.negativeSlope_left); } else if (indir == MarchDirections.positiveSlope_left) { return(MarchDirections.positiveSlope_right); } else if (indir == MarchDirections.positiveSlope_right) { return(MarchDirections.positiveSlope_left); } else { return(MarchDirections.none); } }
public void Draw(HintItem[] hint, MarchDirections dir, Triangle initialEdge) { if (dir == MarchDirections.positiveSlope_left || dir == MarchDirections.negativeSlope_left) { //duplicate hint array for duplication HintItem[] hintForward = new HintItem[hint.Length]; hint.CopyTo(hintForward, 0); //reverse hint array. for (int i = 0; i < hint.Length; i++) { hint[i] = hintForward[hint.Length - 1 - i]; } } for (int i = 1; i <= hint.Length; i++) { //color from int to color? //Where do we store the palette? //Debug.Log("Drawing a single hint set"); DrawOneHint(i, hint[i - 1].q, hint[i - 1].color, Triangle.GetHintDrawDir(dir), initialEdge); } }
public void DrawOneHint(int numberFromAxis, int number, Color c, MarchDirections drawDir, Triangle initialEdge) { MeshRenderer filledMesh = GameObject.Instantiate(hintMeshMaker, Vector3.zero, Quaternion.identity, transform).GetComponent <MeshRenderer>(); Mesh mesh = new Mesh(); numberFromAxis--;// Vector2Int drawPosition = new Triangle(initialEdge.position.x, initialEdge.position.y, initialEdge.edgeLength).position; drawPosition = Triangle.March(drawPosition, drawDir); for (int i = 0; i < numberFromAxis; i++) { //Skip over x times, to get to the right triangle (rhombus) place to darw drawPosition = Triangle.March(drawPosition, drawDir); drawPosition = Triangle.March(drawPosition, drawDir); } Vector2Int drawPosition2 = Triangle.March(drawPosition, drawDir); //A rhombus is made of two triangles that share an edge. These are those two triangles. Triangle rh1 = new Triangle(drawPosition); Triangle rh2 = new Triangle(drawPosition2); //Get verts of our triangles. Vector2[] vertsrh1 = rh1.GetVertsInWorldSpace(); Vector2[] vertsrh2 = rh2.GetVertsInWorldSpace(); //Ah, a nice neat array of our verts. Vector2[] verts2 = new Vector2[vertsrh1.Length + vertsrh2.Length]; vertsrh1.CopyTo(verts2, 0); vertsrh2.CopyTo(verts2, vertsrh1.Length); //Great! Verts 2 is our nice neat array of two triangles now. ///It has duplicate vertices buuuuut is that actually a problem? Vector2[] verts2Local = new Vector2[verts2.Length]; //4 Vector3[] verts3 = new Vector3[verts2.Length]; //4 Vector3 offset = Vector3.Lerp(rh1.GetCentroidInWorldSpace(), rh2.GetCentroidInWorldSpace(), 0.5f); for (int i = 0; i < verts2.Length; i++) { verts2Local[i] = verts2[i] - (Vector2)offset; //same but Vector2 cus why bother casting a whole array later for the polygon collider2d. verts3[i] = (Vector3)verts2[i] - offset; //offset by vertex 0... } int[] tris = new int[] { 2, 1, 0, 5, 4, 3 };//simple enough. mesh.vertices = verts3; mesh.triangles = tris; // filledMesh.transform.position = transform.position + offset;//un-offset. By this offset so the position is the centroid, and by the parent, for moving the grid around. Now our triangles are positioned sensibly. //and we can do sorting/filtering by world positions or transforms, which is easier than just naked data because unity has a lot of features for it //already built it. I THINK. // filledMesh.GetComponent <MeshFilter>().mesh = mesh; filledMesh.material.color = c; filledMesh.enabled = true; //Set our text to be the right hint. filledMesh.GetComponentInChildren <TMPro.TextMeshPro>().text = number.ToString(); //Center the textMesh //offset set in the chid object of prefab. IDK, its fine. // filledMesh.transform.GetChild(0).transform.position = filledMesh.transform.position; }
public int[][] GetSolutionsForEdge(LevelEdge edge, Dictionary <Vector2Int, int> level) { MarchDirections mdir = MarchDirections.horizontal_right; List <Triangle> edgeTriangles = new List <Triangle>(); // if (edge == LevelEdge.top) { edgeTriangles = topEdgeTriangles; mdir = MarchDirections.positiveSlope_left; } else if (edge == LevelEdge.topRight) { edgeTriangles = topRightEdgeTriangles; mdir = MarchDirections.positiveSlope_left; } else if (edge == LevelEdge.topLeft) { edgeTriangles = topLeftEdgeTriangles; mdir = MarchDirections.horizontal_right; } else if (edge == LevelEdge.bottom) { edgeTriangles = bottomEdgeTriangles; mdir = MarchDirections.negativeSlope_left; } else if (edge == LevelEdge.bottomRight) { edgeTriangles = bottomRightEdgeTriangles; mdir = MarchDirections.negativeSlope_left; } else if (edge == LevelEdge.bottomLeft) { edgeTriangles = bottomLeftEdgeTriangles; mdir = MarchDirections.horizontal_right; } int[][] solutions = new int[edgeTriangles.Count][];//our array of arrays. // for(int i = edgeTriangles.Count-1;i>0;i--){ foreach (Triangle mt in edgeTriangles) { // Triangle mt = edgeTriangles[i];//-1-i Vector2Int m = mt.position; List <Vector2Int> trisInRow = new List <Vector2Int>(); List <int> solution = new List <int>(); solution.Add(level[m]); trisInRow.Add(m); bool marching = true; while (marching) { Vector2Int key = Triangle.March(m, mdir); if (level.ContainsKey(key)) { m = key;//key is in while, m is out of this scope. solution.Add(level[m]); trisInRow.Add(m); } else { marching = false; } } // solutions[i] = solution.ToArray(); edgeTriangleToRowOfTrianglesMap.Add(mt.position, trisInRow.ToArray());//used for hint comparisons. edgeTriangleToSolutionMap.Add(mt, solution.ToArray()); } // return(solutions); }