/// <summary> /// Primary constructor for Level /// </summary> /// <param name="service">ServiceProvider for the main game</param> /// <param name="config"></param> /// <param name="screenWidth"></param> /// <param name="screenHeight"></param> public Level(ContentManager content, LevelConfig config, int screenWidth, int screenHeight) { this.config = config; this.config.NodeWidth = screenWidth / config.HorizontalNodeCount; this.config.NodeHeight = screenHeight / config.VerticalNodeCount; nodeCenter = new Vector2(this.config.NodeWidth / 2, this.config.NodeHeight / 2); this.buildNodes = config.BuildNodes; this.pathNodes = config.PathNodes; mapNodes = new List<MapNode>(); nightmares = new List<Nightmare>(); towers = new List<Tower>(); projectiles = new List<Projectile>(); textures = new Dictionary<string,Texture2D>(); this.content = content; LoadTextures(); InitNodes(); InitNightmares(); Vector2 playerPosition = mapNodes[pathNodes.Count - 1].Position; player = new Player(100, config.WalletStartAmount, new Ability(), new Ability(), playerPosition);//TODO: Add attack/defend abilities }
public LevelConfig GenerateLevelConfig(int level) { Dictionary<string, string> textures = new Dictionary<string,string>(); XmlDocument doc = new XmlDocument(); List<int> build = new List<int>(); List<int> path = new List<int>(); LevelConfig config; doc.Load(levelConfigFile); XmlNode baseNode = doc.SelectSingleNode(String.Format("/levels/level{0}", level)); string[] list = baseNode.SelectSingleNode("nodes/build/ids").InnerText.Split(new char[] { ',' }); foreach (string str in list) { build.Add(Convert.ToInt32(str)); } list = baseNode.SelectSingleNode("nodes/path/ids").InnerText.Split(new char[] { ',' }); foreach (string str in list) { path.Add(Convert.ToInt32(str)); } textures.Add("NONBUILD", baseNode.SelectSingleNode("nodes/nonbuild/texture").InnerText); textures.Add("BUILD", baseNode.SelectSingleNode("nodes/build/texture").InnerText); textures.Add("PATH", baseNode.SelectSingleNode("nodes/path/texture").InnerText); config = new LevelConfig( Convert.ToInt32(baseNode.SelectSingleNode("nodes/horizontalNodeCount").InnerText) , Convert.ToInt32(baseNode.SelectSingleNode("nodes/verticalNodeCount").InnerText) , Convert.ToInt32(baseNode.SelectSingleNode("walletStart").InnerText) , build , path , textures ); return config; }