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 ())
    }
Esempio n. 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (startSwap)
        {
            if (jewel1 == null || jewel2 == null)
            {
                return;
            }
            jewel1.transform.Translate(new Vector3(-(jewel1.transform.position.x - jewelTwoOriginalPos.x) * translationMultiplier, -(jewel1.transform.position.y - jewelTwoOriginalPos.y) * translationMultiplier, 0));
            jewel2.transform.Translate(new Vector3(-(jewel2.transform.position.x - jewelOneOriginalPos.x) * translationMultiplier, -(jewel2.transform.position.y - jewelOneOriginalPos.y) * translationMultiplier, 0));
            if (Mathf.Abs(jewel1.transform.position.x - jewelTwoOriginalPos.x) < distanceToTarget && Mathf.Abs(jewel1.transform.position.y - jewelTwoOriginalPos.y) < distanceToTarget &&
                Mathf.Abs(jewel2.transform.position.x - jewelOneOriginalPos.x) < distanceToTarget && Mathf.Abs(jewel2.transform.position.y - jewelOneOriginalPos.y) < distanceToTarget)
            {
                jewel1.transform.position = jewelTwoOriginalPos;
                jewel2.transform.position = jewelOneOriginalPos;
                jewel1.layer = secondJewelLayer;
                jewel2.layer = firstJewelLayer;
                startSwap    = false;
                //				firstJewelBlockMovement.moving = false;
                //				secondJewelBlockMovement.moving = false;
                pauseTouchForSwap = false;
            }
            if (!startSwap)
            {
                jewel1.GetComponent <Rigidbody2D>().isKinematic = false;
                jewel2.GetComponent <Rigidbody2D>().isKinematic = false;
                instantiator.SetJewelGridGameObject(jewelOneMovement.GetRow(), jewelOneMovement.GetCol(), jewel1);
                instantiator.SetJewelGridGameObject(jewelTwoMovement.GetRow(), jewelTwoMovement.GetCol(), jewel2);
                jewelOneMovement = jewel1.GetComponent <RockLevelJewelMovement> ();
                jewelTwoMovement = jewel2.GetComponent <RockLevelJewelMovement> ();
                jewelOneMovement.SetMoving(false);
                jewelTwoMovement.SetMoving(false);
                if (jewelOneMovement.GetRow() < jewelTwoMovement.GetRow())
                {
                    if (!checkForMatches.CheckForSwapBack(jewel1, jewelOneMovement.GetRow(), jewelOneMovement.GetCol()) && !checkForMatches.CheckForSwapBack(jewel2, jewelTwoMovement.GetRow(), jewelTwoMovement.GetCol()))
                    {
                        if (!swapJewelsBack && restrictMovements)
                        {
                            Swap(jewel1, jewel2, true);
                        }
                        else
                        {
                            if (jewel1 != null)
                            {
                                PowerStarTracker.RemoveFromHashSet(jewel1);
                                jewel1 = null;
                                jewelOneMovement.SetSwappingJewel(false);
                            }
                            if (jewel2 != null)
                            {
                                PowerStarTracker.RemoveFromHashSet(jewel2);
                                jewel2 = null;
                                jewelTwoMovement.SetSwappingJewel(false);
                            }
                        }
                        return;
                    }
                    deleteJewels.SetSwapComplete(true);
                    if (!timeBombLevel && !jewelCollectorLevel)
                    {
                        bombHandler.DecreaseAllBombsInList();
                    }
                    else if (jewelCollectorLevel)
                    {
                        Debug.Log("Calling moveNumberHandler.SubtractOneFromMoveNumber ()");
                        moveNumberHandler.SubtractOneFromMoveNumber();
                    }
                    if (!firstSwapPerformed)
                    {
                        GameObject.Find("Game Manager").GetComponent <GameManagerScript> ().SetFirstMoveMade(true);
                        firstSwapPerformed = true;
                        //Debug.Log ("First Swap Performed");
                    }
                    if (jewel1 != null)
                    {
                        PowerStarTracker.RemoveFromHashSet(jewel1);
                        jewel1 = null;
                        jewelOneMovement.SetSwappingJewel(false);
                    }
                    if (jewel2 != null)
                    {
                        PowerStarTracker.RemoveFromHashSet(jewel2);
                        jewel2 = null;
                        jewelTwoMovement.SetSwappingJewel(false);
                    }
//					stoppedMoving.SetGridStaticToFalse ();
                }
                else
                {
                    if (!checkForMatches.CheckForSwapBack(jewel2, jewelTwoMovement.GetRow(), jewelTwoMovement.GetCol()) && !checkForMatches.CheckForSwapBack(jewel1, jewelOneMovement.GetRow(), jewelOneMovement.GetCol()))
                    {
                        if (!swapJewelsBack && restrictMovements)
                        {
                            Swap(jewel1, jewel2, true);
                        }
                        else
                        {
                            if (jewel1 != null)
                            {
                                PowerStarTracker.RemoveFromHashSet(jewel1);
                                jewel1 = null;
                                jewelOneMovement.SetSwappingJewel(false);
                            }
                            if (jewel2 != null)
                            {
                                PowerStarTracker.RemoveFromHashSet(jewel2);
                                jewel2 = null;
                                jewelTwoMovement.SetSwappingJewel(false);
                            }
                        }
                        checkForMatches.deleteList.Clear();
                        return;
                    }
                    deleteJewels.SetSwapComplete(true);
                    if (!timeBombLevel && !jewelCollectorLevel)
                    {
                        bombHandler.DecreaseAllBombsInList();
                    }
                    else if (jewelCollectorLevel)
                    {
                        moveNumberHandler.SubtractOneFromMoveNumber();
                    }
                    if (!firstSwapPerformed)
                    {
                        GameObject.Find("Game Manager").GetComponent <GameManagerScript> ().SetFirstMoveMade(true);
                        firstSwapPerformed = true;
                        //Debug.Log ("First Swap Performed");
                    }
                    if (jewel1 != null)
                    {
                        PowerStarTracker.RemoveFromHashSet(jewel1);
                        jewel1 = null;
                        jewelOneMovement.SetSwappingJewel(false);
                    }
                    if (jewel2 != null)
                    {
                        PowerStarTracker.RemoveFromHashSet(jewel2);
                        jewel2 = null;
                        jewelTwoMovement.SetSwappingJewel(false);
                    }
//					stoppedMoving.SetGridStaticToFalse ();
                }
            }
        }
    }
    void CheckEveryJewelForMatch()
    {
        //Debug.Log ("gridStatic = true");
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                if (gameStarted)
                {
                    GameObject tempObject = instantiator.GetJewelGridGameObject(i, j);
                    if (checkForMatches.CheckForSwapBack(tempObject, i, j))
                    {
                        gridStatic = false;
                        deleteJewels.PunchNewTimeStamp();
//						CheckGridForMovement ();
                        return;
                    }
//					tempObject.GetComponent<Rigidbody2D> ().isKinematic = false;
                    tempObject.GetComponent <RockLevelJewelMovement> ().SetMoving(false);
                    tempObject.GetComponent <RockLevelJewelMovement> ().SetNotToBeDestroyed();
                }
            }
        }

        bombHandler.ZeroBombsStillExist();

        if (!bombHandler.BombIsExploded() && !touchHandler.GetGameStarted())
        {
            touchHandler.SetGameStarted(true);
        }

//		if (tutorialLevel && GameObject.Find ("No Extras Shade").GetComponent<LevelOneShadeController> ().GetOwlieNumber () == 1 && bombHandler.GetBombCount () > 0) {
//			GameObject.Find ("No Extras Shade").GetComponent<LevelOneShadeController> ().DarkenShade ();
//		}
        if (GameObject.Find("Jewel Collection Level ID") == null && !startLaunchingStars && bombHandler.GetBombListCount() == 0)
        {
            startLaunchingStars = true;
            touchHandler.SetGameStarted(false);
            starShooter.SetStartLaunchingStars(true);
        }
        else if (GameObject.Find("Jewel Collection Level ID") != null && collectingDone && !GameObject.Find("Jewel Collector").GetComponent <EndOfLevelCollectionJewelShooter> ().GetStartSpray())
        {
            GameObject.Find("Jewel Collector").GetComponent <EndOfLevelCollectionJewelShooter> ().StartJewelSpray();
        }         /*else if (GameObject.Find ("Jewel Collection Level ID") != null && collectingDone && GameObject.Find ("Jewel Collector").GetComponent<EndOfLevelCollectionJewelShooter> ().GetStartSpray () &&
                   *       GameObject.Find ("Jewel Collector").GetComponent<JewelCollectorController> ().GetTotalJewelCollectionGoalNumber () <= 0) {
                   * //			GameObject instantiatedShade = (GameObject)Instantiate (levelCompleteShade);
                   * //			instantiatedShade.GetComponent<DarkenOnInstantiaton> ().SetLevelComplete(true);
                   *    GameObject.Find ("Jewel Collector").GetComponent<MoveNumberHandler> ().StartLaunchingRowDestructionStars ();
                   * }
                   */
        else if (GameObject.Find("Jewel Collection Level ID") != null && !collectingDone && GameObject.Find("Jewel Collector").GetComponent <MoveNumberHandler> ().GetMoveNumber() == 0)
        {
            GameObject instantiatedShade = (GameObject)Instantiate(levelCompleteShade);
            instantiatedShade.GetComponent <DarkenOnInstantiaton> ().SetLevelComplete(false);
        }

        if (GameObject.Find("Jewel Collector") != null && GameObject.Find("Jewel Collector").GetComponent <MoveNumberHandler> ().GetFinishedLaunching())
        {
            GameObject instantiatedShade = (GameObject)Instantiate(levelCompleteShade);
            instantiatedShade.GetComponent <DarkenOnInstantiaton> ().SetLevelComplete(true);
        }


        if (!launchBombs && bombHandler.TimeBombIsExploded())
        {
            launchBombs = true;
            touchHandler.SetGameStarted(false);
            bombHandler.LaunchArtillery();
        }

        if (gameStarted == false)
        {
            gameStarted = true;
        }
    }