public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { if (Music != null && Music.State != SoundState.Playing) { Music.Play(); } else if (Music == null && Assets.SoundEffects.ContainsKey("Music")) { Music = Assets.SoundEffects["Music"].CreateInstance(); } if (IsActive && !otherScreenHasFocus && State == GameState.Running) { if (Player.Health < 0) { State = GameState.Lost; GameOver.ScreenState = ScreenState.Active; Assets.SoundEffects["Wilhelm"].Play(); } SpawnerCooldown -= SpawnerCooldown > 0 ? gameTime.ElapsedGameTime.TotalSeconds : 0; if (SpawnerCooldown <= 0) { var spawners = Entities.OfType <Spawner>().ToList(); if (spawners.Count > 0) { SpawnerCooldown = spawners.Count / 10.0f + 0.3f; SpawnCrawler(spawners); } else if (spawners.Count == 0 && !Entities.OfType <Crawler>().Any()) { State = GameState.Won; GameWon.ScreenState = ScreenState.Active; } } if (Pathfinder != null && Player != null && Player.PreviousSector != Player.Sector) { Player.PreviousSector = Player.Sector; var pos = PositionHelper.GetSectorAsVector(Player.Body.Position); Pathfinder.CalculateWavePropogation((int)pos.X, (int)pos.Y); } // becuase it doesn't run fast enough if called only once. for (int i = 0; i < 8; i++) { World.Step(gameTime.ElapsedGameTime); } // Update AI int updatesLeft = 50; while (EnemiesRequiringPath.Count > 0 && updatesLeft > 0) { updatesLeft--; var enemy = EnemiesRequiringPath.Dequeue(); enemy.UpdateDirection(); } while (EntitiesToRemove.Count > 0) { var item = EntitiesToRemove.Pop(); if (World.BodyList.Contains(item.Body)) { World.Remove(item.Body); } if (Entities.Contains(item)) { Entities.Remove(item); } } Camera.Follow(Player); foreach (var e in Entities.Where(e => e != Player).ToList()) { e.Update(gameTime); } Player.Update(gameTime); var origin = ViewPortOrigin; Scale = Zoom == ZoomLevel.Far ? (float)_graphics.PreferredBackBufferWidth / (SectorCountX * SectorSize) : 1.05f; Camera.Zoom = Zoom; ViewPortOrigin = origin; base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); } }