예제 #1
0
        public Runner.PlatformObject GetRandomPlatformByTypeAndDistance(int type, float distance)
        {
            var result = from p in ListByType[type]
                         where p.MinimumDistance <= distance && HasInTempPlatform(p) == false
                         select p;


            var            len     = result.Count();
            PlatformObject current = null;

            if (len == 1)
            {
                current = PopPlatform(result.ElementAt(0).Id);
                AddToTempPlatform(current);
            }
            else if (len > 0)
            {
                current = PopPlatform(result.ElementAt(Random.Range(0, len)).Id);
                AddToTempPlatform(current);
            }
            else
            {
                Debug.LogError("not available platforms by type: " + type + " and distance: " + distance);
                current = PopPlatform(ListByType[type][(Random.Range(0, ListByType[type].Count))].Id);
                AddToTempPlatform(current);
            }
            return(current);
        }
예제 #2
0
 public static void RemovePowerUpObjects(PlatformObject p)
 {
     foreach (Transform child in p.transform)
     {
         if (child.CompareTag("PowerUp"))
         {
             RemovePowerUpObject(child.GetComponent <ObstaclePowerUp>());
         }
     }
 }
예제 #3
0
        private bool HasInTempPlatform(PlatformObject platform)
        {
            List <int> temp;

            if (tempPlatforms.TryGetValue(platform.Type, out temp))
            {
                return(temp.Contains(platform.Id));
            }
            return(false);
        }
예제 #4
0
        private void AddToListByType(PlatformObject platform)
        {
            List <Runner.PlatformObject> tempList;

            if (ListByType.TryGetValue(platform.Type, out tempList) == false)
            {
                tempList = new List <PlatformObject>();
                ListByType.Add(platform.Type, tempList);
            }
            tempList.Add(platform);
        }
예제 #5
0
        private void AddToTempPlatform(PlatformObject platform)
        {
            List <int> temp;

            if (tempPlatforms.TryGetValue(platform.Type, out temp))
            {
                temp.Add(platform.Id);
            }
            if (temp != null && IsFullTempList(platform.Type))
            {
                RemoveTempType(platform.Type);
            }
        }
예제 #6
0
 public static void AddPowerUpObjects(PlatformObject p)
 {
     foreach (Transform child in p.transform)
     {
         if (child.CompareTag("Bonus"))
         {
             if (Random.Range(1, 100) <= bonusChance)
             {
                 ObstaclePowerUp o = PopPowerUp(Random.Range(0, ListById.Length));
                 p.gameObject.AddChild(o.gameObject);
                 o.gameObject.SetActive(true);
                 o.transform.position = child.position;
             }
         }
     }
 }
예제 #7
0
        public void Generate(float speed, Runner.PlayerController player)
        {
            Runner.PlatformObject platform = _platforms.Last;
            bool isStartPlatform           = false;

            if (platform == null)
            {
                platform        = _platformsManager.GetRandomStartPlatform(Runner.PlayerData.PlatformType);
                isStartPlatform = true;
                if (platform == null)
                {
                    ErrorManager.Show("empty start platform", "add start platforms");
                    return;
                }
                PlayerData.PlatformTypeRemainingDistance = _platformsManager.GetDistanceByType(platform.Type);
                _next = platform.GetNextRandom();
                _platforms.Add(platform);
            }
            float   distance = platform.Distance(player);
            Vector3 size;
            int     count = 0;

            while (distance <= LocationManager.GenerateDistance && count < Runner.LocationManager.MaxGeneratePlatforms)
            {
                int nextType = -1;
                if (PlayerData.PlatformTypeRemainingDistance <= 0.0f && isStartPlatform == false)
                {
                    nextType = _platformsManager.GetTypeByDistance(player.Distance, PlayerData.PlatformType, Random.Range(0, 2) > 0);
                    if (nextType == -1)
                    {
                        nextType = platform.Type;
                    }
                    if (nextType != PlayerData.PlatformType)
                    {
                        _next = _platformsManager.GetTransitionPlatform(PlayerData.PlatformType, nextType);
                    }
                    if (_next == null)
                    {
                        _next = _platformsManager.GetRandomPlatformByTypeAndDistance(PlayerData.PlatformType, player.Distance);
                    }
                    PlayerData.PlatformType = nextType;
                    PlayerData.PlatformTypeRemainingDistance += _platformsManager.GetDistanceByType(nextType);
                }
                else
                {
                    _next = _next != null ? _next : _platformsManager.GetRandomPlatformByTypeAndDistance(PlayerData.PlatformType, _player.Distance);
                }
                _platformsManager.GetSize(out size, platform);
                vectorHelper.x           = 0;
                vectorHelper.y           = 0;
                vectorHelper.z           = size.z - size.z / 2;
                _next.transform.position = platform.transform.position + vectorHelper;
                platform = _next;
                _platformsManager.GetSize(out size, platform);
                vectorHelper.x = 0;
                vectorHelper.y = 0;
                vectorHelper.z = size.z - size.z / 2;
                platform.transform.position += vectorHelper;
                distance = platform.Distance(player);
                _platforms.Add(platform);
                _next = platform.GetNextRandom();
                count++;
            }
        }
예제 #8
0
 public void Reset()
 {
     _next = null;
 }