Exemplo n.º 1
0
    void Generate()
    {
        m_spire = GameObject.FindGameObjectWithTag("Spire").GetComponent <SpireGenerator>();
        float currentDistance = m_spire.m_flatLengthStart + m_startFreeZoneSize;

        do
        {
            float currentDifficulty = Random.Range(m_globalDifficultyMin, m_globalDifficultyMax);

            int steps = (int)(currentDifficulty * (m_stepsBetweenObstacleForHard - m_stepsBetweenObstacleForEasy) + m_stepsBetweenObstacleForEasy);
            GenerateObstacleStreak(ref currentDistance, steps, currentDifficulty);
        } while (currentDistance < (m_spire.PathLength - m_spire.m_flatLengthEnd - m_startFreeZoneSize));
    }
Exemplo n.º 2
0
    public void SetupPosition(float _pathPosition)
    {
        float          pct   = 0.0f;
        SpireGenerator spire = GameObject.FindGameObjectWithTag("Spire").GetComponent <SpireGenerator>();

        transform.position = spire.Spline.GetAtDistanceFrom(ref pct, _pathPosition);

        Vector3 tangent = spire.Spline.GetTangentAtPercentage(pct);
        float   angle   = Mathf.Acos(Vector3.Dot(tangent, new Vector3(0.0f, 0.0f, 1.0f))) * Mathf.Rad2Deg;
        Vector3 cross   = Vector3.Cross(tangent, new Vector3(0.0f, 0.0f, 1.0f));

        transform.rotation = Quaternion.Euler(0.0f, angle * (cross.y < 0.0f ? 1.0f : -1.0f), 0.0f);
    }
    // Use this for initialization
    void Start()
    {
        GameObject player = GameObject.FindGameObjectWithTag("Player");

        m_playerTransform = player.transform;
        m_playerCtrl      = player.GetComponent <Player_Spire>();
        m_spire           = GameObject.FindGameObjectWithTag("Spire").GetComponent <SpireGenerator>();

        Camera camera = GetComponent <Camera>();
        float  frustumHeightAtUnit      = 2.0f * Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad);
        float  idealFrustumWidthAtUnit  = frustumHeightAtUnit * 9.0f / 16.0f;
        float  idealFrustumHeightAtUnit = idealFrustumWidthAtUnit / camera.aspect;

        camera.fieldOfView = 2.0f * Mathf.Atan(idealFrustumHeightAtUnit * 0.5f) * Mathf.Rad2Deg;
    }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        m_gameProp = GameObject.FindGameObjectWithTag("GameProp").GetComponent <GameProperty_Spire>();
        m_spire    = GameObject.FindGameObjectWithTag("Spire").GetComponent <SpireGenerator>();

        GameObject mainObj = GameObject.Find("Main");

        if (mainObj != null)
        {
            m_main = mainObj.GetComponent <Main>();
        }
        else
        {
            SceneManager.UnloadSceneAsync("SpireUp");
            SceneManager.LoadSceneAsync("Main");
        }

        m_boostVisuals = GetComponent <PlayerBoostVisuals>();

        // Adjust ball size
        transform.localScale = Vector3.one * m_gameProp.m_sphereRadius * 2.0f;
    }
Exemplo n.º 5
0
    private void GenerateObstacles()
    {
        if (m_obstaclePrefab == null)
        {
            return;
        }

        SpireGenerator m_spire = GameObject.FindGameObjectWithTag("Spire").GetComponent <SpireGenerator>();

        float groupDistance   = m_minObstacleDistance * (m_chanceForObstacleCount.Length - 1);
        float currentDistance = m_spire.m_flatLengthStart + groupDistance;

        float randomRange = 0.0f;

        foreach (float value in m_chanceForObstacleCount)
        {
            randomRange += value;
        }

        int   boostCount        = 0;
        float boostEnd          = 0.0f;
        float boostSafeEnd      = 0.0f;
        int   lastObstacleCount = -1;

        int maxObstacleCount = m_chanceForObstacleCount.Length;

        do
        {
            int obstacleCount = 0;
            do
            {
                float obstacleChance = Random.Range(0.0f, randomRange);
                for ( ; obstacleCount < maxObstacleCount; ++obstacleCount)
                {
                    obstacleChance -= m_chanceForObstacleCount[obstacleCount];
                    if (obstacleChance <= 0.0f)
                    {
                        break;
                    }
                }
            } while (obstacleCount == lastObstacleCount);

            int obstacleDone = 0;
            for (int i = 0; i < (m_chanceForObstacleCount.Length - 1) && obstacleDone < obstacleCount; ++i)
            {
                float obstaclePosition = currentDistance + i * m_minObstacleDistance;
                if (obstaclePosition > boostEnd && obstaclePosition < boostSafeEnd)
                {
                    continue;
                }

                if (obstaclePosition > boostSafeEnd)
                {
                    if ((m_chanceForObstacleCount.Length - 1 - i) > (obstacleCount - obstacleDone))
                    {
                        if (Random.Range(0, 2) == 1)
                        {
                            // Chance to insert a boost here
                            if (boostCount < m_maxBoostCount)
                            {
                                if ((Random.Range(0.0f, 1.0f)) < m_boostChance)
                                {
                                    boostCount++;
                                    GameObject boostInstance = Instantiate(m_boostPrefab);
                                    Booster    booster       = boostInstance.GetComponent <Booster>();
                                    booster.PathPosition = obstaclePosition;
                                    booster.SetupPosition();

                                    boostEnd     = obstaclePosition + booster.m_boostDistance;
                                    boostSafeEnd = obstaclePosition + booster.m_boostDistance + m_boostSafeDistance;
                                }
                            }
                            continue;
                        }
                    }
                }

                obstacleDone++;

                int        randomIdx = Random.Range(0, m_obstaclePrefab.Count);
                GameObject instance  = Instantiate(m_obstaclePrefab[randomIdx]);
                Obstacle   obstacle  = instance.GetComponent <Obstacle>();
                obstacle.SetupPosition(obstaclePosition);
            }
            currentDistance += groupDistance;
        } while (currentDistance < (m_spire.PathLength - m_spire.m_flatLengthEnd - groupDistance));
    }
Exemplo n.º 6
0
 private void Awake()
 {
     m_spire  = GameObject.FindGameObjectWithTag("Spire").GetComponent <SpireGenerator>();
     m_player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player_Spire>();
 }