private void OnOrbClick(GridOrb orb) { //find connected orbs List <GridOrb> orbs = new List <GridOrb>(); orbs = GetConnectedOrbs(orb, orbs); if (orbs.Count >= 3) { //Increase score Score = Score + 10 * orbs.Count; //Set dead orb locations for destroying random orbs //Vector2Int[] deadOrbLocations = new Vector2Int[NumOrbsToKill]; //for (int i = 0; i < NumOrbsToKill; i++) //{ // GridOrb orbToKill = orbs[Random.Range(0, orbs.Count)]; // deadOrbLocations[i] = new Vector2Int(orbToKill.Column, orbToKill.Row); //} //Destroy remaining connected orbs foreach (ManaOrb connectedOrb in orbs) { Destroy(connectedOrb.gameObject); } //Add dead orbs for random placements //foreach (Vector2Int location in deadOrbLocations) // CreateDeadOrb(location.x, location.y); //Kill the clicked orb CreateDeadOrb(orb.Column, orb.Row); //Fill gaps StartCoroutine(DropOrbs()); } }
private void PlaceOrb(int col, int row, GridOrb orb) { //Set orb transform RectTransform orbRect = orb.GetComponent <RectTransform>(); orbRect.sizeDelta = new Vector2(OrbSize, OrbSize); orbRect.localPosition = CoordinatesToLocal(col, row); }
private void MoveOrb(int oldCol, int oldRow, int newCol, int newRow) { //Orb found, drop it in here GridOrb orb = GridOrbs[oldCol, oldRow]; GridOrbs[newCol, newRow] = orb; orb.Column = newCol; orb.Row = newRow; PlaceOrb(newCol, newRow, orb); //Empty previous slot GridOrbs[oldCol, oldRow] = null; }
private List <GridOrb> GetConnectedOrbs(GridOrb orb, List <GridOrb> orbs) { orbs.Add(orb); //Check above if (orb.Row + 1 < height) { GridOrb upOrb = GridOrbs[orb.Column, orb.Row + 1]; if (upOrb != null && !orbs.Contains(upOrb) && upOrb.OrbTypeID == orb.OrbTypeID) { //If the orb matches and is not already in the list //Add it and all of it's connected orbs orbs = GetConnectedOrbs(upOrb, orbs); } } //Check Right if (orb.Column + 1 < width) { GridOrb rightOrb = GridOrbs[orb.Column + 1, orb.Row]; if (rightOrb != null && !orbs.Contains(rightOrb) && rightOrb.OrbTypeID == orb.OrbTypeID) { //If the orb matches and is not already in the list //Add it and all of it's connected orbs orbs = GetConnectedOrbs(rightOrb, orbs); } } //Check Below if (orb.Row > 0) { GridOrb downOrb = GridOrbs[orb.Column, orb.Row - 1]; if (downOrb != null && !orbs.Contains(downOrb) && downOrb.OrbTypeID == orb.OrbTypeID) { //If the orb matches and is not already in the list //Add it and all of it's connected orbs orbs = GetConnectedOrbs(downOrb, orbs); } } //Check Left if (orb.Column > 0) { GridOrb leftOrb = GridOrbs[orb.Column - 1, orb.Row]; if (leftOrb != null && !orbs.Contains(leftOrb) && leftOrb.OrbTypeID == orb.OrbTypeID) { //If the orb matches and is not already in the list //Add it and all of it's connected orbs orbs = GetConnectedOrbs(leftOrb, orbs); } } return(orbs); }