Ejemplo n.º 1
0
        /// <summary>
        /// Clean up all current obstacles
        /// </summary>
        public void Setdown()
        {
            foreach (KeyValuePair <ObstacleData, ObstaclePool> keyValue in pool)
            {
                keyValue.Value.ResetWeight();
                keyValue.Value.pool.ForEach(item =>
                {
                    item.Setdown();
                });
            }
            nextObst = null;

            weightQueue.Clear();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get an object from the pool
        /// If nothing is available, instantiate a new one
        /// </summary>
        /// <param name="obData"></param>
        /// <returns></returns>
        public ObstacleTilemap GetPool(ObstacleData obData)
        {
            List <ObstacleTilemap> obsPool = pool[obData].pool;
            ObstacleTilemap        obstacle;

            for (int i = 0; i < obsPool.Count; i++)
            {
                obstacle = obsPool[i];
                if (obstacle.isActiveAndEnabled == false)
                {
                    return(obstacle);
                }
            }

            obstacle = Instantiate(obData.GetObstacle());
            obstacle.transform.parent = obstaclePool.transform;
            obsPool.Add(obstacle);
            return(obstacle);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Spawn the next obstacle
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        public ObstacleTilemap SpawnNext()
        {
            ObstacleTilemap obstacle = Spawn(this.nextObst);

            //Modify the weight so it does not occor too many times in a row.
            pool[this.nextObst].ApplyWeightMod();
            if (weightQueue.Count >= currentLevel.data.obstacles.Count)
            {
                pool[weightQueue[qIndex]].ResetWeight();
                weightQueue.RemoveAt(qIndex);
                qIndex++;
                if (qIndex >= currentLevel.data.obstacles.Count)
                {
                    qIndex = 0;
                }
            }

            CalculateTotalWeight();
            weightQueue.Add(this.nextObst);
            this.nextObst = Roll();

            return(obstacle);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Spawn a specific obstacle
        /// </summary>
        /// <param name="data"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public ObstacleTilemap Spawn(ObstacleData obData)
        {
            ObstacleTilemap obstacle = GetPool(obData);

            return(obstacle);
        }
Ejemplo n.º 5
0
 public void SetupResetObst()
 {
     this.nextObst = currentLevel.data.resetObstacle;
 }