Beispiel #1
0
    public Vector3 GetNewVector(BallControl fobject, float speed, float t, int c, bool for_direction)
    { // calculate a new positions for balls
      // fobject - script that on a ball
      // speed - speed for move
      // t - percentage between two points [0,1]
      // c - number of point in array of points (SetOfPoints)
      // for_direction - true if need only get a position
        Vector3 ireturn = fobject.gameObject.transform.position;

        t += speed;
        if (speed > 0)
        {
            if (t >= 1)
            {
                t -= 1;
                c++;
                while (t >= 1)
                {
                    t -= 1;
                    c++;
                }
                if (c < SetOfPoints.Count)
                {
                    fobject.c = c;
                }
            }

            if (c > SetOfPoints.Count - 2)
            { // if it`s and of line
                if (!for_direction)
                {
                    if (SendTo.GetComponent <ControlOfPl>().Player_off == 0)
                    {
                        SendTo.GetComponent <ControlOfPl>().Player_off = 1;
                        SendTo.GetComponent <ControlOfPl>().CanThrow.z = 1;
                    }
                    else if (SendTo.GetComponent <ControlOfPl>().Player_off == -1)
                    {
                        int index = SendTo.GeneratedBalls.IndexOf(fobject);
                        Destroy(fobject.gameObject);
                        SendTo.GeneratedBalls.RemoveAt(index);
                    }
                }
            }
            if (c < SetOfPoints.Count - 1 && c >= 0)
            {
                ireturn = new Vector3(Mathf.Lerp(SetOfPoints[c].x, SetOfPoints[c + 1].x, t), Mathf.Lerp(SetOfPoints[c].y, SetOfPoints[c + 1].y, t), Mathf.Lerp(SetOfPoints[c].z, SetOfPoints[c + 1].z, t));
            }
            else
            {
                ireturn = new Vector3(-100, -100, -100);
            }
        }

        if (speed < 0)
        {
            if (t <= 0)
            {
                t += 1;
                c--;
                while (t <= 0)
                {
                    t += 1;
                    c--;
                }
                if (c > 0)
                {
                    if (!for_direction)
                    {
                        fobject.c = c;
                    }
                }
                else
                {
                    fobject.c = 0;
                }
            }
            if (c > 0)
            {
                ireturn = new Vector3(Mathf.Lerp(SetOfPoints[c].x, SetOfPoints[c + 1].x, t), Mathf.Lerp(SetOfPoints[c].y, SetOfPoints[c + 1].y, t), Mathf.Lerp(SetOfPoints[c].z, SetOfPoints[c + 1].z, t));
            }
            else
            {
                ireturn = new Vector3(-100, -100, -100);
            }
        }
        fobject.t = t;
        return(ireturn);
    }
Beispiel #2
0
    void OnTriggerEnter(Collider other)
    {
        if (!once && GameObject.Find("Main Camera").GetComponent <ControlOfPl> ().Player_off == 0)                                                                                                                   // if all right
        {
            if (other.gameObject.GetComponent <BallControl> () != null && gameObject.name == "throw ball" && !This_destroyBall && !This_fireBall && !This_DestroyColor && other.gameObject.name != "ball under off") // if it`s simple ball
            {
                if (other.GetComponent <BallControl> ().c < other.GetComponent <BallControl> ().ccObject.SetOfPoints.Count - 7)                                                                                      // if it`s not near finish
                {
                    BallControl otherToScript = other.gameObject.GetComponent <BallControl> ();                                                                                                                      // get component from other ball
                    mainStart = otherToScript.msScript;

                    GetComponent <BallControl> ().ccObject = otherToScript.ccObject;
                    GetComponent <BallControl> ().msScript = otherToScript.msScript;

                    //тут идет проигрывание звука шарик ударяется
                    if (GameObject.Find("Sound Center").GetComponent <SoundCenter> ().Ball_collision_with_line != null)
                    {
                        GameObject.Find("SC 1").GetComponent <AudioSource> ().PlayOneShot(GameObject.Find("Sound Center").GetComponent <SoundCenter> ().Ball_collision_with_line);
                    }

                    timeBall = mainStart.TimeBall;
                    once     = true;
                    Vector3 GetFirst  = otherToScript.ccObject.GetNewVector(otherToScript, 0.001f, otherToScript.t - 1, otherToScript.c, true);
                    Vector3 GetSecond = otherToScript.ccObject.GetNewVector(otherToScript, 0.001f, otherToScript.t + 1, otherToScript.c, true);
                    // calculate a two distances, need for get info about future position of ball
                    float dist1    = Mathf.Sqrt((transform.position.x - GetFirst.x) * (transform.position.x - GetFirst.x) + (transform.position.y - GetFirst.y) * (transform.position.y - GetFirst.y) + (transform.position.z - GetFirst.z) * (transform.position.z - GetFirst.z));
                    float dist2    = Mathf.Sqrt((transform.position.x - GetSecond.x) * (transform.position.x - GetSecond.x) + (transform.position.y - GetSecond.y) * (transform.position.y - GetSecond.y) + (transform.position.z - GetSecond.z) * (transform.position.z - GetSecond.z));
                    float interval = mainStart.interval;

                    if (dist1 > dist2)
                    {
                        // After this ball
                        mode       = mainStart.GeneratedBalls.IndexOf(otherToScript) - 1;
                        StopIndex2 = mainStart.FindStopIndex(mode, 1f, mainStart.BaseSpeed, 0);
                        if (mainStart.BaseSpeed < 0)
                        {
                            StopIndex2 = mainStart.FindStopIndex(mode, 1f, -mainStart.BaseSpeed, 0);
                        }

                        if (mode >= 0)
                        {
                            if ((interval * mainStart.GeneratedBalls [mode].c + interval * mainStart.GeneratedBalls [mode].t) - (interval * mainStart.GeneratedBalls [mode + 1].c + interval * mainStart.GeneratedBalls [mode + 1].t) > mainStart.distance * 0.99f &&
                                (interval * mainStart.GeneratedBalls [mode].c + interval * mainStart.GeneratedBalls [mode].t) - (interval * mainStart.GeneratedBalls [mode + 1].c + interval * mainStart.GeneratedBalls [mode + 1].t) < mainStart.distance * 3f)
                            {
                                StopIndex2 = mainStart.FindStopIndex(mode, 1f, mainStart.BaseSpeed, 0);
                                if (mainStart.BaseSpeed < 0)
                                {
                                    StopIndex2 = mainStart.FindStopIndex(mode, 1f, -mainStart.BaseSpeed, 0);
                                }
                                dmode = -1;
                            }
                        }
                    }
                    else
                    {
                        // Before this ball
                        mode       = mainStart.GeneratedBalls.IndexOf(otherToScript);
                        StopIndex2 = mainStart.FindStopIndex(mode, 1f, mainStart.BaseSpeed, 0);
                        if (mainStart.BaseSpeed < 0)
                        {
                            StopIndex2 = mainStart.FindStopIndex(mode, 1f, -mainStart.BaseSpeed, 0);
                        }
                        if (mode < mainStart.GeneratedBalls.Count - 2)
                        {
                            if ((interval * mainStart.GeneratedBalls [mode].c + interval * mainStart.GeneratedBalls [mode].t) - (interval * mainStart.GeneratedBalls [mode + 1].c + interval * mainStart.GeneratedBalls [mode + 1].t) > mainStart.distance * 1.01f)
                            {
                                dmode      = 1;
                                StopIndex2 = mainStart.FindStopIndex((mode - 1), 1f, mainStart.BaseSpeed, 0);
                                if (mainStart.BaseSpeed < 0)
                                {
                                    StopIndex2 = mainStart.FindStopIndex((mode - 1), 1f, -mainStart.BaseSpeed, 0);
                                }
                            }
                        }
                    }
                    // start Coroutine for other work
                    if (mainStart.BaseSpeed >= 0)
                    {
                        StartCoroutine(pGoInLine(other.gameObject.GetComponent <SpriteRenderer> ().sortingOrder));
                    }
                    if (mainStart.BaseSpeed < 0)
                    {
                        StartCoroutine(nGoInLine(other.gameObject.GetComponent <SpriteRenderer> ().sortingOrder));
                    }
                    mainStart.mode_IndexStop = mode;
                }
            }
            else if (other.gameObject.GetComponent <BallControl> () != null && gameObject.name == "throw ball" && This_destroyBall && other.gameObject.name != "ball under off")                // if it`s object that can destroy a ball
            {
                once = true;
                if (GameObject.Find("Sound Center").GetComponent <SoundCenter> ().Bonus_Set_of_destroyBall != null)
                {
                    GameObject.Find("SC 7").GetComponent <AudioSource> ().PlayOneShot(GameObject.Find("Sound Center").GetComponent <SoundCenter> ().Bonus_Set_of_destroyBall);
                }
                BallControl otherToScript = other.gameObject.GetComponent <BallControl> ();
                GetComponent <BallControl> ().ccObject = otherToScript.ccObject;
                GetComponent <BallControl> ().msScript = otherToScript.msScript;
                mainStart = otherToScript.msScript;
                int Indexofball = mainStart.GeneratedBalls.IndexOf(otherToScript);
                mainStart.GeneratedBalls.Remove(otherToScript);
                mainStart.CreateDestroyBall(otherToScript.gameObject);

                Vector3 ResultPosition = otherToScript.gameObject.transform.position;
                mainStart.GetComponent <ControlOfPl> ().AddScoreGlobal(mainStart.GetComponent <ControlOfPl> ().Score_Bonuse, otherToScript.GetComponent <SpriteRenderer> ().color, ResultPosition);

                Destroy(otherToScript.gameObject);
                mainStart.IndexStop = mainStart.FindStopIndex((mainStart.GeneratedBalls.Count - 2), 1f, mainStart.BaseSpeed, 0);
                mainStart.gameObject.GetComponent <ControlOfPl> ().SearchAvCollors();
                if (Indexofball > 0 && Indexofball < mainStart.GeneratedBalls.Count - 1 && !mainStart.EndOfLine)
                {
                    if (mainStart.GeneratedBalls [Indexofball].GetComponent <SpriteRenderer> ().color == mainStart.GeneratedBalls [Indexofball - 1].GetComponent <SpriteRenderer> ().color)
                    {
                        if (Indexofball > 1)
                        {
                            if (mainStart.GeneratedBalls [Indexofball - 1].GetComponent <SpriteRenderer> ().color == mainStart.GeneratedBalls [Indexofball - 2].GetComponent <SpriteRenderer> ().color)
                            {
                                mainStart.BaseSpeed = mainStart.saveBaseSpeed;
                                mainStart.StartCoroutine(mainStart.CollisionInline(Indexofball - 1));
                            }
                        }
                        if (Indexofball < mainStart.GeneratedBalls.Count - 2)
                        {
                            if (mainStart.GeneratedBalls [Indexofball].GetComponent <SpriteRenderer> ().color == mainStart.GeneratedBalls [Indexofball + 1].GetComponent <SpriteRenderer> ().color)
                            {
                                mainStart.BaseSpeed = mainStart.saveBaseSpeed;
                                mainStart.StartCoroutine(mainStart.CollisionInline(Indexofball - 1));
                            }
                        }
                    }
                }
                Destroy(gameObject);
            }
            // if`s fire
            if (other.gameObject.GetComponent <BallControl> () != null && gameObject.name == "throw ball" && This_fireBall)
            {
                BallControl otherToScript = other.gameObject.GetComponent <BallControl> ();
                GetComponent <BallControl> ().ccObject = otherToScript.ccObject;
                GetComponent <BallControl> ().msScript = otherToScript.msScript;
                mainStart = otherToScript.msScript;
                mainStart.GeneratedBalls.Remove(otherToScript);
                mainStart.CreateDestroyBall(otherToScript.gameObject);

                Vector3 ResultPosition = otherToScript.gameObject.transform.position;
                mainStart.GetComponent <ControlOfPl> ().AddScoreGlobal(mainStart.GetComponent <ControlOfPl> ().Score_Bonuse, otherToScript.GetComponent <SpriteRenderer> ().color, ResultPosition);

                Destroy(otherToScript.gameObject);
                mainStart.IndexStop = mainStart.FindStopIndex((mainStart.GeneratedBalls.Count - 2), 1f, mainStart.BaseSpeed, 0);
                mainStart.gameObject.GetComponent <ControlOfPl> ().SearchAvCollors();
            }
            // if it`s arrow
            if (other.gameObject.GetComponent <BallControl> () != null && gameObject.name == "throw ball" && This_DestroyColor && other.gameObject.name != "ball under off")
            {
                once = true;
                if (GameObject.Find("Sound Center").GetComponent <SoundCenter> ().Bonus_Destroy_color != null)
                {
                    GameObject.Find("SC 8").GetComponent <AudioSource> ().PlayOneShot(GameObject.Find("Sound Center").GetComponent <SoundCenter> ().Bonus_Destroy_color);
                }
                BallControl otherToScript = other.gameObject.GetComponent <BallControl> ();
                GetComponent <BallControl> ().ccObject = otherToScript.ccObject;
                GetComponent <BallControl> ().msScript = otherToScript.msScript;
                mainStart = otherToScript.msScript;
                Color Color_use = otherToScript.GetComponent <SpriteRenderer> ().color;
                int   countGB   = 0;
                List <BallControl> ListOfDel = new List <BallControl> {
                };
                while (countGB < mainStart.GeneratedBalls.Count)
                {
                    if (mainStart.GeneratedBalls [countGB].GetComponent <SpriteRenderer> ().color == Color_use && mainStart.GeneratedBalls [countGB].gameObject.name == "ball")
                    {
                        ListOfDel.Add(mainStart.GeneratedBalls [countGB]);
                    }
                    countGB++;
                }

                while (ListOfDel.Count > 0)
                {
                    mainStart.GeneratedBalls.Remove(ListOfDel [0]);
                    mainStart.CreateDestroyBall(ListOfDel [0].gameObject);

                    Vector3 ResultPosition = ListOfDel [0].gameObject.transform.position;
                    mainStart.GetComponent <ControlOfPl> ().AddScoreGlobal(mainStart.GetComponent <ControlOfPl> ().Score_Bonuse, otherToScript.GetComponent <SpriteRenderer> ().color, ResultPosition);

                    Destroy(ListOfDel [0].gameObject);
                    ListOfDel.Remove(ListOfDel [0]);
                }

                mainStart.gameObject.GetComponent <ControlOfPl> ().SearchAvCollors();
                mainStart.IndexStop = mainStart.FindStopIndex((mainStart.GeneratedBalls.Count - 2), 1f, mainStart.BaseSpeed, 0);
                Destroy(gameObject);
            }
        }
    }