public tilescript checkMatch() { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { tilescript tileScript = tiles[x, y].GetComponent <tilescript>(); if (tileScript != null) { // check horizontal match if (x < WIDTH - 2 && tileScript.isMatch(tiles[x + 1, y], tiles[x + 2, y])) { return(tileScript); } // check vertical match if (y < HEIGHT - 2 && tileScript.isMatch(tiles[x, y + 1], tiles[x, y + 2])) { return(tileScript); } } } } return(null); }
public bool isMatch(GameObject gameObject1, GameObject gameObject2) { // ~ i like... don't understand this whole part really tilescript ts1 = gameObject1.GetComponent <tilescript>(); tilescript ts2 = gameObject2.GetComponent <tilescript>(); return(ts1 != null && ts2 != null && type == ts1.type && type == ts2.type); }
public void removeMatches() { // delete tiles for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { tilescript tileScript = tiles[x, y].GetComponent <tilescript>(); if (tileScript != null) { // check horizontal match if (x < WIDTH - 2 && tileScript.isMatch(tiles[x + 1, y], tiles[x + 2, y])) { // emit particles + increase score Instantiate(particles, tiles[x, y].transform.position, Quaternion.identity); Instantiate(particles, tiles[x + 1, y].transform.position, Quaternion.identity); Instantiate(particles, tiles[x + 2, y].transform.position, Quaternion.identity); Destroy(tiles[x, y]); Destroy(tiles[x + 1, y]); Destroy(tiles[x + 2, y]); var source = GameObject.Find("GameManager").GetComponent <AudioSource>(); source.PlayOneShot(matchSound, .4f); if (playerScript.gameStart) { score += 3; } } // check vertical match if (y < HEIGHT - 2 && tileScript.isMatch(tiles[x, y + 1], tiles[x, y + 2])) { // emit particles + increase score Instantiate(particles, tiles[x, y].transform.position, Quaternion.identity); Instantiate(particles, tiles[x, y + 1].transform.position, Quaternion.identity); Instantiate(particles, tiles[x, y + 2].transform.position, Quaternion.identity); Destroy(tiles[x, y]); Destroy(tiles[x, y + 1]); Destroy(tiles[x, y + 2]); var source = GameObject.Find("GameManager").GetComponent <AudioSource>(); source.PlayOneShot(matchSound, .4f); if (playerScript.gameStart) { score += 3; } } } } } }
public bool Repopulate() { bool repop = false; for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { if (tiles[x, y] == null) { repop = true; // if empty space is in top row if (y == 0) { tiles[x, y] = Instantiate(tilePrefab); tilescript tileScript = tiles[x, y].GetComponent <tilescript>(); tileScript.SetSprite(Random.Range(0, tileScript.tileColors.Length)); tiles[x, y].transform.parent = gridHolder.transform; tiles[x, y].transform.localPosition = new Vector2(WIDTH - x - xOffset, HEIGHT - y - yOffset); } else { slideLerp = 0; tiles[x, y] = tiles[x, y - 1]; tilescript tileScript = tiles[x, y].GetComponent <tilescript>(); if (tileScript != null) { tileScript.SetupSlide(new Vector2(WIDTH - x - xOffset, HEIGHT - y - yOffset)); } playerscript playerScript = tiles[x, y].GetComponent <playerscript>(); if (playerScript != null) { playerScript.playerPos.Set(x, y); } tiles[x, y - 1] = null; } } } } repopulate = repop; return(repop); }
public void createGrid() { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { // make the boy GameObject newTile = Instantiate(tilePrefab); // get the spot for the boy newTile.transform.parent = gridHolder.transform; newTile.transform.localPosition = new Vector2(WIDTH - x - xOffset, HEIGHT - y - yOffset); // place the boy in the spot tiles[x, y] = newTile; // sprite stuff tilescript tileScript = newTile.GetComponent <tilescript>(); tileScript.SetSprite(Random.Range(0, tileScript.tileColors.Length)); } } }