Ejemplo n.º 1
0
 public void Flush()
 {
     _spawnedIdealPlatform = false;
     _ideals.Clear();
     _rndSpace   = 0;
     _spaceCount = 0;
     _prevData   = null;
 }
        public PlatformData GetFirstPlatform(PlatformData data)
        {
            for (var i = _platformsData.IndexOf(data); i >= 0; i--)
            {
                if (_platformsData[i].JoinedPlatform == null)
                {
                    return(_platformsData[i]);
                }
            }

            return(null);
        }
        public void ChooseJoinedPatform(PlatformData data)
        {
            var index = _platformsData.IndexOf(data);

            for (var i = index; i >= 0; i--)
            {
                _platformsData[i].Choosed = true;
                if (_platformsData[i].JoinedPlatform == null)
                {
                    break;
                }
            }

            for (var i = index; i < _platformsData.Count; i++)
            {
                _platformsData[i].Choosed = true;
                if (_platformsData[i].JoinedPlatform == null)
                {
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        public PlatformData GeneratePlatformData(bool isStarted)
        {
            float xPos;
            var   type = EPlatformType.Platform;

            var platformPref = GetPrefBy(type);
            var size         = platformPref.GetComponent <BoxCollider2D>().size;

            if (_prevData != null)
            {
                if (!isStarted)
                {
                    var chance = Random.Range(0, 100);
                    if (chance <= 30)
                    {
                        type = EPlatformType.Platform;
                    }
                    else if (chance > 30 && chance <= 70)
                    {
                        type = EPlatformType.Obstacle;
                    }
                    else
                    {
                        type = EPlatformType.Space;
                    }

                    if ((type == EPlatformType.Space || type == EPlatformType.Obstacle) &&
                        _prevData.Type == EPlatformType.Platform)
                    {
                        var state = true;

                        var count = PlatformManager.Instance.GetPlatformIndex() - 1;
                        _ideals.Add(new IdealPlatform
                        {
                            Counter = count,
                            State   = state
                        });
                    }


                    foreach (var ideal in _ideals)
                    {
                        if (ideal.State)
                        {
                            ideal.Counter++;
                        }
                    }
                }
                else
                {
                    type = EPlatformType.Platform;
                }


                xPos = _prevData.Platform.transform.position.x + size.x;
            }
            else
            {
                var platformStarterSpawnPoint = GameObject.FindWithTag("PlatformSpawnPoint");
                xPos = platformStarterSpawnPoint.transform.position.x;
                type = EPlatformType.Platform;
            }

            for (var i = 0; i < _ideals.Count; i++)
            {
                if (_ideals[i].Counter >= ConfigurationData.PLAYER_JUMP_DISTANCE && _ideals[i].State)
                {
                    type = EPlatformType.Platform;
                    _ideals.Remove(_ideals[i]);

                    _spawnedIdealPlatform = true;
                }
            }

            platformPref = GetPrefBy(type);
            var platform = GameObject.Instantiate(platformPref, new Vector3(xPos, -4, 0f), Quaternion.identity);

            if (_spawnedIdealPlatform)
            {
                _spawnedIdealPlatform = false;
            }

            PlatformData joinedPlatform = null;
            var          choosed        = false;

            if (_prevData != null && _prevData.Type != EPlatformType.Space)
            {
                joinedPlatform = _prevData;
                choosed        = _prevData.Choosed;
            }

            return(_prevData = new PlatformData
            {
                Type = type,
                Platform = platform,
                XDistCenterToEnd = size.x / 2,
                JoinedPlatform = joinedPlatform,
                Choosed = choosed
            });
        }