//Reads in XML file for mobsets /* * <Mobset> * <Mob type="Slider" health="3" spawnPositionX="-50" spawnPositionX="-50" entryPointX="0" entryPoint="0"> * //Required, Either "Slider","Popper", or "Hunter" * <Type>(Slider|Popper|Hunter)</Type> * //Required * <Health></Health> * //Optional - Default 0 if only one is provided * <SpawnPositionX></SpawnPositionX> * //Optional - Default 0 if only one is provided * <SpawnPositionY></SpawnPositionY> * //Optional - Default random if only one is provided * <EntryPointX></EntryPointX> * //Optional - Default random if only one is provided * <EntryPointY></EntryPointY> * </Mob> * </Mobset> */ public MobSpawner() { mobSetList = new List<MobSet>(); activeMobSets = new List<MobSet>(); currentMode = SpawnerMode.None; XmlDocument doc = new XmlDocument(); doc.Load("Content/Mobset.xml"); string type = ""; Random rng = new Random(); int health, spawnPositionX = -50, spawnPositionY = -50; int entryPointX = rng.Next(ManicShooter.ScreenSize.Left, ManicShooter.ScreenSize.Right); int entryPointY = rng.Next(-50, ManicShooter.ScreenSize.Top); bool hasEntryPoint = false; Vector2 spawnPosition, entryPoint = Vector2.Zero; foreach(XmlNode mobSet in doc.DocumentElement.ChildNodes) { MobSet newMobSet = new MobSet(); foreach (XmlNode mob in mobSet.ChildNodes) { try { type = mob.Attributes["type"].InnerText; health = Int32.Parse(mob.Attributes["health"].InnerText); } catch (Exception e) { throw new Exception("XML data not formatted correctly, please revise."); } if (mob.Attributes["spawnPositionX"] != null) { spawnPositionX = Int32.Parse(mob.Attributes["spawnPositionX"].InnerText); } if (mob.Attributes["spawnPositionY"] != null) { spawnPositionY = Int32.Parse(mob.Attributes["spawnPositionY"].InnerText); } if (mob.Attributes["entryPointX"] != null) { hasEntryPoint = true; entryPointX = Int32.Parse(mob.Attributes["entryPointX"].InnerText); } if (mob.Attributes["entryPointY"] != null) { hasEntryPoint = true; entryPointY = Int32.Parse(mob.Attributes["entryPointY"].InnerText); } spawnPosition = new Vector2(spawnPositionX, spawnPositionY); if (hasEntryPoint) { entryPoint = new Vector2(entryPointX, entryPointY); newMobSet.AddEnemy(type, spawnPosition, health, entryPoint); } else { newMobSet.AddEnemy(type, spawnPosition, health); } } mobSetList.Add(newMobSet); } }
public void SetMode(SpawnerMode mode) { this.mode = mode; }
//Optional: link list with key numbers for testing //Constant mode: automatically spawns a new random mob when the current mob dies public void SetSpawnerMode(SpawnerMode newMode) { currentMode = newMode; }