예제 #1
0
 void SpawnNewEnemies(float waveTime)
 {
     // Have we spawned all the enemies yet?
     // If not, are we due to spawn one or more enemies?
     while (SpawnedCount < Desc.Count)
     {
         float nextSpawnTime = LastSpawnTime + EnemyType.SpawnRate;
         if (waveTime > nextSpawnTime)
         {
             EnemyInstance newEnemy = new EnemyInstance(EnemyType, nextSpawnTime);
             newEnemy.UpdatePosition(LevelDesc);
             Enemies.Add(newEnemy);
             LastSpawnTime = nextSpawnTime;
             SpawnedCount++;
         }
         else
         {
             break;
         }
     }
 }
예제 #2
0
        bool AdvanceEnemyPositionsAndReportIfAnyActive(float waveTime)
        {
            bool isActive = false;

            for (int i = 0; i < Enemies.Count; i++)
            {
                EnemyInstance enemy = Enemies[i];
                if (enemy.IsActive)
                {
                    float timeSinceLastTick     = waveTime - enemy.LastMoveTime;
                    float progressSinceLastTick = timeSinceLastTick * enemy.Desc.MovementSpeed;
                    if (enemy.SpeedSlowdown > progressSinceLastTick)
                    {
                        progressSinceLastTick = 0.0F;
                    }
                    else
                    {
                        progressSinceLastTick -= enemy.SpeedSlowdown;
                    }
                    float newPosition = enemy.LinearProgress + progressSinceLastTick;
                    if (newPosition > (float)RoadSegments)
                    {
                        enemy.LinearProgress    = (float)RoadSegments;
                        enemy.ReachedFinishLine = true;
                        LivesLostToReport++;
                    }
                    else
                    {
                        enemy.LinearProgress = newPosition;
                    }
                    enemy.UpdatePosition(LevelDesc);
                    enemy.LastMoveTime = waveTime;
                    isActive           = true;
                }
            }

            return(isActive);
        }