Exemplo n.º 1
0
 /*
  * CurrentLevel is optional for CoinItem and RunnerItem. Required for Hazard Item because
  * hazard item could be different for different levels
  */
 public RunnerItem GetRandomItemOfType(Type inItemType, LevelGroup.eLevelGroupID currentLevelGroup)
 {
     if (inItemType == typeof(HazardItem))
     {
         if (mHazardItemPool.ContainsKey(currentLevelGroup) && mHazardItemPool[currentLevelGroup].Count > 0)
         {
             RunnerItem existingHazardItem = mHazardItemPool[currentLevelGroup].Dequeue();
             existingHazardItem.gameObject.SetActive(true);
             return(existingHazardItem);
         }
         else
         {
             //Create new Hazard Item
             RunnerItem newItem = ItemFactory(inItemType, currentLevelGroup);
             return(newItem);
         }
     }
     else
     {
         if (mItemPool.ContainsKey(inItemType) && mItemPool[inItemType].Count > 0)
         {
             RunnerItem existingPoolItem = mItemPool[inItemType].Dequeue();
             existingPoolItem.gameObject.SetActive(true);
             return(existingPoolItem);
         }
         else
         {
             // Create a new item
             RunnerItem newItem = ItemFactory(inItemType, currentLevelGroup);
             return(newItem);
         }
     }
 }
Exemplo n.º 2
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;
        }
        }
    }
Exemplo n.º 3
0
    private RunnerItem ItemFactory(Type inItemType, LevelGroup.eLevelGroupID levelGroupID)
    {
        RunnerItem spawnedItem = null;

        if (inItemType == typeof(HazardItem))
        {
            List <HazardItem> hazardItems  = levelHazardItems[levelGroupID];
            HazardItem        randomHazard = hazardItems[Random.Range(0, hazardItems.Count)];
            spawnedItem = (HazardItem)Instantiate(randomHazard);
        }
        else if (inItemType == typeof(CoinItem))
        {
            CoinItem randomCoin = CoinItems[Random.Range(0, CoinItems.Count)];
            spawnedItem = (CoinItem)Instantiate(randomCoin);
        }
        else if (inItemType == typeof(RunnerItem))
        {
            RunnerItem randomItem = ItemPrefabs[Random.Range(0, ItemPrefabs.Count)];
            spawnedItem = (RunnerItem)Instantiate(randomItem);
        }
        else
        {
            Debug.LogError("No spawn logic set for item type " + inItemType);
        }

        spawnedItem.transform.parent = runnerItemsParent.transform;
        return(spawnedItem);
    }
Exemplo n.º 4
0
    //TO DO: need to fix caching bug
    public void StoreOrDisposeItem(RunnerItem inItem, LevelGroup.eLevelGroupID levelGroupID)
    {
        // Disable it. If its queued, then it will 'disapaear' off the map. If its deleted well who cares!
        if (inItem != null)
        {
            inItem.gameObject.SetActive(false);
            Destroy(inItem.gameObject);
        }

        // Type itemType = inItem.GetType();

        // //HazardItem pool needs to be handled differently from the other items
        // if(itemType == typeof(HazardItem)){
        //    //  //Create cache queue
        //    // if(!mHazardItemPool.ContainsKey(levelGroupID))
        //    //      mHazardItemPool.Add(levelGroupID, new Queue<HazardItem>());

        //    // //Add to cache if cache size allows
        //    // if(mHazardItemPool[levelGroupID].Count < ItemPoolMaxSize)
        //    //      mHazardItemPool[levelGroupID].Enqueue((HazardItem)inItem);
        //    // else
        //         GameObject.Destroy(inItem.gameObject);
        // }else{
        //     //Create cache queue
        //     if (!mItemPool.ContainsKey(itemType))
        //         mItemPool.Add(itemType, new Queue<RunnerItem>());

        //    //Add to cache if cache size allows
        //     if (mItemPool[itemType].Count < ItemPoolMaxSize)
        //         mItemPool[itemType].Enqueue(inItem);
        //     else
        //         GameObject.Destroy(inItem.gameObject);
        // }
    }
Exemplo n.º 5
0
    //Remove cached items when resetting
    public void Reset()
    {
        if (mItemPool.ContainsKey(typeof(CoinItem)))
        {
            Queue <RunnerItem> coinQueue = mItemPool[typeof(CoinItem)];
            while (coinQueue.Count > 0)
            {
                print("destroy coin cache");
                RunnerItem coin = coinQueue.Dequeue();
                GameObject.Destroy(coin.gameObject);
            }
        }

        if (mItemPool.ContainsKey(typeof(RunnerItem)))
        {
            Queue <RunnerItem> itemQueue = mItemPool[typeof(RunnerItem)];
            while (itemQueue.Count > 0)
            {
                RunnerItem item = itemQueue.Dequeue();
                GameObject.Destroy(item.gameObject);
            }
        }
    }
Exemplo n.º 6
0
        /// <summary>
        /// Gets an existing free repl session or creates a new one if required
        /// </summary>
        /// <param name="baseValues">the base values used to initialize the repl - session</param>
        /// <param name="scopeInitializer">a callback that is used to prepare the scope variables for the scripting</param>
        /// <param name="visitorInstance">the visitor instance that is capable to process expressions and scripts</param>
        /// <returns>a runner item that can be used to control the repl session</returns>
        public static IDisposable GetReplInstance(IDictionary <string, object> baseValues,
                                                  InitializeScopeVariables scopeInitializer,
                                                  out ScriptVisitor visitorInstance)
        {
            bool simpleInit = (baseValues is Scope);

            lock (runners)
            {
                RunnerItem retVal = runners.FirstOrDefault(n => !simpleInit && n.Lock());
                if (retVal == null)
                {
                    ScriptVisitor visitor = simpleInit
                        ? new ScriptVisitor((Scope)baseValues)
                        : new ScriptVisitor();
                    retVal = new RunnerItem(visitor, simpleInit);
                    retVal.Lock();
                    if (visitor.Reactivateable)
                    {
                        runners.Add(retVal);
                    }
                }

                visitorInstance = (ScriptVisitor)retVal.Visitor;
                if (!simpleInit)
                {
                    visitorInstance.ClearScope(baseValues);
                }

                InitializeScopeVariables dff = scopeInitializer ??
                                               (a =>
                {
                    DefaultCallbacks.PrepareDefaultCallbacks(a.Scope, a.ReplSession);
                });
                visitorInstance.Prepare(dff);
                return(retVal);
            }
        }
Exemplo n.º 7
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.º 8
0
 public void AddLevelItem(RunnerItem inItemToAdd)
 {
     mSpawnedItems.Add(inItemToAdd);
 }