Пример #1
0
        /// <summary>
        /// Read all the platform objects from the currentReadTarget file
        /// </summary>
        /// <returns></returns>
        public static LinkedList<Platform> readPlatforms()
        {
            const int platformObjSize = 8;
            string content;

            if (currentReadTarget == null)
                throw new Exception("File read target not set. LevelParser.readPlatforms");

            using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(currentReadTarget))
            {
                r.MoveToContent();
                r.ReadToFollowing("objects");
                r.ReadToDescendant("platforms");

                content = r.ReadElementContentAsString();
                r.Close();
            }

            LinkedList<Platform> platforms = new LinkedList<Platform>();

            String[] PlatformString = CleanUp(content);
            for (int i = 0; i < PlatformString.Length / platformObjSize; i++)
            {
                //create the rectangle for this platform
                int[] rectangleValues = getNumbers(PlatformString[i*platformObjSize].Substring(4));
                Rectangle r = new Rectangle(rectangleValues[0], rectangleValues[1], rectangleValues[2], rectangleValues[3]);

                //determine whether or not this platform has gravitic properties
                bool hasGravity = PlatformString[i*platformObjSize + 1].Equals("yesgravity", StringComparison.CurrentCultureIgnoreCase);

                // check hazard status
                bool isHazardous = PlatformString[i * platformObjSize + 3].Equals("hazardous", StringComparison.CurrentCultureIgnoreCase);
                bool goThrough = PlatformString[i*platformObjSize+6].Equals("through", StringComparison.CurrentCultureIgnoreCase);
                bool isTiled = PlatformString[i*platformObjSize+7].Equals("tile", StringComparison.CurrentCultureIgnoreCase);
                bool isAnimated = PlatformString[i*platformObjSize+4].Contains("hplatform");
                // parse texture
                string texName = "Interactive/" + PlatformString[i * platformObjSize + 4];

                Platform final = new Platform(r, texName, isHazardous, isAnimated, hasGravity, goThrough, isTiled);

                //get the patrol values for this platform (out of parse order because it has to be created after the platform object)
                if (!PlatformString[i * platformObjSize + 2].Equals("nopatrol"))
                {
                    int[] patrolValues = getNumbers(PlatformString[i * platformObjSize + 2].Substring(4));
                    PatrolModel p = new PatrolModel();

                    for (int j = 0; j < patrolValues.Length / 3; j++)
                    {
                        p.addVector(new Vector2((float)patrolValues[j * 3], (float)patrolValues[j * 3 + 1]), patrolValues[j * 3 + 2]);
                    }
                    final.SetPatrol(p);

                }

                // read trigger
                if (!PlatformString[i * platformObjSize + 5].Equals("notrigger"))
                {
                    int [] triggerValues = getNumbers(PlatformString[i*platformObjSize+5].Substring(8));
                    for (int j = 0; j < triggerValues.Length; j+=4)
                    {
                        final.addTrigger(new Trigger(new Rectangle(triggerValues[j],triggerValues[j+1],triggerValues[j+2],triggerValues[j+3]), final));
                    }
                }
                platforms.AddFirst(final);
            }
            return platforms;
        }