public void Update(GameTime gameTime) { Player.Update(gameTime); Collectables.ForEach(c => c.Update(gameTime)); List <Collectable> collected = Collectables.FindAll(c => c.HasCollidedWithPlayer); foreach (var item in collected) { AllTheSpritesWithinTheScene.Remove(item); Collectables.Remove(item); } var spawnPointsWithinTheViewport = AllSpawnPoints.FindAll(c => Helper.CurrentGame.GraphicsDevice.Viewport.Bounds.Contains(c.SpritePosition - new Vector2(Camera.CamPos.X, Camera.CamPos.Y))); var despawnPointsWithinTheViewport = AllDespawnPoints.FindAll(c => Helper.CurrentGame.GraphicsDevice.Viewport.Bounds.Contains(c.SpritePosition - new Vector2(Camera.CamPos.X, Camera.CamPos.Y))); if (spawnPointsWithinTheViewport.Count > 0 && despawnPointsWithinTheViewport.Count > 0) { if (!AllEnemies.Peek().IsVisible) { AllEnemies.Peek().IsVisible = true; AllEnemies.Peek().SpritePosition = spawnPointsWithinTheViewport.ElementAt(Helper.random.Next(spawnPointsWithinTheViewport.Count)).SpritePosition; AllEnemies.Peek().TargetDestination = despawnPointsWithinTheViewport.ElementAt(Helper.random.Next(despawnPointsWithinTheViewport.Count)).SpritePosition; } } if (AllEnemies.Peek().IsVisible) { AllEnemies.Peek().Update(gameTime); if (AllEnemies.Peek().TargetReached) { AllEnemies.Enqueue(AllEnemies.Dequeue()); } } if (Collectables.Count <= 0) { Gameover = true; } }