Exemple #1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        // stop
        if (other.gameObject.name.Contains("ball") && setTarget && name.IndexOf("bug") < 0)
        {
            if (!other.gameObject.GetComponent <ball>().enabled)
            {
                if ((other.gameObject.tag == "black_hole") && GamePlay.Instance.GameStatus == GameState.Playing)
                {
                    SoundBase.GetInstance().GetComponent <AudioSource>().PlayOneShot(SoundBase.GetInstance().black_hole);
                    DestroySingle(gameObject);
                }

                if (!fireBall)
                {
                    StopBall(true, other.transform);
                }
                else
                {
                    if (other.gameObject.tag.Contains("animal") || other.gameObject.tag.Contains("empty") || other.gameObject.tag.Contains("chicken"))
                    {
                        return;
                    }
                    fireBallLimit--;
                    if (fireBallLimit > 0)
                    {
                        DestroySingle(other.gameObject, 0.000000000001f);
                    }
                    else
                    {
                        StopBall();
                        destroy(fireballArray, 0.000000000001f);
                    }
                }
                //           FindLight(gameObject);
            }
            //          }
        }
        else if (other.gameObject.name.IndexOf("ball") == 0 && setTarget && name.IndexOf("bug") == 0)
        {
            if (other.gameObject.tag == gameObject.tag)
            {
                Destroy(other.gameObject);
                //                Score.Instance.addScore(3);
            }
        }

        else if (other.gameObject.name == "TopBorder" && setTarget)
        {
            if (LevelData.mode == ModeGame.Vertical || LevelData.mode == ModeGame.Animals)
            {
                if (!findMesh)
                {
                    transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z);
                    StopBall();

                    if (fireBall)
                    {
                        destroy(fireballArray, 0.000000000001f);
                    }
                }
            }
        }
    }
 // Use this for initialization
 void Awake()
 {
     DontDestroyOnLoad(gameObject);
     Instance = this;
 }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            GameObject ball = gameObject;
            if (!ClickOnGUI(Input.mousePosition) && !launched && !ball.GetComponent <ball>().setTarget&& MainScript.Instance.newBall2 == null /*&& MainScript.Instance.newBall == null*/ && newBall && !Camera.main.GetComponent <MainScript>().gameOver&& (GamePlay.Instance.GameStatus == GameState.Playing || GamePlay.Instance.GameStatus == GameState.WaitForChicken))
            {
                Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                worldPos = pos;
                if (worldPos.y > -1.5f && !MainScript.StopControl)
                {
                    launched = true;
                    rabbit.Play("rabbit_move");
                    SoundBase.GetInstance().GetComponent <AudioSource>().PlayOneShot(SoundBase.GetInstance().swish[0]);
                    mTouchOffsetX = (worldPos.x - ball.transform.position.x);   //+ MathUtils.random(-10, 10);
                    mTouchOffsetY = (worldPos.y - ball.transform.position.y);
                    xOffset       = (float)Mathf.Cos(Mathf.Atan2(mTouchOffsetY, mTouchOffsetX));
                    yOffset       = (float)Mathf.Sin(Mathf.Atan2(mTouchOffsetY, mTouchOffsetX));
                    speed         = new Vector2(xOffset, yOffset);
                    if (!fireBall)
                    {
                        GetComponent <CircleCollider2D>().enabled = true;
                    }
                    target = worldPos;

                    setTarget  = true;
                    startTime  = Time.time;
                    dropTarget = transform.position;
                    InitScript.Instance.BoostActivated = false;
                    MainScript.Instance.newBall        = gameObject;
                    MainScript.Instance.newBall2       = gameObject;
                    GetComponent <Rigidbody2D>().AddForce(target - dropTarget, ForceMode2D.Force);

                    //Debug.DrawLine( DrawLine.waypoints[0], target );
                    //Debug.Break();
                }
            }
        }
        if (transform.position != target && setTarget && !stopedBall && !isPaused && Camera.main.GetComponent <MainScript>().dropDownTime < Time.time)
        {
            float totalVelocity = Vector3.Magnitude(GetComponent <Rigidbody2D>().velocity);
            if (totalVelocity > 20)
            {
                float tooHard = totalVelocity / (20);
                GetComponent <Rigidbody2D>().velocity /= tooHard;
            }
            else if (totalVelocity < 15)
            {
                float tooSlowRate = totalVelocity / (15);
                if (tooSlowRate != 0)
                {
                    GetComponent <Rigidbody2D>().velocity /= tooSlowRate;
                }
            }

            if (GetComponent <Rigidbody2D>().velocity.y < 1.5f && GetComponent <Rigidbody2D>().velocity.y > 0)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, 1.7f);
            }
        }
        if (setTarget)
        {
            triggerEnter();
        }

        if ((transform.position.y <= -10 || transform.position.y >= 5) && fireBall && !Destroyed)
        {
            MainScript.Instance.CheckFreeChicken();
            setTarget = false;
            launched  = false;
            DestroySingle(gameObject, 0.00001f);
            MainScript.Instance.checkBall = gameObject;
        }
    }
Exemple #4
0
    ///SoundBase.Instance.audio.PlayOneShot( SoundBase.Instance.kreakWheel );

    // Use this for initialization
    void Awake()
    {
        DontDestroyOnLoad(gameObject);
        Instance = this;
    }
Exemple #5
0
 /// <summary>
 ///
 /// </summary>
 public abstract bool Process(SoundBase sound, bool isKeyOff, bool isSoundOff);
Exemple #6
0
 void Awake()
 {
     _instance = this;
 }
Exemple #7
0
    // Update is called once per frame
    IEnumerator WinAction()
    {
        winStarted = true;
        InitScript.Instance.AddLife(1);
        GameObject.Find("Canvas").transform.Find("LevelCleared").gameObject.SetActive(true);
        //       yield return new WaitForSeconds( 1f );
        //if( GameObject.Find( "Music" ) != null)
        //    GameObject.Find( "Music" ).SetActive( false );
        //    GameObject.Find( "CanvasPots" ).transform.Find( "Black" ).gameObject.SetActive( true );
        SoundBase.GetInstance().GetComponent <AudioSource>().PlayOneShot(SoundBase.GetInstance().winSound);
        yield return(new WaitForSeconds(1f));

        if (LevelData.mode == ModeGame.Vertical)
        {
            //  SoundBase.Instance.audio.PlayOneShot( SoundBase.Instance.swish[0] );
            //  GameObject.Find( "Canvas" ).transform.Find( "PreComplete" ).gameObject.SetActive( true );
            yield return(new WaitForSeconds(1f));

            GameObject.Find("CanvasPots").transform.Find("Black").gameObject.SetActive(false);
            //     SoundBase.Instance.audio.PlayOneShot( SoundBase.Instance.swish[0] );
            //  yield return new WaitForSeconds( 1.5f );
            yield return(new WaitForSeconds(0.5f));
        }

        foreach (GameObject item in GameObject.FindGameObjectsWithTag("Ball"))
        {
            item.GetComponent <ball>().StartFall();
        }
        // StartCoroutine( PushRestBalls() );
        Transform b = GameObject.Find("-Ball").transform;

        ball[] balls = GameObject.Find("-Ball").GetComponentsInChildren <ball>();
        foreach (ball item in balls)
        {
            item.StartFall();
        }

        while (LevelData.LimitAmount > 0)
        {
            if (MainScript.Instance.boxCatapult.GetComponent <Grid>().Busy != null)
            {
                LevelData.LimitAmount--;
                ball ball = MainScript.Instance.boxCatapult.GetComponent <Grid>().Busy.GetComponent <ball>();
                MainScript.Instance.boxCatapult.GetComponent <Grid>().Busy = null;
                ball.transform.parent = MainScript.Instance.Balls;
                ball.tag = "Ball";
                ball.PushBallAFterWin();
            }
            yield return(new WaitForEndOfFrame());
        }
        foreach (ball item in balls)
        {
            if (item != null)
            {
                item.StartFall();
            }
        }
        yield return(new WaitForSeconds(2f));

        while (GameObject.FindGameObjectsWithTag("Ball").Length > 0)
        {
            yield return(new WaitForSeconds(0.1f));
        }
        SoundBase.GetInstance().GetComponent <AudioSource>().PlayOneShot(SoundBase.GetInstance().aplauds);
        if (PlayerPrefs.GetInt(string.Format("Level.{0:000}.StarsCount", MainScript.Instance.currentLevel), 0) < MainScript.Instance.stars)
        {
            PlayerPrefs.SetInt(string.Format("Level.{0:000}.StarsCount", MainScript.Instance.currentLevel), MainScript.Instance.stars);
        }


        if (PlayerPrefs.GetInt("Score" + MainScript.Instance.currentLevel) < MainScript.Score)
        {
            PlayerPrefs.SetInt("Score" + MainScript.Instance.currentLevel, MainScript.Score);
        }
        GameObject.Find("Canvas").transform.Find("LevelCleared").gameObject.SetActive(false);
        GameObject.Find("Canvas").transform.Find("MenuComplete").gameObject.SetActive(true);
    }