public void drawGridSystem(MapInfoObject mapInfo, Camera2d camera, GraphicsDeviceManager graphics)
        {
            barriersList.Clear();
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
            for (int i = 0; i < mapInfo.gridSizeX; ++i)
            {
                for (int j = 0; j < mapInfo.gridSizeY; ++j)
                {
                    Vector2    transformedV = Vector2.Transform(new Vector2(j * mapInfo.tileSize, i * mapInfo.tileSize), Matrix.Invert(camera.get_transformation(graphics.GraphicsDevice)));
                    var        tile         = new Rectangle((int)transformedV.X, (int)transformedV.Y, mapInfo.tileSize, mapInfo.tileSize);
                    TileObject tile2        = new TileObject();
                    tile2.Rectangle = tile;
                    tile2.isGreen   = false;
                    barriersList.Add(tile2);
                    DrawBorder(tile, 2, Color.Red);
                    var positionsLabel = "(" + tile2.Rectangle.X + ":" + tile2.Rectangle.Y + ")";

                    spriteBatch.DrawString(verdana36, positionsLabel, new Vector2(tile2.Rectangle.X, tile2.Rectangle.Y), Color.White);
                }
            }
            spriteBatch.End();
        }
        //http://clintbellanger.net/articles/isometric_math/
        //spriteBatch.Draw(texture, new Rectangle(400, 50, 100, 100), null, Color.Red, 0, Vector2.Zero, SpriteEffects.None, 0);



        public void drawIsometricGridSystem(MapInfoObject mapInfo, Camera2d camera, GraphicsDeviceManager graphics)
        {
            barriersList.Clear();
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
            for (int i = 0; i < mapInfo.gridSizeX; ++i)
            {
                for (int j = 0; j < mapInfo.gridSizeY; ++j)
                {
                    //  tempPt.x = pt.x - pt.y;
                    //tempPt.y = (pt.x + pt.y) / 2;
                    //var x=j*mapInfo.tileSize/2;
                    //var y=i*mapInfo.tileSize/2;

                    var x = j * mapInfo.tileSize;
                    var y = i * mapInfo.tileSize;

                    //var isotileX = x - y;
                    //var isotileY = (x+y) / 2;
                    //var isotileX = (x - y) * mapInfo.tileSize / 2;
                    //var isotileY = (x + y) * mapInfo.tileSize / 2;
                    Vector2 isoPt        = TwoDToIso(new Vector2(x, y));
                    Vector2 transformedV = Vector2.Transform(new Vector2(isoPt.X, isoPt.Y), Matrix.Invert(camera.get_transformation(graphics.GraphicsDevice)));
                    var     tile         = new Rectangle((int)transformedV.X, (int)transformedV.Y, mapInfo.tileSize, mapInfo.tileSize);

                    TileObject tile2 = new TileObject();
                    tile2.Rectangle = tile;
                    tile2.isGreen   = false;
                    barriersList.Add(tile2);
                    DrawBorder(tile, 2, Color.Red);
                    var positionsLabel = "(" + tile2.Rectangle.X + ":" + tile2.Rectangle.Y + ")";

                    spriteBatch.DrawString(verdana36, positionsLabel, new Vector2(tile2.Rectangle.X, tile2.Rectangle.Y), Color.White, 0, Vector2.Zero, new Vector2(1, 1), SpriteEffects.None, 0);
                }
            }
            spriteBatch.End();
        }
示例#3
0
        public void storeLevelAsJSON(System.Collections.Generic.List <TileObject> listIn, MapInfoObject infoObject, string fullPath)
        {
            List <object> dataList = new List <object>();
            IDictionary <string, MapInfoObject> windowMapInfo = new Dictionary <string, MapInfoObject>();
            IDictionary <string, System.Collections.Generic.List <TileObject> > tilesInfo = new Dictionary <string, System.Collections.Generic.List <TileObject> >();

            windowMapInfo.Add("MapWindowInfo", infoObject);
            tilesInfo.Add("Tiles", listIn);
            dataList.Add(windowMapInfo);
            dataList.Add(tilesInfo);
            var json = JsonConvert.SerializeObject(dataList);

            File.WriteAllText(fullPath, json);
        }