Esempio n. 1
0
        /// <summary>
        /// Initializes a new map with 3 layers !
        /// </summary>
        /// <param name="mapWidth">Width of map</param>
        /// <param name="mapHeight">Height of Map</param>
        public TileMap(int mapWidth, int mapHeight)
        {
            TileMap.mapWidth = mapWidth;
            TileMap.mapHeight = mapHeight;

            for (int l = 0; l < layercount; l++)
            {
                TileMapLayer layer = new TileMapLayer(mapWidth, mapHeight);
                for (int y = 0; y < mapHeight; y++)
                    for (int x = 0; x < mapWidth; x++)
                        layer.SetTile(x, y, -1);

                layers.Add(layer);
            }
            //Initialize a new tilemap with 3 layers !
        }
Esempio n. 2
0
        private void LoadLayer(XmlNode layerNode, TileMapLayer layer)
        {
            int rowCount = 0;

            foreach (XmlNode node in layerNode)
            {
                if (node.Name == "Row")
                {
                    string row = node.InnerText;
                    row.Trim();
                    string[] cells = row.Split(' ');
                    for (int i = 0; i < mapWidth; i++)
                        layer.SetTile(i, rowCount, Int32.Parse(cells[i]));
                    rowCount++;
                }
            }
        }
Esempio n. 3
0
        private void createNewMap()
        {
            //get values from newmapform

            tileMap = new TileMap.TileMap(mapform.MapWidth, mapform.MapHeight);
            CollisionMap = new Texture2D(GraphicsDevice, mapform.MapWidth * Engine.TileWidth, mapform.MapHeight * Engine.TileHeight);
            CollisionData  = new int[(mapform.MapWidth * Engine.TileWidth) * (mapform.MapHeight * Engine.TileHeight)];
            currentLayer = tileMap.layers[0];
        }
Esempio n. 4
0
 private void BtnLayerUp_Click(object sender, EventArgs e)
 {
     if (tileMap != null)
     {
         int layernumber = int.Parse(TBCurrentLayer.Text);
         if (layernumber + 1 < tileMap.layers.Count)
         {
             currentLayer = tileMap.layers[layernumber + 1];
             TBCurrentLayer.Text = (layernumber + 1).ToString();
         }
     }
 }
Esempio n. 5
0
        private void LoadMap(string mapName)
        {
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(mapName);
            }
            catch
            {
                throw new Exception("Unable to find the map.");
            }

            XmlNode rootNode = xmlDoc.FirstChild;

            if (rootNode.Name != "TileMap")
            {
                throw new Exception("Invalid tile map format!");
            }

            mapWidth = Int32.Parse(rootNode.Attributes["Width"].Value);
            mapHeight = Int32.Parse(rootNode.Attributes["Height"].Value);

            XmlNode layersNode = rootNode.FirstChild;

            if (layersNode.Name != "Layers")
            {
                throw new Exception("Invalid tile map format!");
            }

            TileMapLayer layer;
            int layerCounter = 0;
            foreach (XmlNode node in layersNode.ChildNodes)
            {
                if (node.Name == "Layer")
                {
                    try
                    {
                        layer = new TileMapLayer(mapWidth, mapHeight);
                        LoadLayer(node, layer);
                        layers.Add(layer);
                        layerCounter++;
                        layerNames.Add("Layer " + layerCounter.ToString());
                    }
                    catch
                    {
                        throw new Exception("Error reading in map layer!");
                    }
                }
            }
        }
Esempio n. 6
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfile = new OpenFileDialog();
            //savefile.InitialDirectory = "../Tilesets";
            openfile.Filter = "XML Document (*.xml)|*.xml";
            openfile.Title = "Save map";

            if (openfile.ShowDialog() == DialogResult.OK)
            {
                Players.Clear();
                tileMap = new TileMap.TileMap(1, 1);

               tileMap = tileMap.opentilemap(openfile.FileName);

                //load Collisionmap
               PathfindingNodeManager.GetInstance().ClearNodes();
               CollisionMap = new CollisionMap(GraphicsDevice, tileMap.MapWidth * Engine.TileWidth, tileMap.MapHeight * Engine.TileHeight, true, Util.GetQuadDepth(tileMap.MapWidth));
               CollisionMap.LoadMap(openfile.FileName.Substring(0, openfile.FileName.LastIndexOf('\\')), openfile.FileName.Substring(openfile.FileName.LastIndexOf('\\')).Replace(".xml", ""));
               PathfindingNodeManager.GetInstance().ClearNodes();
                Util.LoadNodes(openfile.FileName, GraphicsDevice);
                Util.LoadPlayers(openfile.FileName);
                CollisionData = new int[(tileMap.MapWidth * Engine.TileWidth) * (tileMap.MapHeight * Engine.TileHeight)];
               currentLayer = tileMap.layers[0];
            }
        }
Esempio n. 7
0
        private void createNewMap()
        {
            //get values from newmapform

            tileMap = new TileMap.TileMap(mapform.MapWidth, mapform.MapHeight);
            CollisionMap = new CollisionMap(GraphicsDevice, mapform.MapWidth * Engine.TileWidth, mapform.MapHeight * Engine.TileHeight,true,Util.GetQuadDepth(mapform.MapWidth));
            //CollisionData  = new int[(mapform.MapWidth * Engine.TileWidth) * (mapform.MapHeight * Engine.TileHeight)];
            currentLayer = tileMap.layers[0];
            Players.Clear();
            PathfindingNodeManager.GetInstance().ClearNodes();
        }