public void RemoveMatches() { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { TileScript temp = tiles[x, y].GetComponent <TileScript>(); if (temp is object) { if (x < WIDTH - 2 && temp.IsMatch(tiles[x + 1, y], tiles[x + 2, y])) { //emit particles // emitParams.position = tiles[x,y].transform.position; // explosion.Emit(emitParams, 10); // emitParams.position = tiles[x + 1, y].transform.position; // explosion.Emit(emitParams, 10); // emitParams.position = tiles[x + 2, y].transform.position; // explosion.Emit(emitParams, 10); explosion1.transform.position = tiles[x, y].transform.position; explosion1.Play(); explosion2.transform.position = tiles[x + 1, y].transform.position; explosion2.Play(); explosion3.transform.position = tiles[x + 2, y].transform.position; explosion3.Play(); score += 3; //Debug.Log("Horizontal Match " + x + " " + y); Destroy(tiles[x, y]); Destroy(tiles[x + 1, y]); Destroy(tiles[x + 2, y]); scoreText.text = "SCORE: " + score; playerScript.resetTurns(6); } if (y < HEIGHT - 2 && temp.IsMatch(tiles[x, y + 1], tiles[x, y + 2])) { // emitParams.position = tiles[x,y].transform.position; // explosion.Emit(emitParams, 1); // emitParams.position = tiles[x, y + 1].transform.position; // explosion.Emit(emitParams, 1); // emitParams.position = tiles[x, y + 2].transform.position; // explosion.Emit(emitParams, 1); explosion1.transform.position = tiles[x, y].transform.position; explosion1.Play(); explosion2.transform.position = tiles[x, y + 1].transform.position; explosion2.Play(); explosion3.transform.position = tiles[x, y + 2].transform.position; explosion3.Play(); score += 3; //Debug.Log("Vertical Match " + x + " " + y); Destroy(tiles[x, y]); Destroy(tiles[x, y + 1]); Destroy(tiles[x, y + 2]); scoreText.text = "SCORE: " + score; playerScript.resetTurns(6); } } } } }
public void RemoveMatches() { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { TileScript temp = tiles[x, y].GetComponent <TileScript>(); if (temp is object) { if (x < WIDTH - 2 && temp.IsMatch(tiles[x + 1, y], tiles[x + 2, y])) { explosion1.transform.position = tiles[x, y].transform.position; explosion1.Play(); explosion2.transform.position = tiles[x + 1, y].transform.position; explosion2.Play(); explosion3.transform.position = tiles[x + 2, y].transform.position; explosion3.Play(); score += 1; //Debug.Log("Horizontal Match " + x + " " + y); Destroy(tiles[x, y]); Destroy(tiles[x + 1, y]); Destroy(tiles[x + 2, y]); scoreText.text = "SCORE: " + score; transform.GetChild(0).SendMessage("BeginContact"); //playerScript.resetTurns(6); } if (y < HEIGHT - 2 && temp.IsMatch(tiles[x, y + 1], tiles[x, y + 2])) { explosion1.transform.position = tiles[x, y].transform.position; explosion1.Play(); explosion2.transform.position = tiles[x, y + 1].transform.position; explosion2.Play(); explosion3.transform.position = tiles[x, y + 2].transform.position; explosion3.Play(); score += 1; //Debug.Log("Vertical Match " + x + " " + y); Destroy(tiles[x, y]); Destroy(tiles[x, y + 1]); Destroy(tiles[x, y + 2]); scoreText.text = "SCORE: " + score; transform.GetChild(0).SendMessage("BeginContact"); //playerScript.resetTurns(6); } } } } }
//Hasmatch returns an object that has a matching object vertically or horizontally public TileScript HasMatch() { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { TileScript temp = tiles[x, y].GetComponent <TileScript>(); if (temp is object) { if (x < WIDTH - 2 && temp.IsMatch(tiles[x + 1, y], tiles[x + 2, y])) { return(temp); } if (y < HEIGHT - 2 && temp.IsMatch(tiles[x, y + 1], tiles[x, y + 2])) { return(temp); } } } } return(null); }
public void RemoveMatches() { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { TileScript temp = tiles[x, y].GetComponent <TileScript>(); if (temp is object) { if (x < WIDTH - 2 && temp.IsMatch(tiles[x + 1, y], tiles[x + 2, y])) { BackgroundAudio.Instance.PlaySound("pop"); ParticleSystem e0 = Instantiate(explosion, tiles[x, y].transform.position, Quaternion.identity).GetComponent <ParticleSystem>(); ParticleSystem e1 = Instantiate(explosion, tiles[x + 1, y].transform.position, Quaternion.identity).GetComponent <ParticleSystem>(); ParticleSystem e2 = Instantiate(explosion, tiles[x + 2, y].transform.position, Quaternion.identity).GetComponent <ParticleSystem>(); e0.Play(); e1.Play(); e2.Play(); score += 1; //Debug.Log("Horizontal Match " + x + " " + y); Destroy(tiles[x, y]); Destroy(tiles[x + 1, y]); Destroy(tiles[x + 2, y]); Destroy(e0.gameObject, 3f); Destroy(e1.gameObject, 3f); Destroy(e2.gameObject, 3f); scoreText.text = "SCORE: " + score; GrowPlants(temp.type); GrowOuterPlant(); //transform.GetChild(0).SendMessage("BeginContact"); //playerScript.resetTurns(6); // This is an extremely hacky implementation of transitioning between screens if (score == 20 && !changedState) { TransitionToNextState(); } } if (y < HEIGHT - 2 && temp.IsMatch(tiles[x, y + 1], tiles[x, y + 2])) { BackgroundAudio.Instance.PlaySound("pop"); ParticleSystem e0 = Instantiate(explosion, tiles[x, y].transform.position, Quaternion.identity).GetComponent <ParticleSystem>(); ParticleSystem e1 = Instantiate(explosion, tiles[x, y + 1].transform.position, Quaternion.identity).GetComponent <ParticleSystem>(); ParticleSystem e2 = Instantiate(explosion, tiles[x, y + 2].transform.position, Quaternion.identity).GetComponent <ParticleSystem>(); e0.Play(); e1.Play(); e2.Play(); score += 1; //Debug.Log("Vertical Match " + x + " " + y); Destroy(tiles[x, y]); Destroy(tiles[x, y + 1]); Destroy(tiles[x, y + 2]); Destroy(e0.gameObject, 3f); Destroy(e1.gameObject, 3f); Destroy(e2.gameObject, 3f); scoreText.text = "SCORE: " + score; GrowPlants(temp.type); GrowOuterPlant(); //transform.GetChild(0).SendMessage("BeginContact"); //playerScript.resetTurns(6); if (score == 20 && !changedState) { TransitionToNextState(); } } } } } }