Example #1
0
        private void Generate(bool i_newSeed)
        {
            m_emulatedState.Reset();

            if (i_newSeed)
            {
                m_cachedSeed = System.Environment.TickCount;
            }
            Random.InitState(m_cachedSeed);

            m_emulatedState.m_difficulty = m_startingDifficulty;

            int puzzleIndex = 0;

            while (m_emulatedState.m_distance < m_emulatedDistanceInCells)
            {
                PuzzleAsset selectedPuzzle = SelectPuzzle();
                if (selectedPuzzle == null)
                {
                    break;
                }

                PuzzleData puzzleData = GeneratePuzzle(puzzleIndex, selectedPuzzle.Generator, transform.position + new Vector3(0f, 0f, m_emulatedState.m_distance * m_cellSize));

                m_emulatedState.m_distance  += puzzleData.Height;
                m_emulatedState.m_difficulty = Mathf.Min(m_emulatedState.m_difficulty + m_difficultyIncreasePerCell * puzzleData.Height, 1f);

                ++puzzleIndex;
            }
        }
Example #2
0
        // Must destroy a puzzle first to spawn a new one
        private IEnumerator GeneratePuzzlesToMax()
        {
            m_generatingPuzzle = true;
            while (m_spawnedPuzzles.Count < m_puzzlesSpawnedAtATime)
            {
                PuzzleAsset selectedPuzzle = SelectPuzzle(m_runningDifficulty);
                if (selectedPuzzle == null)
                {
                    break;
                }

                float totalTrackT      = m_runningDistancePS / m_trackLengthPS;
                float scaledDifficulty = Mathf.InverseLerp(selectedPuzzle.DifficultyMin, selectedPuzzle.DifficultyMax, m_runningDifficulty);
                yield return(GeneratePuzzle(selectedPuzzle.Generator, scaledDifficulty, totalTrackT, totalTrackT % 1f));

                int puzzleHeight = m_spawnedPuzzles.Last().m_puzzleData.Height;
                m_runningDistancePS += puzzleHeight;
                m_runningDifficulty  = Mathf.Min(m_runningDifficulty + m_difficultyIncreasePerCell * puzzleHeight, 1f);
            }
            m_generatingPuzzle = false;
        }