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; } } }
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); }