예제 #1
0
        /// <summary>
        /// Parses Xml to populate the level with enemies, objects, etc.
        /// </summary>
        /// <param name="doc">XmlDocument containing level data.</param>
        /// <param name="engine">Game engine.</param>
        /// <returns></returns>
        protected void initializeLevelFromXml(XmlDocument doc, Engine engine)
        {
            // First load the tiles
            XmlElement ele = (XmlElement)doc.GetElementsByTagName("level")[0];
            width_ = Convert.ToInt32(ele.GetAttribute("numTilesWide"));
            height_ = Convert.ToInt32(ele.GetAttribute("numTilesTall"));

            tiles_ = new int[height_, width_];

            XmlNodeList tList = doc.GetElementsByTagName("tile");
            for (int i = 0; i < height_; i++)
            {
                for (int j = 0; j < width_; j++)
                {
                    XmlElement ele2 = (XmlElement)tList[j + i * width_];
                    int tempInt = Convert.ToInt32(ele2.GetAttribute("index"));
                    tiles_[i, j] = tempInt;
                }
            }

            // Load the tileset similar to this
            XmlElement tilesetEle = (XmlElement)doc.GetElementsByTagName("tileset")[0];
            if (tilesetEle == null)
            {
                tileSet_ = Tileset.getTilesetFromContent(@"XML\defaultTileset", engine);
            }
            else
            {
                tileSet_ = Tileset.getTilesetFromContent(tilesetEle.InnerText, engine);
            }

            // Now load the enemies
            tList = doc.GetElementsByTagName("enemy");
            for (int i = 0; i < tList.Count; i++)
            {
                parseEnemy(tList[i]);
            }
            // Now load the healthBoxes, ammoBoxes, weapon pickups, and level transitions
            tList = doc.GetElementsByTagName("item");
            for (int i = 0; i < tList.Count; i++)
            {
                parseItem(tList[i]);
            }
            tList = doc.GetElementsByTagName("overlay");
            for (int i = 0; i < tList.Count; i++)
            {
                parseOverlay(tList[i]);
            }
            // Load player location from file
            if (doc.GetElementsByTagName("playerLocation").Count > 0)
            {
                XmlElement playerLocation = (XmlElement)doc.GetElementsByTagName("playerLocation")[0];
                playerStartLocation_ = new Vector2((float)Convert.ToInt32(playerLocation.GetAttribute("x")), (float)Convert.ToInt32(playerLocation.GetAttribute("y")));
            }

            //TODO: get from XML
            //player_ = new ActuatedMainPlayer(pipeline, null, new Vector2(100f, 200f), new Vector2(1.0f, 0.0f));
            //
            player_ = null;
        }
예제 #2
0
 public void setPlayer(PlayableCharacterAbstract player)
 {
     player_ = player;
 }