Exemplo n.º 1
0
    private void SpawnitemtAtRandomPointInGroup(LevelComponent inLevelComponent, PointGroup inSpawnGroup, RunnerItem inItemToSpawn)
    {
        Vector3 newPosition = inSpawnGroup.mPoints[0].mLocalPosition;

        switch (inSpawnGroup.mCurveType)
        {
        case eCurveType.Point:
        {
            if (inSpawnGroup.mPoints.Count > 0)
            {
                //newPosition -= inLevelComponent.gameObject.transform.localPosition;
            }
            else
            {
                Debug.LogError("No point for the line type point?");
            }
        }
        break;

        case eCurveType.Linear:
        {
            if (inSpawnGroup.mPoints.Count > 0)
            {
                //Vector3 randomPoint = inSpawnGroup.mPoints[Random.Range(0, inSpawnGroup.mPoints.Count)].mPosition;
                Debug.Log(inSpawnGroup.mPoints[0].mPosition.y);
                newPosition += inSpawnGroup.mPoints[0].mPosition;
            }
            else
            {
                Debug.LogError("No points for the line type linear");
            }
        }
        break;

        case eCurveType.Quadratic:
        {
            if (inSpawnGroup.mPoints.Count > 3)
            {
                float   randomT             = Random.value;
                Vector3 retrievedCurvePoint = CalculateQuadtraticPoint(randomT,
                                                                       inSpawnGroup.mPoints[0].mPosition,
                                                                       inSpawnGroup.mPoints[1].mPosition,
                                                                       inSpawnGroup.mPoints[2].mPosition);
                newPosition += retrievedCurvePoint;
            }
            else
            {
                Debug.LogError("only " + inSpawnGroup.mPoints.Count + " points for quad curve when I need 3");
            }
        }
        break;

        case eCurveType.Cubic:
        {
            if (inSpawnGroup.mPoints.Count > 4)
            {
                float   randomT             = Random.value;
                Vector3 retrievedCurvePoint = CalculateBezierPoint(randomT,
                                                                   inSpawnGroup.mPoints[0].mPosition,
                                                                   inSpawnGroup.mPoints[1].mPosition,
                                                                   inSpawnGroup.mPoints[2].mPosition,
                                                                   inSpawnGroup.mPoints[3].mPosition);
                newPosition += retrievedCurvePoint;
            }
            else
            {
                Debug.LogError("only " + inSpawnGroup.mPoints.Count + " points for cubic curve when I need 4");
            }
        }
        break;
        }
        inItemToSpawn.transform.position = newPosition + inLevelComponent.transform.localPosition;

        // Spawn it at that point
        //(CoinItem)inItemToSpawn.
        inLevelComponent.AddLevelItem(inItemToSpawn);
    }
Exemplo n.º 2
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;
        }
    }