Esempio n. 1
0
    private int CreateHorizontalMovingPlatform(List <Platform> platforms, Transform platformParent, float segmentHeight, float platformMargin)
    {
        int filledSegmentsCount = 1;

        float   platformPositionX = MinWorldBoundsX + platformMargin;
        Vector3 platformPosition  = new Vector3(platformPositionX, segmentHeight, 0f);

        Platform newPlatform = _platformSpawner.CreatePlatformOfType(PlatformType.MovingHorizontal, platformPosition, platformParent);

        if (newPlatform != null)
        {
            TryMakePlatformDestructible(newPlatform);

            if (TryCreateItemForPlatform(newPlatform))
            {
                ++filledSegmentsCount;
            }

            MovingPlatform movingPlatform = newPlatform.GetComponent <MovingPlatform>();
            if (movingPlatform != null)
            {
                float horizontalMovementRange = (MaxWorldBoundsX - platformMargin) - (MinWorldBoundsX + platformMargin);
                movingPlatform.Initialize(horizontalMovementRange);
            }

            platforms.Add(newPlatform);
        }

        return(filledSegmentsCount);
    }
Esempio n. 2
0
    private int CreatePlatforms(List <Platform> platforms, int platformCount, PlatformType platformType, Transform platformParent, float segmentHeight, float platformMargin)
    {
        bool  isItemCreated        = false;
        float minPlatformPositionX = MinWorldBoundsX + platformMargin;

        for (int i = 0; i < platformCount; ++i)
        {
            float platformPositionX = CalculateRandomPlatformPositionX(minPlatformPositionX, MaxWorldBoundsX, platformCount - i, _platformWidth, _horizontalPlatformSpacing);
            float platformPositionY = CalculateRandomPlatformPositionY(segmentHeight);

            Vector3 platformPosition = new Vector3(platformPositionX, platformPositionY, 0);

            Platform newPlatform = _platformSpawner.CreatePlatformOfType(platformType, platformPosition, platformParent);
            if (newPlatform != null)
            {
                TryMakePlatformDestructible(newPlatform);
                isItemCreated |= TryCreateItemForPlatform(newPlatform);

                if (platformType == PlatformType.MovingVertical)
                {
                    MovingPlatform movingPlatform = newPlatform.GetComponent <MovingPlatform>();
                    if (movingPlatform != null)
                    {
                        movingPlatform.Initialize(_verticalMovementRange);
                    }
                }

                minPlatformPositionX = newPlatform.transform.position.x + (_horizontalPlatformSpacing + _platformWidth);

                platforms.Add(newPlatform);
            }
        }

        int filledSegmentsCount = 1;

        if (platformCount > 0 && platformType == PlatformType.MovingVertical)
        {
            filledSegmentsCount += _verticalMovementRange;
        }

        if (isItemCreated)
        {
            ++filledSegmentsCount;
        }

        return(filledSegmentsCount);
    }