//everything involved in removing a vertex. //removes it, updates the ui, and checks for successful match public void RemovePlayerVertex(int removalIndex, TestPolygon p) { p.RemoveVertex(removalIndex); numToRemove -= 1; UpdateRemoveText(); //if we've removed the correct amount and it matches, speed up wall to finish shape if (numToRemove == 0) { bool success = false; Transform polygon = GameObject.Find("PlayerPolygon").transform; //reworked so that it accounts for all holes foreach (TestPolygon tp in polygon.GetComponentsInChildren <TestPolygon>()) { TestPolygon hole = tp.holeToMatch; bool individualsuccess = VerticesAreSame(hole, tp); //if we failed one check, it is a total fail, so break from loop if (!individualsuccess) { success = false; break; } success = true; } if (success) { GameObject.FindObjectOfType <Wall>().speedingup = true; } } }
public override bool VerticesAreSame(TestPolygon p1, TestPolygon p2) { bool result = true; //if vertices count is not the same, the vertices definitely can not be the same if (p1.verticesList.Count != p2.verticesList.Count) { return(false); } /*int i = 0; * foreach (Vector3 v1 in p1.verticesList) { * if (v1.x != p2.verticesList [i].x || v1.y != p2.verticesList [i].y) * return false; * i++; * }*/ //copy of p1 list List <Vector3> p1ListCopy = new List <Vector3>(); foreach (Vector3 vec in p1.verticesList) { p1ListCopy.Add(new Vector3(vec.x, vec.y, vec.z)); } //copy of p2 list List <Vector3> p2ListCopy = new List <Vector3>(); foreach (Vector3 vec in p2.verticesList) { p2ListCopy.Add(new Vector3(vec.x, vec.y, vec.z)); } //for each point in p1, find if there is a matching one in p2 //if so, remove both? from their respective lists. At least remove the one from the second list //if at the end of this, p2 is empty, then we have succeeded. both lists are "the same". int i = 0; foreach (Vector3 vec in p1ListCopy) { //if we got rid of everything in p2 already, but we are still looping (i.e. we had more elements in p1 than //in p2 if (p2ListCopy.Count == 0) { return(false); } if (p2ListCopy.Exists(v => v.x == vec.x && v.y == vec.y)) { Vector3 p2Vec = p2ListCopy.Find(v => v.x == vec.x && v.y == vec.y); p2ListCopy.Remove(p2Vec); } i++; } if (p2ListCopy.Count == 0) { return(true); } return(false); //if we made it through the loop without finding a mismatch, we good, success! //return true; }
void CheckSuccess() { TestPolygon hole = GameObject.Find("Wall").GetComponentInChildren <TestPolygon> (); bool success = VerticesAreSame(hole, currentPoly); animDone = false; if (success) { StartCoroutine(SuccessAnim()); } else { StartCoroutine(FailAnim()); } }
void UndoLastMove() { if (removedVertices.Count > 0) { PolygonVertexPair toReplace = removedVertices.Pop(); TestPolygon toAddTo = toReplace.poly; IndexedVertex vertToAdd = toReplace.vertex; Debug.Log("toaddto " + toAddTo); Debug.Log("vertoAdd " + vertToAdd); Debug.Log("vertices list? " + toAddTo.verticesList); toAddTo.verticesList.Insert(vertToAdd.index, vertToAdd.coords); toAddTo.ReDraw(); gm.numToRemove += 1; gm.UpdateRemoveText(); } }
void OnMouseDown() { if (mouseControlEnabled) { //if highlighter is highlighting something //remove the vertex its highlighting if (highlightedOne) { TestPolygon highlightedPoly = highlightGO.GetComponent <HighlightVertex>().GetPolygon(); if (highlightedPoly.verticesList.Count > 3) { int removeIndex = highlightGO.GetComponent <HighlightVertex>().removalIndex; IndexedVertex indVert = highlightedPoly.GetIndexedVertex(removeIndex); highlightedPoly.RemoveVertex(removeIndex); //add removal info to the stack removedVertices.Push(new PolygonVertexPair(highlightedPoly, indVert)); numRemoved += 1; gm.numToRemove -= 1; gm.UpdateRemoveText(); //if we've removed the correct amount and it matches, speed up wall to finish shape if (gm.numToRemove == 0) { bool success = false; //reworked so that it accounts for all holes foreach (TestPolygon tp in polygon.GetComponentsInChildren <TestPolygon>()) { TestPolygon hole = tp.holeToMatch; bool individualsuccess = gm.VerticesAreSame(hole, tp); if (!individualsuccess) { success = false; break; } success = true; } //all checked were success, so speed up wall if (success) { GameObject.FindObjectOfType <Wall>().speedingup = true; } } } } } }
// Use this for initialization void Start() { polygon = GameObject.Find("PlayerPolygon").transform; //mainCam = GameObject.Find ("Main Camera").GetComponent<Camera> (); polygonScript = polygon.GetComponent <TestPolygon>(); highlightGO = transform.Find("Highlighter").gameObject; highlightedOne = false; removedVertices = new Stack <PolygonVertexPair>(); gm = GameObject.FindObjectOfType <GameManager>(); numRemoved = 0; wall = GameObject.FindObjectOfType <Wall> (); width = (float)Screen.width / 2.0f; height = (float)Screen.height / 2.0f; touchposition = new Vector3(0f, 0f, 0f); }
public void CreateHoles() { //if there is at least one hole object //destroy all hole objects and clear the current holes list if (currentHoles.Count != 0) { foreach (TestPolygon hole in GameObject.Find("Wall").GetComponentsInChildren <TestPolygon>()) { Destroy(hole.gameObject); } currentHoles.Clear(); } //create any new holes to be associated with the new player polygons int i = 0; foreach (TestPolygon playerPoly in currentPolys) { TestPolygon newHolePolygon = GameObject.FindObjectOfType <Wall>().CreateHoleShape(playerPoly.verticesList, playerPoly.numToRemove); //different positioning for different number of shapes //special case for the third element in a 3 shape setup if (currentLevel.NumberOfShapes == 3) { if (i == 2) { newHolePolygon.transform.localPosition = new Vector3(0f, .5f, 0f); } else { newHolePolygon.transform.localPosition = new Vector3(-1.2f + i * 2.4f, -1.8f, 0f); } } else { newHolePolygon.transform.localPosition = new Vector3(-1.2f + i * 2.4f, 0f, 0f); } //newHolePolygon.transform.localPosition = new Vector3(-1f + i * 2f, 0f, 0f); currentHoles.Add(newHolePolygon); //make sure the player polygon has a reference to it's approaching "hole" playerPoly.holeToMatch = newHolePolygon; i += 1; } }
public void RemoveRandomVertex() { BonusSelect bonus = bonusSelector.GetComponent <BonusSelect>(); if (bonus.removeBonus > 0) { //get the polygons in a random order int[] randomInts = Shuffle(currentPolys.Count); foreach (int j in randomInts) { //get a random polygon from player polygons TestPolygon p = currentPolys[j]; //if it has more vertices than its corresponding hole, we shall remove one from it if (p.verticesList.Count > p.holeToMatch.verticesList.Count) { bool foundOne = false; int i = 0; Vector3 toCheck = new Vector3(0, 0, 0); while (!foundOne) { //get a random vertex from this player polygon i = Random.Range(0, p.verticesList.Count); toCheck = p.verticesList[i]; //if the target polygon doesn't have it, good to remove it from player polygon if (!(p.holeToMatch.verticesList.Exists(v => v.x == toCheck.x && v.y == toCheck.y))) { RemovePlayerVertex(i, p); foundOne = true; } //if target polygon DOES have that vertex, we don't care, try to find another one to remove } bonus.removeBonus -= 1; bonus.removeText.text = "" + bonus.removeBonus; //we removed one, break from our loop looking for a candidate polygon break; } } } }
void TryRemoveVertex(TestPolygon tp) { if (tp.verticesList.Count > 3) { Debug.Log("vertices at least 3"); int removeIndex = highlightGO.GetComponent <HighlightVertex>().removalIndex; IndexedVertex indVert = tp.GetIndexedVertex(removeIndex); tp.RemoveVertex(removeIndex); //add removal info to the stack removedVertices.Push(new PolygonVertexPair(tp, indVert)); numRemoved += 1; gm.numToRemove -= 1; gm.UpdateRemoveText(); //if we've removed all and it matches, speed up wall to finish shape if (gm.numToRemove == 0) { bool success = false; //reworked so that it accounts for all holes foreach (TestPolygon p in polygon.GetComponentsInChildren <TestPolygon>()) { TestPolygon hole = p.holeToMatch; bool individualsuccess = gm.VerticesAreSame(hole, p); if (!individualsuccess) { success = false; break; } success = true; } if (success) { GameObject.FindObjectOfType <Wall>().speedingup = true; } } } }
public void SetHighlightedVertex(TestPolygon whichPolygon, Vector3 v) { polygon = whichPolygon; removalIndex = whichPolygon.verticesList.FindIndex(vec => vec.x == v.x && vec.y == v.y && vec.z == v.z); }
public abstract bool VerticesAreSame(TestPolygon p1, TestPolygon p2);
public void CreateNewPlayerPolygons() { Transform polygonParent = GameObject.Find("PlayerPolygon").transform; //remove the current removal markers //this needs to account for markers on multiple polygon objects foreach (GameObject marker in GameObject.FindGameObjectsWithTag("marker")) { Destroy(marker); } //create as many new polygons as the current level dictates //first, clear the currentPoly's list and destroy the objects that exist for them already if (currentPolys.Count > 0) { foreach (TestPolygon playerPolygon in polygonParent.GetComponentsInChildren <TestPolygon>()) { Destroy(playerPolygon.gameObject); } currentPolys.Clear(); } for (int i = 0; i < currentLevel.NumberOfShapes; i++) { //create a polygon TestPolygon newPolygon = ((GameObject)Instantiate(polyPrefab, polygonParent)).GetComponent <TestPolygon>(); newPolygon.Setup(); //different positioning for different number of shapes //special case for the third element in a 3 shape setup if (currentLevel.NumberOfShapes == 3) { if (i == 2) { newPolygon.transform.localPosition = new Vector3(0f, .5f, 0f); } else { newPolygon.transform.localPosition = new Vector3(-1.2f + i * 2.4f, -1.8f, 0f); } } else { newPolygon.transform.localPosition = new Vector3(-1.2f + i * 2.4f, 0f, 0f); } //newVerts needs to be a new List of vertices, copied from the list in memory //polyRangeHigh should never exceed polygons.count List <Vector3> newVerts = new List <Vector3>(polygons[Random.Range(polyRangeLow, polyRangeHigh)]); newPolygon.verticesList = newVerts; //base the number to remove on the base maximum and also how many vertices exist in the new shape int maxCanRemove = newPolygon.verticesList.Count - 3; newPolygon.numToRemove = Mathf.Clamp(Random.Range(1, maxCanRemove + 1), 1, currentLevel.BaseRemoveNum); newPolygon.vertices2D = System.Array.ConvertAll <Vector3, Vector2>(newVerts.ToArray(), v => v); newPolygon.color = playerPolyColors[UnityEngine.Random.Range(0, playerPolyColors.Length)]; newPolygon.OutlineFadeInEffect(); currentPolys.Add(newPolygon); } // PROCEDURAL POLYGON GENERATION // // MAY WORK ON IN FUTURE VERSION // /*List<XYPair> confirmedVerts = new List<XYPair> (); * //generate 'numVerts' number of unique vertices for polygon * for (int i = 0; i < numVerts; i++) { * int xVal = -1, yVal = -1; * bool foundNew = false; * while(!foundNew){ * xVal = Random.Range (0, 3); * yVal = Random.Range (0, 3); * //only proceed to add if certain conditions are met in confirmed verts list * //can't be more than 1 of either x or y value * //also can't be a vert in list that has both x and y already * if (confirmedVerts.FindAll (p => p.x == xVal).Count < 2 && * confirmedVerts.FindAll (p => p.y == yVal).Count < 2 && * !confirmedVerts.Exists (p => p.x == xVal && p.y == yVal)) { * * confirmedVerts.Add (new XYPair (xVal, yVal)); * foundNew = true; * * } * } * * Vector3 newVert = new Vector3 (xVal, yVal, 0f); * newVerts.Add (newVert); * Debug.Log ("new Vert added: " + newVert); * }*/ //currentPoly.ReDraw (); pointerController.removedVertices.Clear(); }
// Use this for initialization void Start() { score = 0; failCounter = 0; chainAmt = 0; chainThreshold = 5; levelThreshold = 1; level = 0; currentLevel = levels[0]; polyRangeLow = 0; polyRangeHigh = 1; currHealth = 1f; newHealth = 1f; t = 0f; wallSpeed = .05f; audiosource = GameObject.Find("BGM").GetComponent <AudioSource> (); wallPlane = GameObject.Find("Wall").transform.Find("Plane"); animDone = false; smallBeat = false; skyboxOffset = 0f; //screen orientation stuff ScreenWatcher.AddOrientationChangeListener(OnOrientationChanged); //Screen.orientation = ScreenOrientation.LandscapeLeft; wall = GameObject.FindObjectOfType <Wall>(); currentPoly = GameObject.Find("PlayerPolygon").GetComponent <TestPolygon> (); cylinderOffsetProperty = "_DownTex"; cylinderOffsetProp2 = "_DownTex2"; twoOffsetProps = false; //PositionForLandscape (); if (Screen.orientation == ScreenOrientation.Landscape) { PositionForLandscape(); } else if (Screen.orientation == ScreenOrientation.Portrait) { PositionForPortrait(); } GameObject.Find("MainCanvas").GetComponent <CanvasScaler> ().referenceResolution = new Vector2(Screen.width, Screen.height); polygons = new List <List <Vector3> >(); Vector3[] shape1 = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1f, 1f, 0f), new Vector3(1f, 0f, 0f) }; polygons.Add(new List <Vector3>(shape1)); Vector3[] shape2 = new Vector3[] { new Vector3(0f, -1f, 0f), new Vector3(0f, 0f, 0f), new Vector3(2f, 1f, 0f), new Vector3(1f, -1f, 0f) }; polygons.Add(new List <Vector3>(shape2)); Vector3[] shape3 = new Vector3[] { new Vector3(-1f, -1f, 0f), new Vector3(0f, 0f, 0f), new Vector3(1f, 0f, 0f), new Vector3(0f, -1f, 0f) }; polygons.Add(new List <Vector3>(shape3)); Vector3[] shape4 = new Vector3[] { new Vector3(-1f, -1f, 0f), new Vector3(0f, 0f, 0f), new Vector3(1f, 0f, 0f), new Vector3(2f, -1f, 0f) }; //5 sided polygons.Add(new List <Vector3>(shape4)); Vector3[] shape5 = new Vector3[] { new Vector3(0f, -.5f, 0f), new Vector3(-.5f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1f, 0f, 0f), new Vector3(.5f, -.5f, 0f) }; polygons.Add(new List <Vector3>(shape5)); Vector3[] shape6 = new Vector3[] { new Vector3(0f, -.5f, 0f), new Vector3(-.5f, 0f, 0f), new Vector3(-.5f, .5f, 0f), new Vector3(0f, 1f, 0f), new Vector3(.5f, 0f, 0f) }; polygons.Add(new List <Vector3>(shape6)); Vector3[] shape7 = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(-.5f, .5f, 0f), new Vector3(.5f, 1f, 0f), new Vector3(1f, .5f, 0f), new Vector3(.5f, 0f, 0f) }; polygons.Add(new List <Vector3>(shape7)); Vector3[] shape8 = new Vector3[] { new Vector3(0f, -.5f, 0f), new Vector3(-.5f, 0f, 0f), new Vector3(0f, .5f, 0f), new Vector3(1f, 0f, 0f), new Vector3(0f, 0f, 0f) }; polygons.Add(new List <Vector3>(shape8)); //6 sided Vector3[] shape9 = new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(-.5f, 0f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1f, .5f, 0f), new Vector3(.5f, .5f, 0f), new Vector3(1f, -.5f, 0f) }; polygons.Add(new List <Vector3>(shape9)); Vector3[] shape10 = new Vector3[] { new Vector3(0f, -.5f, 0f), new Vector3(-.5f, .5f, 0f), new Vector3(0f, 1f, 0f), new Vector3(.5f, 1f, 0f), new Vector3(1f, .5f, 0f), new Vector3(.5f, -.5f, 0f) }; polygons.Add(new List <Vector3>(shape10)); Vector3[] shape11 = new Vector3[] { new Vector3(-.5f, -0f, 0f), new Vector3(0f, .5f, 0f), new Vector3(0f, 1f, 0f), new Vector3(.5f, 1f, 0f), new Vector3(.5f, 0f, 0f), new Vector3(1f, -.5f, 0f) }; polygons.Add(new List <Vector3>(shape11)); Vector3[] shape12 = new Vector3[] { new Vector3(-.5f, 0f, 0f), new Vector3(-.5f, .5f, 0f), new Vector3(0f, 1f, 0f), new Vector3(1f, 1f, 0f), new Vector3(1f, -.5f, 0f), new Vector3(.5f, -.5f, 0f) }; polygons.Add(new List <Vector3>(shape12)); currentPoly.Setup(); CreateNewPlayerPolygon(); CreateHole(); }
public PolygonVertexPair(TestPolygon p, IndexedVertex v) { poly = p; vertex = v; }