private Vector2 RowAndColumn() { Vector2 rowAndColumn = new Vector2(); int numberHorizontal = 0; int numberVertical = 0; GemBehaviour firstGem = currentMatchesList[0].GetComponent <GemBehaviour>(); if (firstGem != null) { foreach (GameObject currentGem in currentMatchesList) { GemBehaviour gem = currentGem.GetComponent <GemBehaviour>(); if (gem.row == firstGem.row) { numberHorizontal++; } if (gem.column == firstGem.column) { numberVertical++; } } } rowAndColumn = new Vector2(numberHorizontal, numberVertical); return(rowAndColumn); }
private IEnumerator SwapTilesRoutine(GemBehaviour gemA, GemBehaviour gemB) { var indexA = gemA.Index.Clone(); var indexB = gemB.Index.Clone(); gemA.Move(indexB, SequenceParameters.GemMoveTime); gemB.Move(indexA, SequenceParameters.GemMoveTime); yield return(new WaitForSeconds(SequenceParameters.GemMoveTime)); var matches = GridManager.FindMatchesAt(indexA) .Union(GridManager.FindMatchesAt(indexB)); if (matches.Any()) { yield return(new WaitForSeconds(SequenceParameters.PlayerMatchCheckDelay)); ClearAndRefillBoard(matches); } else { gemA.Move(indexA, SequenceParameters.GemMoveTime); gemB.Move(indexB, SequenceParameters.GemMoveTime); } }
private bool FiveInColumnOrRow() { int numberHorizontal = 0; int numberVertical = 0; GemBehaviour firstGem = currentMatchesList[0].GetComponent <GemBehaviour>(); if (firstGem != null) { foreach (GameObject currentGem in currentMatchesList) { GemBehaviour gem = currentGem.GetComponent <GemBehaviour>(); if (gem.row == firstGem.row) { numberHorizontal++; } if (gem.column == firstGem.column) { numberVertical++; } } } return(numberVertical == 5 || numberHorizontal == 5); }
public void CheckToSetSpecialClearSquareGem() { if (currentGem != null) { if (currentGem.isMatched) { if (!currentGem.isSquareClearGem) { currentGem.isMatched = false; currentGem.CreateSpecialGem(SpecialGem.SQUARE_CLEAR); } } else { if (currentGem.nextGem != null) { GemBehaviour nextGemBehaviour = currentGem.nextGem.GetComponent <GemBehaviour>(); if (nextGemBehaviour.isMatched) { if (!nextGemBehaviour.isSquareClearGem) { nextGemBehaviour.isMatched = false; nextGemBehaviour.CreateSpecialGem(SpecialGem.SQUARE_CLEAR); } } } } } }
private void RefillBoard() { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (board[i, j] == null && !immovableboard[i, j]) { Vector3 temPos = new Vector3(i, j + offSet, 0); int currentGem = Random.Range(0, GemTypesToUse()); int maxIterations = 0; while (MatchesAt(i, j, gemTypes[currentGem]) && maxIterations < 100) { maxIterations++; currentGem = Random.Range(0, GemTypesToUse()); } maxIterations = 0; GameObject temp = Instantiate(gemTypes[currentGem], temPos, Quaternion.identity); board[i, j] = temp; temp.GetComponent <GemBehaviour>().row = j; temp.GetComponent <GemBehaviour>().column = i; } } } }
private GemBehaviour PlaceGem(GemBehaviour gem, GridIndex index) { gem.gameObject .ResetTransformation() .SetPosition(index.GridX, index.GridY); SetGemPosition(gem, index); return(gem); }
public void ReadBoard() { for (int i = 0; i < transform.childCount; i++) { GemBehaviour gem = transform.GetChild(i).GetComponent <GemBehaviour>(); Vector2 index = gem.GetTileIndex(); orbBoard[(int)index.x, (int)index.y] = gem; } }
//new match logic chheck: public void FindMatches() { if (xCoord > 0 && xCoord < papaSpawner.cols - 1) { //check left: //print(papaSpawner.name); //print(papaSpawner.gemsInMe[xCoord - 1, yCoord].GetComponent<GemBehaviour>().myColorName); GemBehaviour lDot1 = papaSpawner.gemsInMe[xCoord - 1, yCoord].GetComponent <GemBehaviour>(); GemBehaviour rDot1 = papaSpawner.gemsInMe[xCoord + 1, yCoord].GetComponent <GemBehaviour>(); //are the left and right the same color as me? if (lDot1.myColor == myColor && rDot1.myColor == myColor) { //lDot1.isMatched = true; //rDot1.isMatched = true; //isMatched = true; //lDot1.ChangeColor(); //rDot1.ChangeColor(); //ChangeColor(); papaSpawner.gemsToClear.Add(lDot1); papaSpawner.gemsToClear.Add(rDot1); papaSpawner.gemsToClear.Add(this); papaSpawner.MakingMatchOf(myColorName); //lDot1.DestroyMe(); //rDot1.DestroyMe(); //DestroyMe(); } } if (yCoord > 0 && yCoord < papaSpawner.rows - 1) { //check up: GemBehaviour uDot1 = papaSpawner.gemsInMe[xCoord, yCoord + 1].GetComponent <GemBehaviour>(); GemBehaviour dDot1 = papaSpawner.gemsInMe[xCoord, yCoord - 1].GetComponent <GemBehaviour>(); //are the up and down the same color as me? if (uDot1.myColor == myColor && dDot1.myColor == myColor) { //uDot1.DestroyMe(); //dDot1.DestroyMe(); //DestroyMe(); if (!papaSpawner.gemsToClear.Contains(uDot1)) { papaSpawner.gemsToClear.Add(uDot1); } if (!papaSpawner.gemsToClear.Contains(dDot1)) { papaSpawner.gemsToClear.Add(dDot1); } if (!papaSpawner.gemsToClear.Contains(this)) { papaSpawner.gemsToClear.Add(this); } papaSpawner.MakingMatchOf(myColorName); } } papaSpawner.DestroyGems(); }
public void TriggerSkyFall() { bool missingOrbs = false; for (int y = 0; y < boardVertical; y++) { for (int x = 0; x < boardHorizontal; x++) { if (orbBoard[x, y] != null) { int newY = y; while (newY > 0) { if (orbBoard[x, newY - 1] == null) { newY--; } else { break; } } if (newY != y) { orbBoard[x, newY] = orbBoard[x, y]; orbBoard[x, y] = null; orbBoard[x, newY].SetTilePosition(new Vector2(x, newY)); orbBoard[x, newY].ApplyPositionOnBoard(); } } } } for (int y = 0; y < boardVertical; y++) { for (int x = 0; x < boardHorizontal; x++) { if (orbBoard[x, y] == null) { missingOrbs = true; Vector2 pos = new Vector2(-450 + x * orbSize, -390 + y * orbSize); GameObject orb = Instantiate(orbPrefabs[Random.Range(0, orbPrefabs.Length)], Vector3.zero, Quaternion.identity, transform); orb.GetComponent <RectTransform>().anchoredPosition = pos; GemBehaviour gem = orb.GetComponent <GemBehaviour>(); gem.SetTilePosition(new Vector2(x, y)); orbBoard[x, y] = gem; } } } if (missingOrbs) { FindMatches(0.6f); } }
private GemBehaviour MakeGemFall(GemBehaviour gem, int xIndex, int initY, int newY) { var index = new GridIndex(xIndex, newY); gem.Move(index, gemFallSpeed * (initY - newY)); SetGemPosition(gem, index); allGems[xIndex, initY] = null; return(gem); }
private void SetSpecialClearRowOrColumnGem(GemBehaviour gem) { gem.isMatched = false; if ((currentGem.changedAngle > -45.0f && currentGem.changedAngle <= 45.0f) || (currentGem.changedAngle <= -135.0f || currentGem.changedAngle > 135.0f)) { gem.CreateSpecialGem(SpecialGem.ROW_CLEAR); } else { gem.CreateSpecialGem(SpecialGem.COLUMN_CLEAR); } }
public void SetGemColor(GemBehaviour whichGem) { whichGem.SetColor(GameManager.GM.colorsToSpawn[reserveToSpawn]); if (reserveToSpawn < GameManager.GM.colorsToSpawn.Length - 1) { reserveToSpawn++; } else { reserveToSpawn = 0; } }
public IEnumerator SpawnGemInColumn(int whichColumn) { //float wait = 0; //if (stagger) //{ // wait = 1; //} yield return(new WaitForSeconds(spawnDel)); //GameObject t = Instantiate(gemToSpawn, columns[whichColumn], false); GameObject t = Instantiate(gemToSpawn, m_columnSpawnPos[whichColumn], Quaternion.identity, columns[whichColumn]); m_columnSpawnPos[whichColumn] += Vector3.up * spawnBuffer; GemBehaviour gb = t.GetComponent <GemBehaviour>(); gb.xCoord = whichColumn; //go through the gemsInMe 2DA and set the gem's ycoord in the first free spot from the bottom for (int i = 0; i < rows; i++) { //find the first open spot in the column. //maybe redundant? if (gemsInMe[whichColumn, i] == null) { // print("this was null: " + whichColumn + ", " + i); gemsInMe[whichColumn, i] = gb.transform; //gb.yCoord = i; } } //gb.yCoord = rows - 1; //gemsInMe[whichColumn, rows - 1] = t.transform; //this seems really sledgehammer-y but it's working and nothing else that i've tried has worked: foreach (Transform c in columns) { List <GemBehaviour> tempList = new List <GemBehaviour>(); tempList.AddRange(c.GetComponentsInChildren <GemBehaviour>()); tempList.Sort((x, y) => x.startTime.CompareTo(y.startTime)); for (int i = 0; i < tempList.Count; i++) { tempList[i].yCoord = i; gemsInMe[columns.IndexOf(c), i] = tempList[i].transform; } } gb.papaSpawner = this; SetGemColor(gb); refilling = true; //stagger = !stagger; }
public void GenerateBoard() { GenerateImmovableTile(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (!immovableboard[i, j]) { Vector3 tempPos = new Vector3(i, j + offSet, 0); GameObject testTile = Instantiate(tilePrefab, tempPos, Quaternion.identity) as GameObject; testTile.transform.parent = this.transform; testTile.name = "( " + i + "," + j + " )"; int currentGem = Random.Range(0, GemTypesToUse()); int maxLoopTime = 0; while (MatchesAt(i, j, gemTypes[currentGem]) && maxLoopTime < 100) { currentGem = Random.Range(0, GemTypesToUse()); maxLoopTime++; } maxLoopTime = 0; GameObject tempGem = Instantiate(gemTypes[currentGem], tempPos, Quaternion.identity); tempGem.GetComponent <GemBehaviour>().row = j; tempGem.GetComponent <GemBehaviour>().column = i; tempGem.transform.parent = this.transform; tempGem.name = "( " + i + "," + j + " )"; board[i, j] = tempGem; } else { Vector3 tempPos = new Vector3(i, j + offSet, 0); GameObject testTile = Instantiate(tilePrefab, tempPos, Quaternion.identity) as GameObject; testTile.transform.parent = this.transform; testTile.name = "( " + i + "," + j + " )"; SpriteRenderer sprRen = testTile.GetComponent <SpriteRenderer>(); sprRen.enabled = true; testTile.transform.position = new Vector3(i, j, 0); } } } }
int CheckDownwards(Vector2 index, OrbType orbType) { if (index.y >= 0 && index.y < boardVertical) { GemBehaviour thisOrb = orbBoard[(int)index.x, (int)index.y]; if (thisOrb.GetOrbType() == orbType) { if (thisOrb != null) { potentialOrbs.Add(thisOrb); } return(1 + CheckDownwards(index + Vector2.down, orbType)); } } return(0); }
int CheckRightwards(Vector2 index, OrbType orbType) { if (index.x >= 0 && index.x < boardHorizontal) { GemBehaviour thisOrb = orbBoard[(int)index.x, (int)index.y]; if (thisOrb.GetOrbType() == orbType) { if (thisOrb != null) { potentialOrbs.Add(thisOrb); } return(1 + CheckRightwards(index + Vector2.right, orbType)); } } return(0); }
private void OnTriggerEnter2D(Collider2D collision) { if (!orbPicked) { return; } //if (lastSwapped == collision.gameObject) return; GemBehaviour neighbour = collision.GetComponent <GemBehaviour>(); Vector2 newTilePos = neighbour.GetTileIndex(); neighbour.SetTilePosition(indexOnBoard); neighbour.ApplyPositionOnBoard(); indexOnBoard = newTilePos; }
public void GenerateBoard() { orbBoard = new GemBehaviour[boardHorizontal, boardVertical]; orbChecked = new bool[boardHorizontal, boardVertical]; for (int y = 0; y < boardVertical; y++) { for (int x = 0; x < boardHorizontal; x++) { Vector2 pos = new Vector2(-450 + x * orbSize, -390 + y * orbSize); GameObject orb = Instantiate(orbPrefabs[Random.Range(0, orbPrefabs.Length)], Vector3.zero, Quaternion.identity, transform); orb.GetComponent <RectTransform>().anchoredPosition = pos; GemBehaviour gem = orb.GetComponent <GemBehaviour>(); gem.SetTilePosition(new Vector2(x, y)); orbBoard[x, y] = gem; } } }
void Spawn() { Debug.Log("Spawning..."); // Find a random index between zero and one less than the number of spawn points. int spawnPointIndex = Random.Range(0, gems.Length); // Create an instance of the enemy prefab at the randomly selected spawn point's position and rotation. if (!gems [spawnPointIndex].activeInHierarchy) { GemBehaviour sample = gems [spawnPointIndex].GetComponent("GemBehaviour") as GemBehaviour; sample.GemSpawned(); Debug.Log("Spawned."); } else { Debug.Log("Gem is already active!"); } }
public void CheckToSetSpecialClearRowOrColumnGem() { if (currentGem != null) { if (currentGem.isMatched) { SetSpecialClearRowOrColumnGem(currentGem); } else if (currentGem.nextGem != null) { GemBehaviour nextGem = currentGem.nextGem.GetComponent <GemBehaviour>(); if (nextGem.isMatched) { SetSpecialClearRowOrColumnGem(nextGem); } } } }
private List <GameObject> CheckMatchedGemsInColumn(GemBehaviour gem1, GemBehaviour gem2, GemBehaviour gem3) { List <GameObject> currentGems = new List <GameObject>(); if (gem1.isColumnClearGem) { currentMatchesList.Union(MatchedGemsInColumn(gem1.column)); } if (gem2.isColumnClearGem) { currentMatchesList.Union(MatchedGemsInColumn(gem2.column)); } if (gem3.isColumnClearGem) { currentMatchesList.Union(MatchedGemsInColumn(gem3.column)); } return(currentGems); }
private void ProcessNearbyGems(GameObject gem1, GameObject gem2, GameObject gem3) { if (gem1 != null && gem3 != null) { GemBehaviour gem1Behaviour = gem1.GetComponent <GemBehaviour>(); GemBehaviour gem2GemBehaviour = gem2.GetComponent <GemBehaviour>(); GemBehaviour gem3GemBehaviour = gem3.GetComponent <GemBehaviour>(); if (gem1.tag == gem2.tag && gem3.tag == gem2.tag) { currentMatchesList.Union(CheckMatchedGemsInRow(gem1Behaviour, gem2GemBehaviour, gem3GemBehaviour)); currentMatchesList.Union(CheckMatchedGemsInColumn(gem1Behaviour, gem2GemBehaviour, gem3GemBehaviour)); currentMatchesList.Union(CheckMatchedGemsInSquare(gem1Behaviour, gem2GemBehaviour, gem3GemBehaviour)); AddAndMatchNearbyGemsToList(gem1, gem2, gem3); } } }
private List <GameObject> CheckMatchedGemsInRow(GemBehaviour gem1, GemBehaviour gem2, GemBehaviour gem3) { List <GameObject> currentGems = new List <GameObject>(); if (gem1.isRowClearGem) { currentMatchesList.Union(MatchedGemsInRow(gem1.row)); } if (gem2.isRowClearGem) { currentMatchesList.Union(MatchedGemsInRow(gem2.row)); } if (gem3.isRowClearGem) { currentMatchesList.Union(MatchedGemsInRow(gem3.row)); } return(currentGems); }
public IEnumerator PopulateBoardInital() { refilling = true; for (int i = 0; i < cols; i++) { for (int j = 0; j < rows; j++) { GameObject t = Instantiate(gemToSpawn, columns[i], false); GemBehaviour gb = t.GetComponent <GemBehaviour>(); gemsInMe[i, j] = t.transform; gb.xCoord = i; gb.yCoord = j; gb.papaSpawner = this; SetGemColor(gb); yield return(new WaitForSeconds(spawnDel)); } } //refilling = false; }
private IEnumerator FillAndCheckBoard() { RefillBoard(); yield return(new WaitForSeconds(refillDelay)); while (MatchesOnBoard()) { streak++; DestroyAllMatchesGem(); yield return(new WaitForSeconds(2 * refillDelay)); } currentMatchesList.Clear(); currentGem = null; yield return(new WaitForSeconds(refillDelay)); currentState = GameState.MOVE; }
List <GameObject> MatchedGemsInRow(int row) { List <GameObject> gems = new List <GameObject>(); for (int i = 0; i < width; i++) { if (board[i, row] != null) { GemBehaviour gemBehaviour = board[i, row].GetComponent <GemBehaviour>(); if (gemBehaviour.isColumnClearGem) { gems.Union(MatchedGemsInColumn(i)).ToList(); } gems.Add(board[i, row]); gemBehaviour.isMatched = true; } } return(gems); }
List <GameObject> MatchedGemsInColumn(int column) { List <GameObject> gems = new List <GameObject>(); for (int i = 0; i < height; i++) { if (board[column, i] != null) { GemBehaviour gemBehaviour = board[column, i].GetComponent <GemBehaviour>(); if (gemBehaviour.isRowClearGem) { gems.Union(MatchedGemsInRow(i)).ToList(); } gems.Add(board[column, i]); gemBehaviour.isMatched = true; } } return(gems); }
public void CheckForMatch() { GemBehaviour uGem = null; GemBehaviour dGem = null; GemBehaviour lGem = null; GemBehaviour rGem = null; //find all your surrounding gems: if (yCoord < papaSpawner.rows - 1) { //print("my y = " + yCoord); uGem = papaSpawner.gemsInMe[xCoord, yCoord + 1].GetComponent <GemBehaviour>(); } if (yCoord > 0) { dGem = papaSpawner.gemsInMe[xCoord, yCoord - 1].GetComponent <GemBehaviour>(); } if (xCoord > 0) { lGem = papaSpawner.gemsInMe[xCoord - 1, yCoord].GetComponent <GemBehaviour>(); } if (xCoord < papaSpawner.cols - 1) { rGem = papaSpawner.gemsInMe[xCoord + 1, yCoord].GetComponent <GemBehaviour>(); } //check left: //if (lGem) //{ // if (lGem.myColor == myColor) // { // lGem.markForRemoval = true; // markForRemoval = true; // } //} //check right: //if (rGem) //{ // if (rGem.myColor == myColor) // { // //rGem.markForRemoval = true; // markForRemoval = true; // if (!papaSpawner.gemsToClear.Contains(rGem.transform)) // { // papaSpawner.gemsToClear.Add(rGem.transform); // } // //print("Adding " + GameManager.GM.possibleColors[rGem.myColor].name + " " + rGem.xCoord + "," + rGem.yCoord); // if (!papaSpawner.gemsToClear.Contains(transform)) // { // papaSpawner.gemsToClear.Add(transform); // //print("Adding " + GameManager.GM.possibleColors[myColor].name+ " " + xCoord + "," + yCoord); // } // rGem.CheckForMatch(); // } // else // { // //copy the list over to a new one // if (papaSpawner.gemsToClear.Count >= 3) // { // papaSpawner.CopyList(); // } // return; // } //} //potentially wrong: //if (uGem) //{ // if (uGem.myColor == myColor) // { // uGem.markForRemoval = true; // markForRemoval = true; // if (!papaSpawner.gemsToClear.Contains(uGem.transform)) // { // papaSpawner.gemsToClear.Add(uGem.transform); // } // //print("Adding " + rGem.name + " " + rGem.xCoord + "," + rGem.yCoord); // if (!papaSpawner.gemsToClear.Contains(transform)) // { // papaSpawner.gemsToClear.Add(transform); // //print("Adding " + name + " " + xCoord + "," + yCoord); // } // uGem.CheckForMatch(); // } // else // { // return; // } //} //papaSpawner.DestroyGems(); }
public static void DestroyGem(GemBehaviour gem) { Destroy(gem.gameObject); }
private void SetGemPosition(GemBehaviour gem, GridIndex index) { allGems[index.GridX, index.GridY] = gem; gem.SetCord(index); }