Esempio n. 1
0
    /// <summary>
    /// To call when a brick, non falling, is touched by a ball :
    /// Change its state or set it as falling
    /// </summary>
    /// <param name="brickTouched"></param>
    public void NonFallingBrickTouchedByBall(BrickBehaviour brickTouched)
    {
        if (PlayerStatistics.GameEnded)
        {
            return;
        }

        switch (brickTouched.m_ThisBrickType)
        {
        case BrickType.Strong:
            brickTouched.SetStateThisBrick(BrickType.Normal, this);
            break;

        case BrickType.SuperStrong:
            brickTouched.SetStateThisBrick(BrickType.Strong, this);
            break;

        default:
            PlayerStatistics.PlayerNbPoints += 50;
            brickTouched.GetComponent <Rigidbody>().isKinematic = false;
            brickTouched.m_IsBrickFalling = true;
            brickTouched.gameObject.layer = LayerMask.NameToLayer("FallingBrick");
            break;
        }
    }
Esempio n. 2
0
    /// <summary>
    /// To call when a falling brick is hitten, apply the rules of the given brick :
    /// change its state or destroy it, applying its bonus
    /// </summary>
    /// <param name="brickTouched"></param>
    public void OnBrickFallingTouched(BrickBehaviour brickTouched, bool touchedByBall)
    {
        if (PlayerStatistics.GameEnded)
        {
            return;
        }

        switch (brickTouched.m_ThisBrickType)
        {
        case BrickType.Normal:
            brickTouched.DestroyThisBrick();
            NbRemainingBricks--;

            if (touchedByBall)
            {
                PlayerStatistics.PlayerNbPoints += 350;
            }
            break;

        case BrickType.PowerUp_Life:
            brickTouched.DestroyThisBrick();
            NbRemainingBricks--;

            if (touchedByBall)
            {
                PlayerStatistics.PlayerNbPoints += 300;
                PlayerStatistics.PlayerNbLifes  += 2;
            }
            break;

        case BrickType.PowerUp_Speed:
            brickTouched.DestroyThisBrick();
            NbRemainingBricks--;

            if (touchedByBall)
            {
                PlayerStatistics.BallsSpeed     += 0.25f;
                PlayerStatistics.PlayerNbPoints += 300;
            }
            break;

        case BrickType.PowerUp_Ball:
            brickTouched.DestroyThisBrick();
            NbRemainingBricks--;

            if (touchedByBall)
            {
                CreateBallAtRacket();
                PlayerStatistics.PlayerNbPoints += 300;
            }
            break;

        case BrickType.Strong:
            if (touchedByBall)
            {
                brickTouched.SetStateThisBrick(BrickType.Normal, this);
                PlayerStatistics.PlayerNbPoints += 500;
            }
            else
            {
                // destroy it because touched by the ground
                brickTouched.DestroyThisBrick();
                NbRemainingBricks--;
            }
            break;

        case BrickType.SuperStrong:
            if (touchedByBall)
            {
                brickTouched.SetStateThisBrick(BrickType.Strong, this);
                PlayerStatistics.PlayerNbPoints += 1000;
            }
            else
            {
                // destroy it because touched by the ground
                brickTouched.DestroyThisBrick();
                NbRemainingBricks--;
            }
            break;
        }

        if (NbRemainingBricks == 0)
        {
            PlayerStatistics.GameEnded       = true;
            PlayerStatistics.PlayerNbPoints += PlayerStatistics.PlayerNbLifes * 1000;

            // keep the highest score
            if (PlayerPrefs.HasKey("Highscore"))
            {
                if (PlayerPrefs.GetInt("Highscore") < PlayerStatistics.PlayerNbPoints)
                {
                    PlayerPrefs.SetInt("Highscore", PlayerStatistics.PlayerNbPoints);
                }
            }
            else
            {
                PlayerPrefs.SetInt("Highscore", PlayerStatistics.PlayerNbPoints);
            }

            EventManager.raise(EventType.PLAYER_WON);
        }
    }