Example #1
0
        public void Draw(GLEx g, int x, int y, int sx, int sy, int width,
                         int height, int index, bool lineByLine)
        {
            TMXLayer layer = layers[index];

            layer.Draw(g, x, y, sx, sy, width, height, lineByLine, tileWidth,
                       tileHeight);
        }
Example #2
0
 public void Draw(GLEx g, int x, int y, int sx, int sy, int width,
                  int height, bool lineByLine)
 {
     for (int i = 0; i < layers.Count; i++)
     {
         TMXLayer layer = layers[i];
         layer.Draw(g, x, y, sx, sy, width, height, lineByLine, tileWidth,
                    tileHeight);
     }
 }
Example #3
0
        public string GetLayerProperty(int layerIndex, string propertyName,
                                       string def)
        {
            TMXLayer layer = layers[layerIndex];

            if (layer == null || layer.props == null)
            {
                return(def);
            }
            return(layer.props.GetProperty(propertyName, def));
        }
Example #4
0
 public int GetLayerIndex(string name)
 {
     for (int i = 0; i < layers.Count; i++)
     {
         TMXLayer layer = layers[i];
         if (layer.name.Equals(name))
         {
             return(i);
         }
     }
     return(-1);
 }
Example #5
0
        public LTexture GetTileImage(int x, int y, int layerIndex)
        {
            TMXLayer layer = layers[layerIndex];

            int tileSetIndex = layer.data[x, y, 0];

            if ((tileSetIndex >= 0) && (tileSetIndex < tileSets.Count))
            {
                TMXTileSet tileSet = tileSets[tileSetIndex];

                int sheetX = tileSet.GetTileX(layer.data[x, y, 1]);
                int sheetY = tileSet.GetTileY(layer.data[x, y, 1]);

                return(tileSet.tiles.GetSubImage(sheetX, sheetY));
            }

            return(null);
        }
Example #6
0
        private void Load(Stream ins0, string tileSetsLocation)
        {
            screenRect = LSystem.screenRect;

            tilesLocation = tileSetsLocation;

            try
            {
                XMLDocument doc = XMLParser.Parse(ins0);
                XMLElement docElement = doc.GetRoot();

                string orient = docElement.GetAttribute("orientation", "");
                if (!"orthogonal".Equals(orient))
                {
                    throw new Exception(
                            "Only orthogonal maps supported, found " + orient);
                }

                width = docElement.GetIntAttribute("width", 0);
                height = docElement.GetIntAttribute("height", 0);
                tileWidth = docElement.GetIntAttribute("tilewidth", 0);
                tileHeight = docElement.GetIntAttribute("tileheight", 0);

                XMLElement propsElement = (XMLElement)docElement
                        .GetChildrenByName("properties");
                if (propsElement != null)
                {
                    props = new TMXProperty();
                    List<XMLElement> property = propsElement.List("property");
                    for (int i = 0; i < property.Count; i++)
                    {
                        XMLElement propElement = property[i];
                        string name = propElement.GetAttribute("name", null);
                        string value_ren = propElement.GetAttribute("value", null);
                        props.SetProperty(name, value_ren);
                    }
                }

                if (loadTileSets)
                {
                    TMXTileSet tileSet = null;
                    TMXTileSet lastSet = null;

                    List<XMLElement> setNodes = docElement.List("tileset");
                    for (int i_0 = 0; i_0 < setNodes.Count; i_0++)
                    {
                        XMLElement current = setNodes[i_0];

                        tileSet = new TMXTileSet(this, current, true);
                        tileSet.index = i_0;

                        if (lastSet != null)
                        {
                            lastSet.SetLimit(tileSet.firstGID - 1);
                        }
                        lastSet = tileSet;

                        CollectionUtils.Add(tileSets, tileSet);
                    }
                }

                List<XMLElement> layerNodes = docElement.List("layer");
                for (int i_1 = 0; i_1 < layerNodes.Count; i_1++)
                {
                    XMLElement current_2 = layerNodes[i_1];
                    TMXLayer layer = new TMXLayer(this, current_2);
                    layer.index = i_1;

                    CollectionUtils.Add(layers, layer);
                }

                List<XMLElement> objectGroupNodes = docElement
                        .List("objectgroup");

                for (int i_3 = 0; i_3 < objectGroupNodes.Count; i_3++)
                {
                    XMLElement current_4 = objectGroupNodes[i_3];
                    TMXTileGroup objectGroup = new TMXTileGroup(current_4);
                    objectGroup.index = i_3;

                    CollectionUtils.Add(objectGroups, objectGroup);
                }

                defWidth = (int)(screenRect.GetWidth() / tileWidth);
                defHeight = (int)(screenRect.GetHeight() / tileHeight);

            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
                throw new Exception("Failed to parse map", ex);
            }
        }
Example #7
0
        private void Load(Stream ins, string tileSetsLocation)
        {
            screenRect = LSystem.screenRect;

            tilesLocation = tileSetsLocation;

            try
            {
                XMLDocument doc        = XMLParser.Parse(ins);
                XMLElement  docElement = doc.GetRoot();

                string orient = docElement.GetAttribute("orientation", "");
                if (!"orthogonal".Equals(orient))
                {
                    throw new Exception(
                              "Only orthogonal maps supported, found " + orient);
                }

                width      = docElement.GetIntAttribute("width", 0);
                height     = docElement.GetIntAttribute("height", 0);
                tileWidth  = docElement.GetIntAttribute("tilewidth", 0);
                tileHeight = docElement.GetIntAttribute("tileheight", 0);

                XMLElement propsElement = docElement
                                          .GetChildrenByName("properties");
                if (propsElement != null)
                {
                    props = new TMXProperty();
                    List <XMLElement> property = propsElement.List("property");
                    for (int i = 0; i < property.Count; i++)
                    {
                        XMLElement propElement = property[i];
                        string     name        = propElement.GetAttribute("name", null);
                        string     value_ren   = propElement.GetAttribute("value", null);
                        props.SetProperty(name, value_ren);
                    }
                }

                if (loadTileSets)
                {
                    TMXTileSet tileSet = null;
                    TMXTileSet lastSet = null;

                    List <XMLElement> setNodes = docElement.List("tileset");
                    for (int i_0 = 0; i_0 < setNodes.Count; i_0++)
                    {
                        XMLElement current = setNodes[i_0];

                        tileSet       = new TMXTileSet(this, current, true);
                        tileSet.index = i_0;

                        if (lastSet != null)
                        {
                            lastSet.SetLimit(tileSet.firstGID - 1);
                        }
                        lastSet = tileSet;

                        CollectionUtils.Add(tileSets, tileSet);
                    }
                }

                List <XMLElement> layerNodes = docElement.List("layer");
                for (int i_1 = 0; i_1 < layerNodes.Count; i_1++)
                {
                    XMLElement current_2 = layerNodes[i_1];
                    TMXLayer   layer     = new TMXLayer(this, current_2);
                    layer.index = i_1;

                    CollectionUtils.Add(layers, layer);
                }

                List <XMLElement> objectGroupNodes = docElement
                                                     .List("objectgroup");

                for (int i_3 = 0; i_3 < objectGroupNodes.Count; i_3++)
                {
                    XMLElement   current_4   = objectGroupNodes[i_3];
                    TMXTileGroup objectGroup = new TMXTileGroup(current_4);
                    objectGroup.index = i_3;

                    CollectionUtils.Add(objectGroups, objectGroup);
                }

                defWidth  = (int)(screenRect.GetWidth() / tileWidth);
                defHeight = (int)(screenRect.GetHeight() / tileHeight);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.StackTrace);
                throw new Exception("Failed to parse map", ex);
            }
        }
Example #8
0
        public void SetTileId(int x, int y, int layerIndex, int tileid)
        {
            TMXLayer layer = layers[layerIndex];

            layer.SetTileID(x, y, tileid);
        }
Example #9
0
        public int GetTileId(int x, int y, int layerIndex)
        {
            TMXLayer layer = layers[layerIndex];

            return(layer.GetTileID(x, y));
        }