Ejemplo n.º 1
0
        public Tiles[,] GetTiles()
        {
            MapXml mapXml  = new MapXml("Content/demo.tmx");
            var    layers  = mapXml.GetMapLayers();
            var    tileset = mapXml.GetTileset();
            var    data    = layers[0].data;
            //foreach (string i in data)
            //{
            //	Console.WriteLine(i);
            //}
            var width      = layers[0].width;
            var height     = layers[0].height;
            var dataArrays = mapXml.GetDataArrays(data, width, height);

            Tiles[,] tiles = new Tiles[width, height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    var gid = dataArrays[i, j];
                    foreach (var VARIABLE in tileset)
                    {
                        if (gid >= VARIABLE.firstgid && gid < VARIABLE.tilecount + VARIABLE.firstgid)
                        {
                            int       key       = 0;
                            Vector2[] sourcePos = new Vector2[VARIABLE.tilecount];
                            //Console.WriteLine(VARIABLE.tilecount);
                            for (int k = 0; k < VARIABLE.tilecount / VARIABLE.columns; k++)
                            {
                                for (int l = 0; l < VARIABLE.columns; l++)
                                {
                                    sourcePos[key] = new Vector2(l * VARIABLE.tilewidth, k * VARIABLE.tileheight);
                                    key++;
                                }
                            }
                            //Console.WriteLine(VARIABLE.name);
                            Texture2D texture2D = Content.Load <Texture2D>(VARIABLE.name);

                            tiles[i, j] = new Tiles(
                                texture2D,
                                new Vector2(i * VARIABLE.tilewidth, j * VARIABLE.tileheight),
                                new Rectangle(
                                    (int)sourcePos[gid - VARIABLE.firstgid].X,
                                    (int)sourcePos[gid - VARIABLE.firstgid].Y,
                                    VARIABLE.tilewidth,
                                    VARIABLE.tileheight)
                                );
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }

            return(tiles);
        }
Ejemplo n.º 2
0
        public Rectangle[] GetInvisiblePlaces()
        {
            MapXml mapXml  = new MapXml("Content/demo.tmx");
            var    objects = mapXml.GetObjects();

            Rectangle[] objectRectangles = new Rectangle[objects.Count];
            int         key = 0;

            foreach (var VARIABLE in objects)
            {
                objectRectangles[key] = new Rectangle(VARIABLE.xpos, VARIABLE.ypos, VARIABLE.width, VARIABLE.height);
                key++;
            }

            return(objectRectangles);
        }