Ejemplo n.º 1
0
        public static void AddObstacle(Point position, ObstacleDefinition obstacleDefinition, JEventBus eventBus = null)
        {
            Obstacle obstacle = new Obstacle(obstacleDefinition);
            AddObstacleOnWorldMapEvent addObstacleOnWorldMapEvent =
                new AddObstacleOnWorldMapEvent(obstacle, position);

            BaseApi.SendEvent(eventBus, addObstacleOnWorldMapEvent);
        }
        private static void AddObstacleMountains()
        {
            Random random = new Random(789);

            ObstacleDefinition obstacleDefinition = new ObstacleDefinition("Mountain", new Point(2, 3));

            for (int i = 0; i < 25; i++)
            {
                Point position = new Point(random.Next(512), random.Next(512));
                MapObjectFactory.AddObstacle(position, obstacleDefinition);
            }
        }
        private static void AddObstacleTrees()
        {
            Random random = new Random(456);

            ObstacleDefinition obstacleDefinition = new ObstacleDefinition("Tree", new Point(1, 1));

            for (int i = 0; i < 100; i++)
            {
                Point position = new Point(random.Next(512), random.Next(512));
                MapObjectFactory.AddObstacle(position, obstacleDefinition);
            }
        }
Ejemplo n.º 4
0
    void GenerateObstacleStreak(ref float _currentDistance, int _steps, float _difficulty)
    {
        int          prefabCount             = m_obstacleDefinitions.Count;
        float        distance                = _currentDistance;
        List <float> heightOffsetPerObstacle = new List <float>();

        for (int i = 0; i < m_obstacleStreakSize; i++)
        {
            int prefabIdx = Random.Range(0, prefabCount);
            ObstacleDefinition prefabChoosen = null;
            // Find one with the good difficulty
            for (int j = 0; j < prefabCount; j++)
            {
                int realIndex = (j + prefabIdx) % prefabCount;
                if (m_obstacleDefinitions[realIndex].MatchDifficulty(_difficulty))
                {
                    prefabChoosen = m_obstacleDefinitions[realIndex];
                    break;
                }
            }

            if (prefabChoosen != null)
            {
                GameObject instance = Instantiate(prefabChoosen.m_prefab);
                Obstacle   obstacle = instance.GetComponent <Obstacle>();
                obstacle.SetupPosition(_currentDistance);
                heightOffsetPerObstacle.Add(prefabChoosen.m_goldPositionOffset);
            }
            else
            {
                heightOffsetPerObstacle.Add(0.0f);
            }
            _currentDistance += m_stepDistance * _steps;
        }

        // SubSteps for coins
        float lastHeight = 0.0f;

        for (int i = 0; i < m_obstacleStreakSize - 1; i++)
        {
            for (int subStep = 0; subStep < _steps; ++subStep)
            {
                int stepsToGo = _steps - subStep;

                float fraction = Mathf.Min(1.0f, Mathf.Sin(subStep / (float)m_stepsForGoldHeightReset * Mathf.PI / 2.0f));

                float targetHeight = 0.0f;
                if (stepsToGo <= m_stepsForGoldHeightRise)
                {
                    targetHeight = heightOffsetPerObstacle[i + 1];
                    fraction     = Mathf.Sin((1.0f - (stepsToGo / (float)m_stepsForGoldHeightRise)) * Mathf.PI / 2.0f);
                }

                float diff = targetHeight - lastHeight;
                float interpolatedHeight = lastHeight + diff * fraction;
                bool  needCoin           = Random.Range(0.0f, 1.0f) <= m_chanceForSoloGold;
                if (needCoin)
                {
                    float   pct      = 0.0f;
                    Vector3 position = m_spire.Spline.GetAtDistanceFrom(ref pct, distance);
                    position.y += interpolatedHeight;

                    Instantiate(m_goldPrefab, position, Quaternion.identity);
                }
                lastHeight = interpolatedHeight;

                distance += m_stepDistance;
            }
        }
    }
Ejemplo n.º 5
0
 public override void Initialize()
 {
     Definition = null;
 }
Ejemplo n.º 6
0
 public Obstacle(ObstacleDefinition definition)
 {
     Definition = definition;
 }