void OnCollisionEnter2D(Collision2D collision) { if (!bounced) { if (gameManager.GetSoundState() && JewelClackCounter.GetJewelClackNumber() % 40 == 0) { GetComponent <AudioSource> ().Play(); } GetComponent <Rigidbody2D>().AddForce(bounceForce); bounced = true; } else { if (gameManager.GetSoundState() && firstBounce) { firstBounce = false; if (JewelClackCounter.GetJewelClackNumber() % 20 == 0) { GetComponent <AudioSource> ().Play(); } } else if (gameManager.GetSoundState() && !firstBounce && !starShooter.GetStartLaunchingStars() && JewelClackCounter.GetJewelClackNumber() % 3 == 0) { GetComponent <AudioSource> ().Play(); } else if (gameManager.GetSoundState() && JewelClackCounter.GetJewelClackNumber() % 6 == 0) { GetComponent <AudioSource> ().Play(); } } if (bounceAgain) { GetComponent <Rigidbody2D>().AddForce(new Vector2(0, 120)); bounceNumber++; if (bounceNumber > 1) { bounceAgain = false; } } moving = false; checkForMatch.CheckForSwapBack(gameObject, row, col); // if (touchHandler.GetGameStarted ()) }
public void DeleteAllJewelsInList(HashSet <GameObject> deleteList, bool powerUpDelete) { removeList = new HashSet <GameObject> (); if (deleteList.Count >= 3) { soundHandler.PlayJewelBreak(); } assistanceTimeStamp = Time.time; timeStamp = Time.time; okayToMoveTimeStamp = Time.time; okayToMoveAgain = false; matchAssistant.SetResetRandoms(true); movementChecker.SetGridStaticToFalse(); GameObject tempJewel; if (deleteList.Count == 4) { soundHandler.PlayPowerUpSound(); fourInARowScript.ActivateFourInARowPower(deleteList); // scoreKeeper.IncreaseScoreByFourJewelBonus (); } foreach (GameObject a in deleteList) { if (a != null) { if (!powerUpDelete && a.tag != "Boulder") { jewelMovement = a.GetComponent <RockLevelJewelMovement> (); if (jewelMovement.GetRow() + 1 < 9) { CheckForBoulders(jewelMovement.GetRow() + 1, jewelMovement.GetCol()); } if (jewelMovement.GetRow() - 1 >= 0) { CheckForBoulders(jewelMovement.GetRow() - 1, jewelMovement.GetCol()); } if (jewelMovement.GetCol() + 1 < 9) { CheckForBoulders(jewelMovement.GetRow(), jewelMovement.GetCol() + 1); } if (jewelMovement.GetCol() - 1 >= 0) { CheckForBoulders(jewelMovement.GetRow(), jewelMovement.GetCol() - 1); } } if (a.tag == "Boulder") { jewelMovement = a.GetComponent <RockLevelJewelMovement> (); if (CheckForBoulders(jewelMovement.GetRow(), jewelMovement.GetCol())) { removeList.Add(a); } } } } foreach (GameObject a in removeList) { deleteList.Remove(a); } foreach (GameObject a in boulderDeleteList) { deleteList.Add(a); } foreach (GameObject a in deleteList) { if (a != null) { deleteListCopy = deleteList; if (a != null && a.tag == "Steel Block") { PowerStarTracker.RemoveFromHashSet(a); } if (a != null && a.tag != "Steel Block" && a.name != "Rock 3 Chain(Clone)" && a.name != "Rock 2 Chain(Clone)" && a.name != "Rock 1 Chain(Clone)") { jewelMovement = a.GetComponent <RockLevelJewelMovement> (); // moveJewelsDown.MoveJewelsAboveDown(a); // if (GameObject.Find ("Time Bomb ID") != null) { // if (addJewels == null) // addJewels = GameObject.Find ("Time Bomb ID").GetComponent<AddTimeLevelOneJewels> (); // if (Bomb(a) && !bombHandler.TimeBombIsExploded ()) { // bombHandler.RemoveFromBombList (a); // addJewels.InstantiateSingleJewels (jewelMovement.GetCol (), true); // } else if (!bombHandler.TimeBombIsExploded ()) // addJewels.InstantiateSingleJewels (jewelMovement.GetCol (), false); // else if (bombHandler.TimeBombIsExploded ()) { // addJewels.InstantiateOnlyJewels (jewelMovement.GetCol ()); // } // } // else // instantiator.InstantiateSingleJewels (jewelMovement.GetRow (), jewelMovement.GetCol ()); if (Bomb(a) && GameObject.Find("Time Bomb ID") == null) { GameObject tempNumber = null; for (int i = 0; i < a.transform.childCount; i++) { if (a.transform.GetChild(i).tag == "Bomb Number") { tempNumber = a.transform.GetChild(i).gameObject; break; } } if (tempNumber != null) { tempNumber.transform.parent = null; tempNumber.GetComponent <BombNumberHandler> ().SetBombDestroyed(true); } if (bombHandler.GetBombListCount() == 1) { //Debug.Log ("Setting touch to fault"); touchHandler.SetGameStarted(false); } // bombInfo = a.GetComponent<LevelTwoBombInfo> (); // Instantiate (bombInfo.GetBombNumberSprite (), a.transform.position, Quaternion.identity); } else if (Bomb(a) && GameObject.Find("Time Bomb ID") != null) { GameObject tempBomb; // bombInfo = a.GetComponent<LevelTwoBombInfo> (); a.GetComponent <Rigidbody2D>().isKinematic = true; // bombInfo.SetBombDestroyed (true); } } } } boulderDeleteList.Clear(); foreach (GameObject a in deleteList) { if (a != null) { if (explosionsOn) { InstantiateExplosions(a); } if (a.tag != "Steel Block") { scoreKeeper.IncreaseScoreByOneJewel(); if (bombHandler.BombListContains(a)) { jewelMovement = a.GetComponent <RockLevelJewelMovement> (); bombHandler.RemoveFromBombList(a); bombHandler.DecreaseBombCounterByOne(); // scoreKeeper.IncreaseScoreByOneBomb (); } if (/*(GameObject.Find ("Time Bomb ID") == null || (GameObject.Find ("Time Bomb ID") != null && !Bomb (a))) &&*/ a.name != "Rock 3 Chain(Clone)" && a.name != "Rock 2 Chain(Clone)" && a.name != "Rock 1 Chain(Clone)") { if (GameObject.Find("Time Bomb ID") != null && Bomb(a)) { bombDestroyed = true; } tempPositionHolder = new PositionHolder(a.GetComponent <RockLevelJewelMovement> ().GetRow(), a.GetComponent <RockLevelJewelMovement> ().GetCol()); deletedPositions.Add(tempPositionHolder); int row = a.GetComponent <RockLevelJewelMovement> ().GetRow(); int col = a.GetComponent <RockLevelJewelMovement> ().GetCol(); a.GetComponent <RockLevelJewelMovement> ().StartDestroyCountdown(); PowerStarTracker.RemoveFromHashSet(a); if (a.name == "Slug(Clone)") { SlugListManager.RemoveFromSlugList(a); } if (GameObject.Find("Jewel Collection Level ID") != null && !endOfLevelJewelSprayer.GetSprayingInProgress()) { InstantiateStaticJewel(a); } Destroy(a); instantiator.SetJewelGridGameObject(row, col, null); // moveJewelsDown.MoveJewelsAboveDown (tempPositionHolder.GetCol (), tempPositionHolder.GetRow ()); // instantiator.InstantiateSingleJewels (tempPositionHolder.GetRow (), tempPositionHolder.GetCol ()); } } } } // deleteCount++; // // if (deleteCount == 3) { // deleteCount = 0; // GameObject.Find ("Pump Up Word Holder").GetComponent<PumpUpWordHolder> ().InstantiateWow (); // } powerTrackerTimestamp = Time.time; swapMadeTimestamp = Time.time; // if (swapComplete) { // swapComplete = false; // SlugListManager.MoveAllSlugs (); // } deleteList.Clear(); foreach (PositionHolder a in deletedPositions) { // //Debug.Log ("deletePositions.Size = " + deletedPositions.Count); int row = a.GetRow(); int col = a.GetCol(); moveJewelsDown.MoveJewelsAboveDown(col, row); // instantiator.InstantiateSingleJewels (row, col); //// while (row >= 0 && instantiator.GetJewelGridGameObject (row, col) == null) //// row--; //// if (instantiator.GetJewelGridGameObject (row, col) != null) //// instantiator.GetJewelGridGameObject (row, col).GetComponent<RockLevelJewelMovement> ().MoveDown (false); } List <PositionHolder> nullPositions = null; if (!starShooter.GetStartLaunchingStars()) { nullPositions = new List <PositionHolder> (); int positionTotal = deletedPositions.Count, nullCount = 0; bool breakSecondLoop = false; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (instantiator.GetJewelGridGameObject(i, j) == null) { nullCount++; nullPositions.Add(new PositionHolder(i, j)); if (nullCount >= positionTotal) { breakSecondLoop = true; } } } if (breakSecondLoop) { break; } } } foreach (PositionHolder a in deletedPositions) { if (tutorialLevel1) { instantiator.InstantiateLevelOneTutorialJewels(a.GetRow(), a.GetCol()); } else if (tutorialLevel2) { instantiator.InstantiateLevelTwoTutorialJewels(a.GetRow(), a.GetCol()); } else if (tutorialLevel3) { instantiator.InstantiateLevelThreeTutorialJewels(a.GetRow(), a.GetCol()); } else if (tutorialLevel4) { instantiator.InstantiateLevelFourTutorialJewels(a.GetRow(), a.GetCol()); } else { instantiator.InstantiateSingleJewels(a.GetRow(), a.GetCol()); } } if (!starShooter.GetStartLaunchingStars()) { int whileCount = 0; if (!tutorialLevel1 && !tutorialLevel2 && !tutorialLevel3 && noMatchChecker.CheckForNoMatchesWithoutShuffle() && noMatchCount < 3) { Debug.Log("MAKING A NEW MATCH"); noMatchCount++; do { foreach (PositionHolder a in nullPositions) { Destroy(instantiator.GetJewelGridGameObject(a.GetRow(), a.GetCol())); instantiator.SetJewelGridGameObject(a.GetRow(), a.GetCol(), null); instantiator.InstantiateSingleJewels(a.GetRow(), a.GetCol()); } if (whileCount > 100) { Debug.Log("WHILECOUNT BREAK"); break; } whileCount++; } while (noMatchChecker.CheckForNoMatchesWithoutShuffle()); } else { noMatchCount = 0; } } deletedPositions.Clear(); // foreach (PositionHolder a in boulderHolder) { // if (instantiator.GetJewelGridGameObject (a.GetRow (), a.GetCol ()) != null) { // checkForMatches.CheckForSwapBack (instantiator.GetJewelGridGameObject (a.GetRow (), a.GetCol ()), a.GetRow (), a.GetCol ()); // } // } // boulderHolder.Clear (); // if (shadeCount == 0 || shadeCount == 1) { // shadeController = controller.GetCurrentTutorialShade ().GetComponent<LevelTwoTutorialShadeController> (); // shadeController.MakeInvisible (); // shadeCount++; // } // if (swapComplete) { // swapComplete = false; // SlugListManager.MoveAllSlugs (); // } }