Esempio n. 1
0
    private void SpawnItemsInLevel(LevelComponent inLevelComponent, PointGroup inGroup)
    {
        RunnerItemManager runnerItemManager = RunnerItemManager.Instance;

        switch (inGroup.mSpawnType)
        {
        case eSpawnType.Coins:
        {
            SpawnCoinStrip(inLevelComponent, inGroup);
            break;
        }

        case eSpawnType.Hazards:
        {
            HazardItem newHazard = (HazardItem)runnerItemManager.GetRandomItemOfType(typeof(HazardItem), mCurrentLevelGroup.LevelGroupID);
            SpawnitemtAtRandomPointInGroup(inLevelComponent, inGroup, newHazard);
            break;
        }

        case eSpawnType.Items:
        {
            RunnerItem newItem = (RunnerItem)runnerItemManager.GetRandomItemOfType(typeof(RunnerItem), mCurrentLevelGroup.LevelGroupID);
            SpawnitemtAtRandomPointInGroup(inLevelComponent, inGroup, newItem);
            break;
        }
        }
    }
Esempio n. 2
0
    //Destroy all the items for this component
    public void DestroyItems()
    {
        RunnerItemManager runnerItemManager = RunnerItemManager.Instance;

        foreach (RunnerItem currentItem in mSpawnedItems)
        {
            if (currentItem != null)
            {
                runnerItemManager.StoreOrDisposeItem(currentItem, ParentGroup.LevelGroupID);
            }
        }
    }
Esempio n. 3
0
    private void SpawnCoinStrip(LevelComponent inLevelComponent, PointGroup inSpawnGroup)
    {
        RunnerItemManager runnerItemManager = RunnerItemManager.Instance;

        switch (inSpawnGroup.mCurveType)
        {
        case eCurveType.Point:
        case eCurveType.Linear:
        {
            float interpolationLeftovers = 0;
            for (int pointIndex = 0; pointIndex < inSpawnGroup.mPoints.Count - 1; pointIndex++)
            {
                Vector3 currentLineBegin    = inSpawnGroup.mPoints[pointIndex].mPosition;
                Vector3 currentLineEnd      = inSpawnGroup.mPoints[pointIndex + 1].mPosition;
                float   currentLineDistance = Vector3.Distance(currentLineBegin, currentLineEnd);

                // Interpolate along our current line
                int      coinNum  = 1;                   //Number of coins we have spawned on this line
                CoinItem lastCoin = null;
                for (float currentInterpolation = interpolationLeftovers; currentInterpolation < currentLineDistance; currentInterpolation += CoinSpawnDistance)
                {
                    // Find our new spawn point
                    Vector3 newCoinPosition = Vector3.Lerp(currentLineBegin, currentLineEnd, (currentInterpolation / currentLineDistance));
                    // But wait, that's on the prefab. Add in our real world clones position.
                    newCoinPosition += inLevelComponent.transform.localPosition;
                    CoinItem newCoin = (CoinItem)runnerItemManager.GetRandomItemOfType(typeof(CoinItem), mCurrentLevelGroup.LevelGroupID);
                    newCoin.transform.position = newCoinPosition;
                    newCoin.CoinValue          = coinNum;
                    inLevelComponent.AddLevelItem(newCoin);
                    if (coinNum == 1)
                    {
                        newCoin.NextToCollect = true;
                    }
                    else
                    {
                        lastCoin.NextCoin = newCoin;                                 //The coin after the one before us, is us
                    }

                    coinNum++;
                    lastCoin = newCoin;
                    interpolationLeftovers = currentInterpolation - currentLineDistance;
                }
                lastCoin.LastCoin = true;
            }
        }
        break;

        case eCurveType.Quadratic:
        case eCurveType.Cubic:
        {
            float lineLength = CalculateCurveLength(inSpawnGroup);
            if (lineLength > 0f)
            {
                // Set up some variables.
                Vector3 ptA = inSpawnGroup.mPoints[0].mPosition;
                Vector3 ptB = inSpawnGroup.mPoints[1].mPosition;
                Vector3 ptC = inSpawnGroup.mPoints[2].mPosition;
                Vector3 ptD = Vector3.zero;
                if (inSpawnGroup.mPoints.Count > 3)
                {
                    ptD = inSpawnGroup.mPoints[3].mPosition;
                }

                // Iterate the line length.
                int      coinNum  = 1;                   //Number of coins we have spawned on this line
                CoinItem lastCoin = null;
                CoinSpawnDistance += .75f;               //When we are a curve, we need a little bit more spin in between our stars
                for (float currentPosition = 0f; currentPosition < lineLength; currentPosition += CoinSpawnDistance)
                {
                    // Determine current t
                    float currentT = currentPosition / lineLength;
                    // Get the new position
                    Vector3 coinSpawnLocation;
                    if (inSpawnGroup.mCurveType == eCurveType.Quadratic)
                    {
                        coinSpawnLocation = CalculateQuadtraticPoint(currentT, ptA, ptB, ptC);
                    }
                    else
                    {
                        coinSpawnLocation = CalculateBezierPoint(currentT, ptA, ptB, ptC, ptD);
                    }

                    coinSpawnLocation += inLevelComponent.transform.position;
                    // And spawn
                    CoinItem newCoin = (CoinItem)runnerItemManager.GetRandomItemOfType(typeof(CoinItem), mCurrentLevelGroup.LevelGroupID);
                    newCoin.transform.position = coinSpawnLocation;
                    newCoin.CoinValue          = coinNum;
                    inLevelComponent.AddLevelItem(newCoin);
                    if (coinNum == 1)
                    {
                        newCoin.NextToCollect = true;
                    }
                    else
                    {
                        lastCoin.NextCoin = newCoin;                                 //The coin after the one before us, is us
                    }

                    coinNum++;
                    lastCoin = newCoin;
                    inLevelComponent.AddLevelItem(newCoin);
                }
            }
        }
        break;
        }
    }