using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace Subsurface { class BackgroundSpriteManager { const int MaxSprites = 100; private List prefabs; private List activeSprites; public BackgroundSpriteManager(string configPath) { XDocument doc = ToolBox.TryLoadXml(configPath); if (doc == null) return; activeSprites = new List(); prefabs = new List(); foreach (XElement element in doc.Root.Elements()) { prefabs.Add(new BackgroundSpritePrefab(element)); } } public void Update(float deltaTime) { if (activeSprites.Count < MaxSprites) { WayPoint wp = WayPoint.WayPointList[Rand.Int(WayPoint.WayPointList.Count)]; Vector2 pos = new Vector2(wp.Rect.X, wp.Rect.Y); pos += Rand.Vector(200.0f); var prefab = prefabs[Rand.Int(prefabs.Count)]; int amount = Rand.Range(prefab.SwarmMin,prefab.SwarmMax); List swarmMembers = new List(); for (int i = 0; i0) { Swarm swarm = new Swarm(swarmMembers, prefab.SwarmRadius); } } foreach (BackgroundSprite sprite in activeSprites) { sprite.Update(deltaTime); } } public void Draw(SpriteBatch spriteBatch) { foreach (BackgroundSprite sprite in activeSprites) { sprite.Draw(spriteBatch); } } } }