예제 #1
0
        public LevelEnemiesBuilder ForSelectedLanes(params int[] lanes)
        {
            levelEnemies.SelectRandomLanesToSpawnEnemies().Returns(lanes.ToList());

            return(this);
        }
예제 #2
0
        public EnemySpawnContext[] GenerateEnemySpawnContexts()
        {
            for (int j = 0; j < enemySpawnContexts.Length; j++)
            {
                enemySpawnContexts[j].Clear();
            }

            var selectedLanes   = levelEnemies.SelectRandomLanesToSpawnEnemies();
            var existingEnemies = GetEnemiesInAllLanes();//.ToList();

            for (int i = 0; i < selectedLanes.Count; i++)
            {
                var lane      = selectedLanes[i];
                var enemyType = levelEnemies.GetARandomEnemyForLane(lane);

                var e2        = levelEnemies.GetEnemyOfType(enemyType);
                var startTime = levelEnemies.GetTime(enemyType);

                var mirrorE2 = new MirrorEnemy
                {
                    Name      = e2.Name,
                    MaxYTime  = Mathf.Abs(levelEnemies.Maxy) / e2.Speed + startTime,
                    MinYTime  = Mathf.Abs(levelEnemies.Miny) / e2.Speed + startTime,
                    Speed     = e2.Speed,
                    StartTime = startTime
                };

                //Debug.Log(string.Format("lane: {0}  e2- min: {1} -   max: {2}", selectedLanes[i], mirrorE2.MinYTime, mirrorE2.MaxYTime));

                // Lane check
                if (existingEnemies[lane] != null)
                {
                    continue;
                }

                // Check if new enemy will block the path for the player
                bool spawn = false;
                for (int j = 0; j < existingEnemies.Length; j++)
                {
                    if (lane == j)
                    {
                        continue;
                    }
                    if (existingEnemies[j] == null || !CheckOverlap(existingEnemies[j], mirrorE2.MinYTime, mirrorE2.MaxYTime))
                    {
                        spawn = true;
                        break;
                    }
                }

                if (!spawn)
                {
                    continue;
                }

                existingEnemies[lane] = mirrorE2;

                enemySpawnContexts[i].spawnCar  = true;
                enemySpawnContexts[i].lane      = lane;
                enemySpawnContexts[i].enemyType = enemyType;
                enemySpawnContexts[i].MinyTime  = mirrorE2.MinYTime;
                enemySpawnContexts[i].MaxyTime  = mirrorE2.MaxYTime;
                enemySpawnContexts[i].startTime = startTime;
            }

            return(enemySpawnContexts);
        }