Exemple #1
0
    //////////////////////////////////////////////////////////////////////////////////////////////////////////


    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.name == "player" && this.gameObject.activeSelf ||
            collision.gameObject.name == "player_idle" && this.gameObject.activeSelf
            )
        {
            Player tempPlayer = collision.GetComponent <Player>();
            FindObjectOfType <AudioManager>().Play("copy");

            //Here we call function
            foreach (var item in bubbleCopies)
            {
                PlayerCopy tempPlayerCopy = item.GetComponent <PlayerCopy>();
                tempPlayerCopy.gameObject.SetActive(true);
                tempPlayerCopy.transform.position   = tempPlayer.transform.position;
                tempPlayerCopy.playerCopyBubbleSize = tempPlayer.playerBubbleSize;
                tempPlayerCopy.ScaleControll(tempPlayerCopy.playerCopyBubbleSize);
                tempPlayerCopy.lifeTime = 10;
                tempPlayerCopy.timer    = 3;
                tempPlayerCopy.ApplySpeedRB(gameManagerRef.helperRef.TakeRandomPosition());
            }

            this.gameObject.SetActive(false);
            lifeTime = 0;
            gameObject.transform.position = lootContainer.transform.position;
            gameManagerRef.loot.Remove(this.gameObject);
            Destroy(this.gameObject);
        }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    void OnCollisionEnter2D(Collision2D collision)
    {
        //////// HERE IS COLLISION WITH PLAYER IF IT"S ACTIVE  /////////
        if (playerRef != null && this.gameObject.activeSelf == true)
        {
            if (collision.gameObject.name == "player" && gameManagerRef.gameIsStarts || collision.gameObject.name == "player_idle" && gameManagerRef.gameIsStarts)
            {
                int tempPlayerSize = playerRef.playerBubbleSize; // store temp Player's bubble size
                int tempThisSize   = bubbleSize;                 // store temp Enemy bubble size
                bubbleSize              -= tempPlayerSize;       // here calculating enemy's bubble size
                storeBubbleSize          = bubbleSize;
                storeBubbleSizeExplosion = bubbleSize;
                if (playerRef.frozenDurability > 0)
                {
                    bubbleSize -= bubbleSize; FindObjectOfType <AudioManager>().Play("impact_W_ICE");
                }                                                                                                                      //If Player has frozen bubble

                //if player has NO ANY shield
                if (playerRef.shieldDurability <= 0 && playerRef.frozenDurability <= 0)
                {
                    playerRef.playerBubbleSize -= tempThisSize;    // here calculating player's bubble argument after collision
                    if (playerRef.playerBubbleSize <= 0)
                    {
                        playerRef.GetScore(1, Color.red, " Bubble", " -", "playerGetsScore", playerRef.transform.position, false);
                    }
                    if (playerRef.playerBubbleSize > 0)
                    {
                        //Debug.Log("PLAYER SHOULD SEE MINUS");
                        playerRef.go_player_BubbleSize.SetActive(false);
                        playerRef.timeNotActive = 0;
                        playerRef.GetScore(tempThisSize, Color.red, " ", " -", "PlayerChangeArgument", playerRef.transform.position, true);
                        playerRef.ScaleControll(playerRef.playerBubbleSize); // set new scale for player
                        ScaleControll(playerRef.playerBubbleSize);           // Set new scale for player bubble
                    }
                }

                /// CHECKING THIS BUBBLE STATUS AFTER COLLISION WITH PLAYER
                if (bubbleSize <= 0)
                {
                    GetScore(tempThisSize, bubbleSizeOnText.color, " pts", " +", this.transform.position, false, "playerGetsScore", false);
                    playerRef.playerScore             += tempThisSize;
                    playerRef.playerKills             += 1;
                    gameManagerRef.progressBar.f_fill -= (float)tempThisSize / 1000;
                    GetBubbleEnd();
                    Invoke("DestroyBubble", 0.005f);
                }
                else
                {
                    FindObjectOfType <AudioManager>().Play("impact_DOWN");
                    //GetScore(tempPlayerSize, Color.red," ", " -", this.transform.position, true, "changeArgument", true);
                    GetScore(tempPlayerSize, Color.red, " ", " -", this.transform.position, true, "BubbleChangeArgument_" + NUMBER_in_the_list.ToString(), false);
                    gameManagerRef.progressBar.f_fill -= (float)tempPlayerSize / 1000;
                    this.bubbleScoreRenderer.enabled   = false;
                    this.timeNotActive = 0;

                    ScaleControll(bubbleSize);
                }

                if (playerRef.shieldDurability > 0)
                {
                    playerRef.shieldDurability -= 1; // decrease durability for player's shield ability
                    //playerRef.GetScore(1, Color.red, " Shield", " -", "playerGetsScore", playerRef.transform.position, false);
                }
                if (playerRef.frozenDurability > 0)
                {
                    playerRef.frozenDurability -= 1; // decrease durability for player's shield ability
                    //playerRef.GetScore(1, Color.red, " Freeze", " -", "playerGetsScore", playerRef.transform.position, false);
                }
            }
        }


        //Checking collison with others bubbles
        if ((collision.gameObject.name == "blue" || collision.gameObject.name == "green" || collision.gameObject.name == "pink" || collision.gameObject.name == "red" ||
             collision.gameObject.name == "purple" || collision.gameObject.name == "white" || collision.gameObject.name == "yellow") &&
            !gameManagerRef.playerTurn && gameManagerRef.gameIsStarts

            || (collision.gameObject.name == "blue" || collision.gameObject.name == "green" || collision.gameObject.name == "pink" || collision.gameObject.name == "red" ||
                collision.gameObject.name == "purple" || collision.gameObject.name == "white" || collision.gameObject.name == "yellow") &&
            playerRef.gameObject.activeSelf == false && playerRef != null && !gameManagerRef.playerTurn && gameManagerRef.gameIsStarts

            || (collision.gameObject.name == "blue_idle" || collision.gameObject.name == "green_idle" || collision.gameObject.name == "pink_idle" || collision.gameObject.name == "red_idle" ||
                collision.gameObject.name == "purple_idle" || collision.gameObject.name == "white_idle" || collision.gameObject.name == "yellow_idle") &&
            !gameManagerRef.playerTurn && gameManagerRef.gameIsStarts

            || (collision.gameObject.name == "blue_idle" || collision.gameObject.name == "green_idle" || collision.gameObject.name == "pink_idle" || collision.gameObject.name == "red_idle" ||
                collision.gameObject.name == "purple_idle" || collision.gameObject.name == "white_idle" || collision.gameObject.name == "yellow_idle") &&
            playerRef.gameObject.activeSelf == false && playerRef != null && !gameManagerRef.playerTurn && gameManagerRef.gameIsStarts
            )
        {
            Bubble collisionBubble = collision.gameObject.GetComponent <Bubble>();
            this.bubbleScoreRenderer.enabled = false;
            this.timeNotActive = 0;
            gameManagerRef.helperRef.ControllOverBubbleCollideEachOther(collisionBubble, this);
        }


        if (collision.gameObject.name == "PlayerCopy_Effect_0" || collision.gameObject.name == "PlayerCopy_Effect_1" || collision.gameObject.name == "PlayerCopy_Effect_2")
        {
            PlayerCopy tempPlayerCopy = collision.gameObject.GetComponent <PlayerCopy>();

            int tempCopyPlayerSize = tempPlayerCopy.playerCopyBubbleSize;   // store temp player's Copy bubble size
            int tempThisSize       = bubbleSize;                            // store temp Enemy bubble size
            bubbleSize -= tempCopyPlayerSize;                               // here calculating enemy's bubble size
            tempPlayerCopy.playerCopyBubbleSize -= Mathf.Abs(tempThisSize); // here calculating player's bubble argument after collision

            if (bubbleSize <= 0)
            {
                bubbleSize = 0;
                GetScore(tempThisSize, bubbleSizeOnText.color, " pts", " +", this.transform.position, false, "playerGetsScore", false);
                tempPlayerCopy.GetScore(Mathf.Abs(tempThisSize), Color.red, " ", " -", "BubbleChangeArgument_" + NUMBER_in_the_list.ToString(), tempPlayerCopy.transform.position, true);
                playerRef.playerScore             += tempThisSize;
                playerRef.playerKills             += 1;
                gameManagerRef.progressBar.f_fill -= (float)tempThisSize / 1000;
                GetBubbleEnd();
                Invoke("DestroyBubble", 0.005f);
            }
            else
            {
                FindObjectOfType <AudioManager>().Play("impact_DOWN");
                GetScore(Mathf.Abs(tempCopyPlayerSize), Color.red, " ", " -", this.transform.position, true, "BubbleChangeArgument_" + NUMBER_in_the_list.ToString(), false);
                gameManagerRef.progressBar.f_fill -= (float)tempCopyPlayerSize / 1000;
                this.bubbleScoreRenderer.enabled   = false;
                this.timeNotActive       = 0;
                storeBubbleSize          = bubbleSize;
                storeBubbleSizeExplosion = bubbleSize;
                ScaleControll(bubbleSize);
            }
            if (tempPlayerCopy.playerCopyBubbleSize > 0)
            {
                tempPlayerCopy.go_playerCopy_BubbleSize.SetActive(false);
                tempPlayerCopy.timeNotActive = 0;
                tempPlayerCopy.GetScore(Mathf.Abs(tempThisSize), Color.red, " ", " -", tempPlayerCopy.name + "_ChangeArgument", tempPlayerCopy.transform.position, true);
                tempPlayerCopy.ScaleControll(tempPlayerCopy.playerCopyBubbleSize); // set new scale for player
            }
        }


        //Checking collision with platfomrs
        if (collision.gameObject.transform.name == "EdgeSpriteCollider" && bubbleIsMoving && playerRef.gameObject.activeSelf == true && playerRef != null && gameManagerRef.gameIsStarts ||
            collision.gameObject.transform.name == "EdgeSpriteCollider" && bubbleIsMoving && playerRef.gameObject.activeSelf == false && playerRef != null && gameManagerRef.gameIsStarts)
        {
            EdgeBoard temp           = collision.gameObject.transform.parent.GetComponent <EdgeBoard>();
            int       tempBubbleSize = bubbleSize; // here we store bubble size by using new variable
            storeBubbleSize          = bubbleSize;
            storeBubbleSizeExplosion = bubbleSize;
            if (temp.negativePositiveChance < 2 && !temp.panelIsPortal && !temp.panelIsZero)
            {
                FindObjectOfType <AudioManager>().Play("impact_UP");
                gameManagerRef.progressBar.f_fill += (float)temp.edgeArgument / 1000;
                //Here we need calculate number argument, make it bugger
                tempEdgeArgument                 = temp.edgeArgument;
                bubbleSize                      += tempEdgeArgument;
                storeBubbleSize                  = bubbleSize;
                storeBubbleSizeExplosion         = bubbleSize;
                this.bubbleScoreRenderer.enabled = false;
                this.timeNotActive               = 0;
                GetScore(tempEdgeArgument, Color.green, " ", " +", collision.transform.position, true, "BubbleChangeArgument_" + NUMBER_in_the_list.ToString(), false);
                ScaleControll(bubbleSize); // Set new scale for this bubble
                //Debug.Log("COLLISION WITH POSITIVE EDGE " + tempEdgeArgument);
                GetImpactEffect(true, this.transform.position, temp.gameObject.name);
            }
            if (temp.negativePositiveChance >= 2 && !temp.panelIsPortal && !temp.panelIsZero)
            {
                //Here we need calculate number, make it smaller

                tempEdgeArgument = temp.edgeArgument;
                bubbleSize      -= tempEdgeArgument;


                if (bubbleSize <= 0)
                {
                    bubbleSize = 0;
                    GetScore(storeBubbleSize, bubbleSizeOnText.color, " pts", " +", this.transform.position, false, "playerGetsScore", false);
                    playerRef.playerScore             += storeBubbleSize;
                    playerRef.playerKills             += 1;
                    gameManagerRef.progressBar.f_fill -= (float)storeBubbleSize / 1000;
                    GetBubbleEnd();
                    Invoke("DestroyBubble", 0.005f);
                }
                else
                {
                    FindObjectOfType <AudioManager>().Play("impact_DOWN");
                    GetScore(tempEdgeArgument, Color.red, " ", " -", collision.transform.position, true, "BubbleChangeArgument_" + NUMBER_in_the_list.ToString(), false);
                    this.bubbleScoreRenderer.enabled = false;
                    this.timeNotActive                 = 0;
                    storeBubbleSize                    = bubbleSize;
                    storeBubbleSizeExplosion           = bubbleSize;
                    gameManagerRef.progressBar.f_fill -= (float)tempEdgeArgument / 1000;
                    ScaleControll(bubbleSize); // Set new scale for this bubble
                }
                GetImpactEffect(false, this.transform.position, temp.gameObject.name);
            }
            if (temp.panelIsPortal && rb_bubble.velocity.magnitude > 0.25f)
            {
                FindObjectOfType <AudioManager>().Play("portal");
                BubbleTeleportOnImpactPortal(temp);
            }
            if (temp.panelIsZero)
            {
                bubbleSize = 0;
                GetScore(storeBubbleSize, bubbleSizeOnText.color, " pts", " +", this.transform.position, false, "playerGetsScore", false);
                playerRef.playerScore             += storeBubbleSize;
                playerRef.playerKills             += 1;
                gameManagerRef.progressBar.f_fill -= (float)storeBubbleSize / 1000;
                GetBubbleEnd();
                Invoke("DestroyBubble", 0.005f);
            }
        }
    }