Example #1
0
    void Update()
    {
        if (!worldFactoryScript)
        {
            //Get world factory script
            GameObject worldFactory = null;
            worldFactory = GlobalOptions.GetWorldFactory();
            if (worldFactory)
            {
                worldFactoryScript = worldFactory.GetComponent <WorldFactory>();
            }
        }

        if (!worldFactoryScript)
        {
            return;
        }

        timeleft -= Time.deltaTime;

        // Interval ended - update GUI text and start new interval
        if (timeleft <= 0.0)
        {
            timeleft = updateInterval;
            string format = worldFactoryScript.GetCurrentObstacleSet();
            guiText.text           = format;
            guiText.material.color = Color.blue;
        }
    }
Example #2
0
 override protected void MakeOnTouch()
 {
     //Get NextLevel
     GlobalOptions.loadingLevel = GlobalOptions.GetWorldFactory().GetComponent <WorldFactory>().GetNextLevelName();
     //GlobalOptions.PlayingLevelNumber=GlobalOptions.PlayingLevelNumber++;
     //GlobalOptions.SavePrefsLastPlayed();
     screenLoader.LoadScreenByName(screenToShow);
 }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        SetRealVelocityWithNoDeltaTime();
        if (!worldFactoryScript)
        {
            //Get world factory script
            GameObject worldFactory = null;
            worldFactory = GlobalOptions.GetWorldFactory();
            if (worldFactory)
            {
                worldFactoryScript = worldFactory.GetComponent <WorldFactory>();
            }
        }

        if (flagYahoo)
        {
            MakeYahoo();
        }

        if (!worldFactoryScript)
        {
            return;
        }

        if (GlobalOptions.gameState == GameStates.GAME)
        {
            MoveLeftRight(force);
            MovingButtons();
            MakeMovingCharacterController();
            TestIsFallen();
            //MakeMusicSpeed();
        }

        bearAnimation.SetWalkSpeed(GetRealVelocityWithNoDeltaTime() / startVelocity);

        SwitchAnimation();
    }
Example #4
0
    public Vector3 GetXandYandAngleSmexForZ(Vector3 inposition, bool usecustomDotIndexAndCustomPos)
    {
        Debug.Log("GetXandYandAngleSmexForZ");
        Vector3 returnXandYandAngle = new Vector3(0, 0, 0);
        int     i;
        float   length = 0;
        float   testlength;
        float   needShag = inposition.z;
        float   t;

        int   tekDotIndex = 0;
        float tekPos      = 0;

        if (usecustomDotIndexAndCustomPos)
        {
            tekDotIndex = customDotIndex;
            tekPos      = customPos;
        }
        else
        {
            tekDotIndex = curDotIndex;
            tekPos      = curPos;
        }

        float length1 = 0, length2 = 0;

        //Vector2 BezieDoty;
        Vector2 BezieDot, origin, control, destination;

        //Vector2 originy,controly,destinationy;

        for (i = tekDotIndex; i < roadPathTransformArray.Count - 1; i++)
        {
            if (i > roadPathTransformArray.Count - 2 && usecustomDotIndexAndCustomPos)
            {
                Debug.Log("i>roadPathTransformArray.Count");
                flagNextTerrainCustom = true;
                return(Vector3.zero);
            }
            //nextterrain
            if (i > roadPathTransformArray.Count - 3 && !usecustomDotIndexAndCustomPos)
            {
                int newCurDot = 1;
                GlobalOptions.GetWorldFactory().GetComponent <WorldFactory>().TryAddTerrrain();
                (abstractElementFactory as TerrainElementFactory).SetNextCurrentTerrain(next);

                next.SetCurDotIndexAndCurPos(newCurDot, tekPos);
                return(next.GetXandYandAngleSmexForZ(inposition, usecustomDotIndexAndCustomPos));
            }

            origin      = new Vector2((roadPathTransformArray[i].position.x + roadPathTransformArray[i - 1].position.x) / 2, (roadPathTransformArray[i].position.z + roadPathTransformArray[i - 1].position.z) / 2);
            control     = new Vector2(roadPathTransformArray[i].position.x, roadPathTransformArray[i].position.z);
            destination = new Vector2((roadPathTransformArray[i + 1].position.x + roadPathTransformArray[i].position.x) / 2, (roadPathTransformArray[i + 1].position.z + roadPathTransformArray[i].position.z) / 2);

            /////

            /*testlength=Mathf.Sqrt(Mathf.Pow (destination.x-origin.x,2)+Mathf.Pow (destination.y-origin.y,2));
             * Debug.Log (tekPos);
             * if(testlength-tekPos>=needShag-length)
             * {
             *      //нашли
             *      tekPos+=needShag-length;
             *      break;
             * }
             * else
             * {
             *      length+=testlength-tekPos;
             *      tekPos=0;
             * }*/

            //наматываем на длинну
            if (tekPos < 0 && i == tekDotIndex)
            {
                if (-tekPos > needShag)
                {
                    //нашли текущую точку
                    tekPos += needShag;
                    break;
                }
                else
                {
                    length += -tekPos;
                    tekPos  = 0;
                }
                //Debug.Log ("0 Dot");
            }

            if (tekPos >= 0 && i == tekDotIndex)
            {
                testlength = Mathf.Sqrt(Mathf.Pow(destination.x - control.x, 2) + Mathf.Pow(destination.y - control.y, 2));
                if (testlength - tekPos >= needShag - length)
                {
                    //нашли текущую точку
                    tekPos += needShag - length;
                    break;
                }
                else
                {
                    length += testlength - tekPos;
                }
            }


            if (i != tekDotIndex)
            {
                testlength = Mathf.Sqrt(Mathf.Pow(control.x - origin.x, 2) + Mathf.Pow(control.y - origin.y, 2));

                if (testlength >= needShag - length)
                {
                    //нашли текущую точку
                    tekPos = -(testlength - (needShag - length));
                    break;
                }
                else
                {
                    length += testlength;
                }

                testlength = Mathf.Sqrt(Mathf.Pow(destination.x - control.x, 2) + Mathf.Pow(destination.y - control.y, 2));
                if (testlength >= needShag - length)
                {
                    //нашли текущую точку
                    tekPos = needShag - length;
                    break;
                }
                else
                {
                    length += testlength;
                }
            }
        }

        //фиксируем точку
        if (usecustomDotIndexAndCustomPos)
        {
            customDotIndex = i;
            customPos      = tekPos;
        }
        else
        {
            curDotIndex = i;
            curPos      = tekPos;
        }

        //Debug.Log ("i="+i+"roadPathTransformArray.Count="+roadPathTransformArray.Count);

        //теперь получим точки безье
        origin  = new Vector2((roadPathTransformArray[i].position.x + roadPathTransformArray[i - 1].position.x) / 2, (roadPathTransformArray[i].position.z + roadPathTransformArray[i - 1].position.z) / 2);
        control = new Vector2(roadPathTransformArray[i].position.x, roadPathTransformArray[i].position.z);
        //Debug.Log (i+"flag"+usecustomDotIndexAndCustomPos);
        if (i > roadPathTransformArray.Count - 2)
        {
            destination = control;
        }
        else
        {
            destination = new Vector2((roadPathTransformArray[i + 1].position.x + roadPathTransformArray[i].position.x) / 2, (roadPathTransformArray[i + 1].position.z + roadPathTransformArray[i].position.z) / 2);
        }

        //originy=new Vector2((roadPathTransformArray[i].position.y+roadPathTransformArray[i-1].position.y)/2,(roadPathTransformArray[i].position.z+roadPathTransformArray[i-1].position.z)/2);
        //controly=new Vector2(roadPathTransformArray[i].position.y,roadPathTransformArray[i].position.y);
        //destinationy=new Vector2((roadPathTransformArray[i+1].position.y+roadPathTransformArray[i].position.y)/2,(roadPathTransformArray[i+1].position.z+roadPathTransformArray[i].position.z)/2);

        length1 = Mathf.Sqrt(Mathf.Pow(control.x - origin.x, 2) + Mathf.Pow(control.y - origin.y, 2));
        length2 = Mathf.Sqrt(Mathf.Pow(destination.x - control.x, 2) + Mathf.Pow(destination.y - control.y, 2));

        //length2=Mathf.Sqrt(Mathf.Pow (destination.x-origin.x,2)+Mathf.Pow (destination.y-origin.y,2));

        t = (length1 + tekPos) / (length1 + length2);

        //t=(tekPos)/(length2);



        BezieDot = GetQuadBezieForT(origin, control, destination, t);
        //BezieDot2=GetQuadBezieForT(origin,control,destination,t-Epsilon);

        //BezieDoty=GetQuadBezieForT(originy,controly,destinationy,t);


        //returnXandYandAngle=new Vector3(BezieDot.x,BezieDot.y,Mathf.Atan ((BezieDot.x-BezieDot2.x)/(BezieDot.y-BezieDot2.y)));
        returnXandYandAngle = new Vector3(BezieDot.x, 0, BezieDot.y);

        //returnXandYandAngle=new Vector3(BezieDot.x,BezieDoty.x,Mathf.Atan ((BezieDot.x-BezieDot2.x)/(BezieDot.y-BezieDot2.y)));
        if (t > 0.5 && usecustomDotIndexAndCustomPos && i > roadPathTransformArray.Count - 2)
        {
            flagNextTerrainCustom = true;
        }
        return(returnXandYandAngle);
    }