// Returns the spawn position, based on the set config
        protected virtual Vector2 GetSpawnPosition(SpawningLane spawningLane)
        {
            if (spawningLanesConfig.SpawnOnTrajectory)
            {
                return(GetProjectedSpawnPosition());
            }

            return(GetSpawnPositionInsideLane(spawningLane));
        }
        // Spawns a random item from the pool
        protected virtual void SpawnRandomItem(SpawningLane spawningLane)
        {
            var itemPool = spawningLane.ItemPool;
            int index    = RandomPoolIndex.Next(0, itemPool.Count);

            AbstractItemEntity item = Instantiate(itemPool[index]).GetComponent <AbstractItemEntity>();

            item.Position = GetSpawnPosition(spawningLane);
            item.Setup(_audioService, _particleService, _mainCamera);
        }
        /// <summary>
        /// Calculates the spawn position, according to the spawning lane restrictions
        /// </summary>
        /// <param name="spawningLane"></param>
        /// <returns></returns>
        private Vector2 GetSpawnPositionInsideLane(SpawningLane spawningLane)
        {
            // Random spread within the lane
            float randomPosY = Random.Range(spawningLane.MinHeight, spawningLane.MaxHeight);

            // Introduce deviation on x position
            float deviationX = Random.Range(-spawningLanesConfig.MaxDeviation,
                                            spawningLanesConfig.MaxDeviation);

            var spawnPosition = new Vector2(Position.x + deviationX, GroundPosition.y + randomPosY);

            return(spawnPosition);
        }
        // Checks if Spawn should occur and Spawns object
        protected virtual void AttemptSpawn(float distance)
        {
            if (!_canSpawn)
            {
                return;
            }

            // Try a spawn in each of the lanes
            for (var i = 0; i < spawningLanesConfig.SpawningLanes.Count; i++)
            {
                SpawningLane spawningLane = spawningLanesConfig.SpawningLanes[i];

                if (ShouldSpawn((int)distance, spawningLane))
                {
                    SpawnRandomItem(spawningLane);
                }
            }
        }
        protected virtual bool ShouldSpawn(int distance, SpawningLane spawningLane)
        {
            // Sanity check
            if (spawningLane.ItemPool.Count == 0)
            {
                Logger.Warn("Item Pool is empty! Please verify if everything is correctly setup in the spawners");
                return(false);
            }

            // Do not spawn if the jester is above the lane max height and is also moving upwards
            if (!spawningLanesConfig.SpawnOnTrajectory &&
                _jesterEntity.Position.y > spawningLane.MaxHeight &&
                _jesterEntity.GoBody.velocity.y > 0)
            {
                return(false);
            }

            DistanceSinceLastSpawn = distance - LastSpawnPoint;

            // Do not spawn if the minimum distance since last Spawn was not travelled yet
            if (DistanceSinceLastSpawn <= spawningLanesConfig.MinDistanceBetweenSpawns)
            {
                return(false);
            }

            // Randomly decide whether to spawn
            bool result = spawningLanesConfig.SpawnChance >= Random.Range(0.01f, 1.0f);

            if (result)
            {
                // Reset distance tracking
                LastSpawnPoint         = distance;
                DistanceSinceLastSpawn = 0;
            }

            return(result);
        }
Exemple #6
0
 public void SelectPath(SpawningLane lane)
 {
     currentIndex    = 0;
     waypoints       = paths[(int)lane].AllWaypoints;
     waypointsLength = waypoints.Count;
 }