コード例 #1
0
    public void startGame()
    {
        backWall.transform.position   = new Vector3(-13f, 0f, 0f);
        mainCamera.transform.position = new Vector3(0f, 0f, -10f);
        score.text              = "0";
        earnedGems.text         = "0";
        ball.transform.position = ballStartPos;
        score.gameObject.SetActive(true);
        scoreAnimator.SetBool("fadeIn", true);
        difficultySelectAnimator.SetBool("fadeIn", false);
        difficultySelectAnimator.SetBool("fade", true);
        middlePanelAnimator.SetBool("fadeIn", false);
        middlePanelAnimator.SetBool("fade", true);
        titlePanelAnimator.SetBool("fadeIn", false);
        titlePanelAnimator.SetBool("fade", true);
        pauseButtonAnimator.gameObject.SetActive(true);
        pauseButtonAnimator.SetBool("fadeIn", true);
        ballAnimator.SetBool("moveToStart", true);

        backgroundSource.Play();
        timeController.setGameOver(false);
        timeController.setGameStarted(true);
        followBall.setFollowActive(true);
        followBall.setFirstSpawn();


        foreach (GameObject obj in GameObject.FindGameObjectsWithTag("PlayerFragment"))
        {
            obj.transform.parent        = ball.transform;
            obj.transform.localPosition = Vector3.zero;
            obj.SetActive(false);
        }
    }
コード例 #2
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (isColliding)
        {
            return;
        }
        isColliding = true;
        if (collision.gameObject.CompareTag("destroyBall") || collision.gameObject.CompareTag("Obstacle") || collision.gameObject.CompareTag("ObstacleWallBack"))
        {
            int intScore = int.Parse(score.text);
            if (intScore >= 200 && uiController.getDifficulty() > 0 && PlayerPrefs.GetInt("ach0") == 0)
            {
                PlayerPrefs.SetInt("achtakeable0", 1);
                uiController.activateAchievementInfo(0);
            }
            if (intScore >= 1200 && uiController.getDifficulty() > 0 && PlayerPrefs.GetInt("ach1") == 0)
            {
                PlayerPrefs.SetInt("achtakeable1", 1);
                uiController.activateAchievementInfo(1);
            }
            if (intScore >= 2000 && uiController.getDifficulty() > 0 && PlayerPrefs.GetInt("ach2") == 0)
            {
                PlayerPrefs.SetInt("achtakeable2", 1);
                uiController.activateAchievementInfo(2);
            }
            if (intScore >= 5000 && uiController.getDifficulty() == 2 && PlayerPrefs.GetInt("ach3") == 0)
            {
                PlayerPrefs.SetInt("achtakeable3", 1);
                uiController.activateAchievementInfo(3);
            }
            if (intScore >= 10000 && uiController.getDifficulty() == 2 && PlayerPrefs.GetInt("ach4") == 0)
            {
                PlayerPrefs.SetInt("achtakeable4", 1);
                uiController.activateAchievementInfo(4);
            }
            ballController.getAdController().ShowInterstitialAd();
            if (collision.gameObject.CompareTag("ObstacleWallBack"))
            {
                if (PlayerPrefs.GetInt("ach8") == 0)
                {
                    PlayerPrefs.SetInt("achtakeable8", 1);
                    uiController.activateAchievementInfo(8);
                }
                uiController.setGameOverPanelComment(int.Parse(score.text), true);
            }
            else
            {
                uiController.setGameOverPanelComment(int.Parse(score.text), false);
            }

            gameOverPanel.SetActive(true);
            ballController.getPauseButton().gameObject.SetActive(false);
            timeController.setGameOver(true);
            timeController.endSlowdown();
            fb.StartCoroutine(fb.Shake(1f, 0.05f));
            fb.setFollowActive(false);
            audioController.playExplosion();
            Vector2 lastVelocity = ballController.getBall().GetComponent <Rigidbody2D>().velocity;
            foreach (GameObject frag in ball.GetComponent <Explodable>().fragments)
            {
                frag.transform.parent = null;
                frag.SetActive(true);
                Rigidbody2D fragRb = frag.GetComponent <Rigidbody2D>();
                fragRb.MovePosition(new Vector2(fragRb.position.x + Random.Range(-.2f, .2f), fragRb.position.y + Random.Range(-.2f, .2f)));
                fragRb.AddForce(new Vector2(Random.Range(-2f, 2f), Random.Range(-2f, 2f)) + lastVelocity * 0.5f, ForceMode2D.Impulse);
                fragRb.AddTorque(Random.Range(-2f, 2f) * 2f);
            }
            ball.SetActive(false);
            int currentScore = int.Parse(score.text);
            switch (uiController.getDifficulty())
            {
            case 0:
                if (PlayerPrefs.GetInt("highScoreE") < currentScore)
                {
                    PlayerPrefs.SetInt("highScoreE", currentScore);
                    uiController.setHighscoreSign(ball.transform.position.x);
                }
                break;

            case 1:
                if (PlayerPrefs.GetInt("highScoreN") < currentScore)
                {
                    PlayerPrefs.SetInt("highScoreN", currentScore);
                    uiController.setHighscoreSign(ball.transform.position.x);
                }
                break;

            case 2:
                if (PlayerPrefs.GetInt("highScoreX") < currentScore)
                {
                    PlayerPrefs.SetInt("highScoreX", currentScore);
                    uiController.setHighscoreSign(ball.transform.position.x);
                }
                break;
            }
            calculateAndSetGems();
            shopController.updateAmount();
        }
        else if (collision.gameObject.CompareTag("reset"))
        {
            fb.setFollowActive(false);
            audioController.playExplosion();
            Vector2 lastVelocity = ballController.getBall().GetComponent <Rigidbody2D>().velocity;
            foreach (GameObject frag in ball.GetComponent <Explodable>().fragments)
            {
                frag.transform.parent = null;
                frag.SetActive(true);
                Rigidbody2D fragRb = frag.GetComponent <Rigidbody2D>();
                fragRb.MovePosition(new Vector2(fragRb.position.x + Random.Range(-.2f, .2f), fragRb.position.y + Random.Range(-.2f, .2f)));
                fragRb.AddForce(new Vector2(Random.Range(-2f, 2f), Random.Range(-2f, 2f)) + lastVelocity * 0.5f, ForceMode2D.Impulse);
                fragRb.AddTorque(Random.Range(-2f, 2f) * 2f);
            }
            ball.SetActive(false);
            uiController.StartCoroutine(uiController.waitAndRetry());
        }
        else if (collision.gameObject.CompareTag("collectibleGem"))
        {
            collision.gameObject.SetActive(false);
            audioController.playGemSound();
            PlayerPrefs.SetInt("totalGems", uiController.getTotalGems() + 1);
            uiController.getTotalGemsText().text = PlayerPrefs.GetInt("totalGems").ToString();
            shopController.updateAmount();
        }
    }