Example #1
0
        private TerrainPoint _GetNextPoint(int difficulty)
        {
            var point = terrainPoints.Borrow();

            point.difficulty = difficulty;

            // This means we've got a restart command
            if (difficulty == 0 && currentPattern.name != initialPatternName)
            {
                currentPattern.ResetPoints();
                currentPattern = GetPatternByName(initialPatternName);
            }


            if (!currentPattern.HasMorePoints())
            {
                Debug.Log("Reached end of pattern - " + currentPattern.name);

                if (OnTerrainPatternFinishedEvent != null)
                {
                    OnTerrainPatternFinishedEvent(currentPattern);
                }

                currentPattern = GetPatternByRank(difficulty);
                Debug.Log("Starting new pattern - " + currentPattern.name);
            }

            var basePoint = currentPattern.GetNextPoint();

            point.distanceFromPrevious = basePoint.distanceFromPrevious;
            point.ceilingY             = basePoint.ceilingY;
            point.floorY      = basePoint.floorY;
            point.patternName = currentPattern.name;
            point.CreateVariation();

            // Set the point at the correct position based on the previous point's
            // position and the distance from it that we just set.
            if (Game.instance.terrainPoints.Count == 0)
            {
                point.x = startingX;
            }
            else
            {
                float previousX = Game.instance.terrainPoints[Game.instance.terrainPoints.Count - 1].x;
                point.x = previousX + point.distanceFromPrevious;
            }

            return(point);
        }
Example #2
0
        // Sets the current pattern to the first which should be the wide tunnel
        protected void Awake()
        {
            // Initialize the patternNames dict to be used later
            for (int i = 0; i < terrainPatterns.Length; i++)
            {
                var pattern = terrainPatterns[i];
                patternNames[pattern.name] = pattern;
            }

            patternNameRanking = new string[terrainPatterns.Length];
            for (int i = 0; i < terrainPatterns.Length; i++)
            {
                patternNameRanking[i] = terrainPatterns[i].name;
            }
            SetPatternRanks();

            currentPattern = GetPatternByName(initialPatternName);
        }