コード例 #1
0
ファイル: Game1.cs プロジェクト: ordanielcmessias/LGame
 public override void OnLoad()
 {
     map = new TMXTiledMap("assets/testmap.tmx");
     LInfo info = new LInfo(300, 300);
     info.SetLocation(5, 0);
     info.PutMessage("��˵�е�");
     Add(info);
 }
コード例 #2
0
ファイル: TMXTileSet.cs プロジェクト: ordanielcmessias/LGame
        public TMXTileSet(TMXTiledMap map, XMLElement element, bool loadImage)
        {
            this.map = map;
            this.name = element.GetAttribute("name", null);
            this.firstGID = element.GetIntAttribute("firstgid", 0);
            string source = element.GetAttribute("source", "");
            if (!"".Equals(source))
            {
                try
                {
                    Stream ins0 = Resources.OpenStream(map.GetTilesLocation()
                            + "/" + source);
                    XMLDocument doc = XMLParser.Parse(ins0);
                    XMLElement docElement = doc.GetRoot();
                    element = docElement;
                }
                catch (Exception e)
                {
                    Loon.Utils.Debug.Log.Exception(e);
                    throw new Exception(this.map.tilesLocation + "/"
                            + source);
                }
            }
            string tileWidthString = element.GetAttribute("tilewidth", "");
            string tileHeightString = element.GetAttribute("tileheight", "");
            if (tileWidthString.Length == 0 || tileHeightString.Length == 0)
            {
                throw new Exception(
                        "tileWidthString.length == 0 || tileHeightString.length == 0");
            }
            tileWidth = Int32.Parse(tileWidthString);
            tileHeight = Int32.Parse(tileHeightString);

            string sv = element.GetAttribute("spacing", "");
            if ((sv != null) && (!"".Equals(sv)))
            {
                tileSpacing = Int32.Parse(sv);
            }

            string mv = element.GetAttribute("margin", "");
            if ((mv != null) && (!"".Equals(mv)))
            {
                tileMargin = Int32.Parse(mv);
            }

            List<XMLElement> list = element.List("image");
            XMLElement imageNode = list[0];
            string fileName = imageNode.GetAttribute("source", null);

            LColor trans = null;
            string t = imageNode.GetAttribute("trans", null);
            if ((t != null) && (t.Length > 0))
            {
                trans = new LColor(((uint)Convert.ToInt32(t, 16)));
            }

            if (loadImage)
            {
                string path = map.GetTilesLocation() + "/" + fileName;
                LTexture image;
                if (trans != null)
                {
                    image = TextureUtils.FilterColor(path, trans);
                }
                else
                {
                    image = LTextures.LoadTexture(path);
                }
                SetTileSetImage(image);
            }

            List<XMLElement> elements = element.List("tile");
            for (int i = 0; i < elements.Count; i++)
            {
                XMLElement tileElement = elements[i];

                int id = tileElement.GetIntAttribute("id", 0);
                id += firstGID;
                TMXProperty tileProps = new TMXProperty();

                XMLElement propsElement = tileElement
                        .GetChildrenByName("properties");
                List<XMLElement> properties = propsElement.List("property");
                for (int p = 0; p < properties.Count; p++)
                {
                    XMLElement propElement = properties[p];
                    string name_1 = propElement.GetAttribute("name", null);
                    string value_ren = propElement.GetAttribute("value", null);
                    tileProps.SetProperty(name_1, value_ren);
                }
                CollectionUtils.Put(props, id, tileProps);
            }
        }
コード例 #3
0
ファイル: TMXLayer.cs プロジェクト: nobcdz/LGame
        /// <summary>
        /// 根据TMX地图描述创建一个新层
        /// </summary>
        ///
        /// <param name="map"></param>
        /// <param name="element"></param>
        /// <exception cref="System.Exception"></exception>
        public TMXLayer(TMXTiledMap map, XMLElement element)
        {
            this.tmx    = map;
            this.name   = element.GetAttribute("name", "");
            this.width  = element.GetIntAttribute("width", 0);
            this.height = element.GetIntAttribute("height", 0);
            this.data   = new int[width, height, 3];
            this.MaxLightSize(width, height);

            // 获得当前图层属性
            XMLElement propsElement = element.GetChildrenByName("properties");

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

            XMLElement dataNode    = element.GetChildrenByName("data");
            string     encoding    = dataNode.GetAttribute("encoding", null);
            string     compression = dataNode.GetAttribute("compression", null);

            // 进行base64的压缩解码
            if ("base64".Equals(encoding) && "gzip".Equals(compression))
            {
                try
                {
                    byte[] sdec = Base64Coder.DecodeBase64(dataNode.GetContents().Trim().ToCharArray());

                    ByteArrayInputStream mask0 = new ByteArrayInputStream(sdec);

                    GZipInputStream dis = new GZipInputStream(mask0);

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            int tileId = 0;

                            tileId |= dis.ReadByte();
                            tileId |= dis.ReadByte() << 8;
                            tileId |= dis.ReadByte() << 16;
                            tileId |= dis.ReadByte() << 24;

                            if (tileId == 0)
                            {
                                data[x, y, 0] = -1;
                                data[x, y, 1] = 0;
                                data[x, y, 2] = 0;
                            }
                            else
                            {
                                TMXTileSet set = map.FindTileSet(tileId);

                                if (set != null)
                                {
                                    data[x, y, 0] = set.index;
                                    data[x, y, 1] = tileId - set.firstGID;
                                }
                                data[x, y, 2] = tileId;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Loon.Utils.Debug.Log.Exception(e);
                    throw new Exception("Unable to decode base64 !");
                }
            }
            else
            {
                throw new Exception("Unsupport tiled map type " + encoding
                                    + "," + compression + " only gzip base64 Support !");
            }
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: 207h2Flogintvg/LGame
        //GLRenderer renderer;
  
        public override void OnLoad()
        {
            //renderer = new GLRenderer();
            map = new TMXTiledMap("assets/testmap.tmx");
            LInfo info = new LInfo(300, 300);
            info.SetLocked(true);
            info.SetLocation(5, 0);
            info.PutMessage("传说中的");
            Add(info);

        }
コード例 #5
0
ファイル: TMXLayer.cs プロジェクト: 207h2Flogintvg/LGame
        /// <summary>
        /// 根据TMX地图描述创建一个新层
        /// </summary>
        ///
        /// <param name="map"></param>
        /// <param name="element"></param>
        /// <exception cref="System.Exception"></exception>
        public TMXLayer(TMXTiledMap map, XMLElement element)
        {

            this.tmx = map;
            this.name = element.GetAttribute("name", "");
            this.width = element.GetIntAttribute("width", 0);
            this.height = element.GetIntAttribute("height", 0);
            this.data = new int[width, height, 3];
            this.MaxLightSize(width, height);

            // 获得当前图层属性
            XMLElement propsElement = element.GetChildrenByName("properties");

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

            XMLElement dataNode = element.GetChildrenByName("data");
            string encoding = dataNode.GetAttribute("encoding", null);
            string compression = dataNode.GetAttribute("compression", null);

            // 进行base64的压缩解码
            if ("base64".Equals(encoding) && "gzip".Equals(compression))
            {
                try
                {

                    byte[] sdec = Base64Coder.DecodeBase64(dataNode.GetContents().Trim().ToCharArray());

                    ByteArrayInputStream mask0 = new ByteArrayInputStream(sdec);

                    GZipInputStream dis = new GZipInputStream(mask0);

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            int tileId = 0;

                            tileId |= dis.ReadByte();
                            tileId |= dis.ReadByte() << 8;
                            tileId |= dis.ReadByte() << 16;
                            tileId |= dis.ReadByte() << 24;

                            if (tileId == 0)
                            {
                                data[x,y,0] = -1;
                                data[x,y,1] = 0;
                                data[x,y,2] = 0;
                            }
                            else
                            {

                                TMXTileSet set = map.FindTileSet(tileId);

                                if (set != null)
                                {
                               
                                    data[x,y,0] = set.index;
                                    data[x,y,1] = tileId - set.firstGID;
                                }
                                data[x,y,2] = tileId;
                            }

                        }
                    }
                }
                catch (Exception e)
                {
                    Loon.Utils.Debugging.Log.Exception(e);
                    throw new Exception("Unable to decode base64 !");
                }
            }
            else
            {
                throw new Exception("Unsupport tiled map type " + encoding
                        + "," + compression + " only gzip base64 Support !");
            }
        }
コード例 #6
0
ファイル: TMXTileSet.cs プロジェクト: nobcdz/LGame
        public TMXTileSet(TMXTiledMap map, XMLElement element, bool loadImage)
        {
            this.map      = map;
            this.name     = element.GetAttribute("name", null);
            this.firstGID = element.GetIntAttribute("firstgid", 0);
            string source = element.GetAttribute("source", "");

            if (!"".Equals(source))
            {
                try
                {
                    Stream ins0 = Resources.OpenStream(map.GetTilesLocation()
                                                       + "/" + source);
                    XMLDocument doc        = XMLParser.Parse(ins0);
                    XMLElement  docElement = doc.GetRoot();
                    element = docElement;
                }
                catch (Exception e)
                {
                    Loon.Utils.Debug.Log.Exception(e);
                    throw new Exception(this.map.tilesLocation + "/"
                                        + source);
                }
            }
            string tileWidthString  = element.GetAttribute("tilewidth", "");
            string tileHeightString = element.GetAttribute("tileheight", "");

            if (tileWidthString.Length == 0 || tileHeightString.Length == 0)
            {
                throw new Exception(
                          "tileWidthString.length == 0 || tileHeightString.length == 0");
            }
            tileWidth  = Int32.Parse(tileWidthString);
            tileHeight = Int32.Parse(tileHeightString);

            string sv = element.GetAttribute("spacing", "");

            if ((sv != null) && (!"".Equals(sv)))
            {
                tileSpacing = Int32.Parse(sv);
            }

            string mv = element.GetAttribute("margin", "");

            if ((mv != null) && (!"".Equals(mv)))
            {
                tileMargin = Int32.Parse(mv);
            }

            List <XMLElement> list      = element.List("image");
            XMLElement        imageNode = list[0];
            string            fileName  = imageNode.GetAttribute("source", null);

            LColor trans = null;
            string t     = imageNode.GetAttribute("trans", null);

            if ((t != null) && (t.Length > 0))
            {
                trans = new LColor(((uint)Convert.ToInt32(t, 16)));
            }

            if (loadImage)
            {
                string   path = map.GetTilesLocation() + "/" + fileName;
                LTexture image;
                if (trans != null)
                {
                    image = TextureUtils.FilterColor(path, trans);
                }
                else
                {
                    image = LTextures.LoadTexture(path);
                }
                SetTileSetImage(image);
            }

            List <XMLElement> elements = element.List("tile");

            for (int i = 0; i < elements.Count; i++)
            {
                XMLElement tileElement = elements[i];

                int id = tileElement.GetIntAttribute("id", 0);
                id += firstGID;
                TMXProperty tileProps = new TMXProperty();

                XMLElement propsElement = tileElement
                                          .GetChildrenByName("properties");
                List <XMLElement> properties = propsElement.List("property");
                for (int p = 0; p < properties.Count; p++)
                {
                    XMLElement propElement = properties[p];
                    string     name_1      = propElement.GetAttribute("name", null);
                    string     value_ren   = propElement.GetAttribute("value", null);
                    tileProps.SetProperty(name_1, value_ren);
                }
                CollectionUtils.Put(props, id, tileProps);
            }
        }