Esempio n. 1
0
        public void parsePlatforms(LinkedList<WorldObject> objects, Texture2D[,] textures)
        {
            String content;
            int platformVars = 8;
            using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(fileName))
            {
                r.MoveToContent();
                r.ReadToFollowing("objects");
                r.ReadToFollowing("platforms");

                content = r.ReadElementContentAsString();
                content = content.Trim();
                //                "\n        rec 160,530,490,100\n        nogravity\n        ptl x1vel,y1vel,time1,x2vel,y2vel,time2\n        tex 0\n      "
                r.Close();
            }
            // TODO: add properties for hazardous here to level load
            String[] properties = content.Split('\n');
            if (properties.Length > 1)
            {
                for (int i = 0; i < properties.Length; i++)
                {
                    properties[i] = properties[i].Trim();
                }
                for (int i = 0; i < properties.Length; i += platformVars)
                {
                    String[] platformDim = new String[5];
                    platformDim = properties[i].Split(',');
                    platformDim[0] = platformDim[0].Substring(4);
                    Rectangle platformRect = new Rectangle(Convert.ToInt32(platformDim[0]), Convert.ToInt32(platformDim[1]), Convert.ToInt32(platformDim[2]), Convert.ToInt32(platformDim[3]));
                    String textName = "";
            //                                    String textName = properties[i + 4].Substring(4);
              //                                int texNum = Convert.ToInt32(textName);

                    if (properties[i + 4][0] == 'p')
                    {
                        textName = properties[i + 4].Substring(8);
                    }
                    else if (properties[i+4][0] == 'h')
                    {
                        textName = properties[i + 4].Substring(9);
                    }
                    int texNum = Convert.ToInt32(textName)-1;
                    String isHazardous = properties[i + 3];
                    Texture2D platformTex = textures[texNum, 0];
                    WorldObject w;
                    bool goThrough;
                    bool tile;
                    if (properties[i+6].Equals("through")) goThrough = true;
                    else goThrough = false;
                    if (properties[i + 7].Equals("tile")) tile = true;
                    else tile = false;
                    if (isHazardous.Equals("hazardous"))
                    {
                        platformTex = textures[texNum, 3];
                        w = new WorldObject(platformRect, platformTex, Util.ObjectType.HazardPlatform, texNum, goThrough, tile);
                    }
                    else {
                        w = new WorldObject(platformRect, platformTex, Util.ObjectType.Platform, texNum, goThrough, tile);
                    }
                    String hasGravity = properties[i + 1];
                    if (hasGravity.Equals("yesgravity")) w.hasGravity = true;
                    else w.hasGravity = false;
                    String s = properties[i + 2];
                    s = s.Substring(4);
                    String [] ptlPoints = s.Split(',');
                    for (int j = 0; j < ptlPoints.Length-1; j += 3)
                    {
                        PatrolPoint p = new PatrolPoint(Convert.ToInt32(ptlPoints[j]), Convert.ToInt32(ptlPoints[j + 1]), Convert.ToInt32(ptlPoints[j + 2]));
                        w.points.AddLast(p);
                        w.numPoints++;
                    }
                    String s2 = properties[i + 5];
                    s2 = s2.Substring(8);
                    String[] triggerPoints = s2.Split(',');
                    for (int j = 0; j < triggerPoints.Length - 1; j += 4)
                    {
                        Trigger t = new Trigger(new Rectangle(Convert.ToInt32(triggerPoints[j]), Convert.ToInt32(triggerPoints[j+1]), Convert.ToInt32(triggerPoints[j+2]), Convert.ToInt32(triggerPoints[j+3])),
                            cm.Load<Texture2D>("trigger"));
                        w.triggers.AddLast(t);
                    }
                    objects.AddLast(w);
                }
            }
        }
Esempio n. 2
0
        public void parseEnemies(LinkedList<WorldObject> objects, Texture2D[,] textures)
        {
            String content;
            using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(fileName))
            {
                r.MoveToContent();
                r.ReadToFollowing("objects");
                r.ReadToFollowing("enemies");

                content = r.ReadElementContentAsString();
                content = content.Trim();
                //                "\n        rec 160,530,490,100\n        nogravity\n        nopatrol\n        tex 0\n      "
                r.Close();
            }
            String[] properties = content.Split('\n');
            if (properties.Length > 1)
            {
                for (int i = 0; i < properties.Length; i++)
                {
                    properties[i] = properties[i].Trim();
                }
                for (int i = 0; i < properties.Length; i += 3)
                {
                    String[] platformDim = new String[5];
                    platformDim = properties[i].Split(',');
                    platformDim[0] = platformDim[0].Substring(4);
                    Rectangle platformRect = new Rectangle(Convert.ToInt32(platformDim[0]), Convert.ToInt32(platformDim[1]), Convert.ToInt32(platformDim[2]), Convert.ToInt32(platformDim[3]));
                    String textName = properties[i + 2].Substring(4);
                    int texNum = Convert.ToInt32(textName);
                    Texture2D enemyTex = textures[texNum, 1];
                    WorldObject w = new WorldObject(platformRect, enemyTex, Util.ObjectType.Enemy, texNum, false, false);
                    String s = properties[i + 1];
                    s = s.Substring(4);
                    String[] ptlPoints = s.Split(',');
                    for (int j = 0; j < ptlPoints.Length - 1; j += 3)
                    {
                        PatrolPoint p = new PatrolPoint(Convert.ToInt32(ptlPoints[j]), Convert.ToInt32(ptlPoints[j + 1]), Convert.ToInt32(ptlPoints[j + 2]));
                        w.points.AddLast(p);
                        w.numPoints++;
                    }
                    objects.AddLast(w);
                }
            }
        }