Пример #1
0
        private void openMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Tile Maps(.xml)|*.xml";
            open.InitialDirectory = System.IO.Path.GetFullPath(filePath + "\\TileMaps");

            if (DialogResult.OK == open.ShowDialog())
            {
                XElement root = XElement.Load(open.FileName);
                ObjectStruct tempObjects = new ObjectStruct();

                XAttribute tileSetFile = root.Attribute("tileSetFile");
                imageName = tileSetFile.Value;
                try
                {
                    tileSetID = TM.LoadTexture(filePath + "\\TileSets\\" + tileSetFile.Value);
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to load the required Tile Set, please check that you have a folder named TileSets");
                    throw;
                }

                int tempX, tempY, tempIndex, tempPixX, tempPixY;
                XElement layer = root.Element("layer");
                XAttribute layerHeight = layer.Attribute("height");
                XAttribute layerWidth = layer.Attribute("width");
                toolTileMapWidth.SelectedIndex = int.Parse(layerWidth.Value) - 1;
                toolTileMapHeight.SelectedIndex = int.Parse(layerHeight.Value) - 1;

                map = new Tile[mapSize.Width, mapSize.Height];

                XElement tileset = root.Element("tileset");
                XAttribute tilesetHeight = tileset.Attribute("height");
                XAttribute tilesetWidth = tileset.Attribute("width");
                toolTileSetHeight.SelectedIndex = int.Parse(tilesetHeight.Value) -1;
                toolTileSetWidth.SelectedIndex = int.Parse(tilesetWidth.Value) - 1;

                XElement tilesize = root.Element("tilesize");
                XAttribute tilesizeHeight = tilesize.Attribute("height");
                XAttribute tilesizeWidth = tilesize.Attribute("width");
                toolTileHeight.SelectedItem = int.Parse(tilesizeHeight.Value);
                toolTileWidth.SelectedItem = int.Parse(tilesizeWidth.Value);

                XElement player = root.Element("player");
                XAttribute playerName = player.Attribute("name");
                XAttribute playerX = player.Attribute("startX");
                XAttribute playerY = player.Attribute("startY");
                tempObjects = new ObjectStruct(playerName.Value);
                tempPixX = int.Parse(playerX.Value);
                tempPixY = int.Parse(playerY.Value);
                tempX = tempPixX / tileSize.Width;
                tempY = tempPixY / tileSize.Height;
                tempIndex = tempY * mapSize.Width + tempX;
                tempObjects.WaypointTiles.Add(tempIndex);
                levelObjects.Add(tempObjects);
                lstObjects.Items.Add(levelObjects[0].Name);

                IEnumerable<XElement> guards = root.Elements("guard");
                int objIndex = 1;
                foreach (XElement guard in guards)
                {
                    XAttribute guardName = guard.Attribute("name");
                    XAttribute guardX = guard.Attribute("startX");
                    XAttribute guardY = guard.Attribute("startY");
                    tempObjects = new ObjectStruct(guardName.Value);
                    tempPixX = int.Parse(guardX.Value);
                    tempPixY = int.Parse(guardY.Value);
                    tempX = tempPixX / tileSize.Width;
                    tempY = tempPixY / tileSize.Height;
                    tempIndex = tempY * mapSize.Width + tempX;
                    tempObjects.WaypointTiles.Add(tempIndex);
                    IEnumerable<XElement> waypoints = guard.Elements("waypoint");

                    foreach (XElement way in waypoints)
                    {
                        if (way.Attribute("tilePoint") != null)
                        {
                            XAttribute point = way.Attribute("tilePoint");
                            tempObjects.WaypointTiles.Add(int.Parse(point.Value));
                        }
                    }
                    levelObjects.Add(tempObjects);
                    lstObjects.Items.Add(levelObjects[objIndex].Name);
                    ++objIndex;
                }

                IEnumerable<XElement> tiles = root.Elements("tiles");
                int x = 0, y = 0;
                foreach (XElement tile in tiles)
                {
                    XAttribute id = tile.Attribute("id");
                    XAttribute col = tile.Attribute("collision");
                    XAttribute eid = tile.Attribute("event");
                    XAttribute fid = tile.Attribute("onfire");
                    XAttribute objID = tile.Attribute("objectID");
                    XAttribute objNum = tile.Attribute("objectNumber");
                    Tile tempTile = new Tile();
                    tempTile.TileID = int.Parse(id.Value);
                    tempTile.CollisionID = int.Parse(col.Value);
                    tempTile.EventID = eid.Value;
                    tempTile.OnFireID = fid.Value;
                    tempTile.ObjectID = char.Parse(objID.Value);
                    tempTile.ObjectNumber = int.Parse(objNum.Value);

                    map[x, y] = tempTile;
                    ++x;
                    if (x >= mapSize.Width)
                    {
                        x = 0;
                        ++y;
                    }
                }
            }
        }
Пример #2
0
        public frmTileEditor()
        {
            InitializeComponent();
            DX.Initialize(pnlTileSet, true);
            DX.AddRenderTarget(pnlTileMap);

            TM.Initialize(DX.Device, DX.Sprite);

            for (int i = 0; i < 100; ++i)
            {
                toolTileSetWidth.Items.Add(i + 1);
                toolTileSetHeight.Items.Add(i + 1);
            }
            for (int i = 1; i < 1025; i *= 2)
            {
                toolTileWidth.Items.Add(i);
                toolTileHeight.Items.Add(i);
            }
            for (int i = 0; i < 200; ++i)
            {
                toolTileMapWidth.Items.Add(i + 1);
                toolTileMapHeight.Items.Add(i + 1);
            }
            toolTileSetWidth.SelectedIndex = 3;
            toolTileSetHeight.SelectedIndex = 1;
            toolTileWidth.SelectedIndex = 6;
            toolTileHeight.SelectedIndex = 6;
            toolTileMapWidth.SelectedIndex = 4;
            toolTileMapHeight.SelectedIndex = 4;

            cmbObjects.SelectedIndex = 0;

            tileSetSize.Width = (int)toolTileSetWidth.SelectedItem;
            tileSetSize.Height = (int)toolTileSetHeight.SelectedItem;
            tileSize.Width = (int)toolTileWidth.SelectedItem;
            tileSize.Height = (int)toolTileHeight.SelectedItem;
            mapSize.Width = (int)toolTileMapWidth.SelectedItem;
            mapSize.Height = (int)toolTileMapHeight.SelectedItem;

            map = new Tile[mapSize.Width, mapSize.Height];
            Tile temp = new Tile();
            temp.TileID = 0;
            temp.CollisionID = 0;
            temp.EventID = "none";
            temp.OnFireID = "none";
            temp.ObjectID = '0';
            temp.ObjectNumber = 0;
            for (int x = 0; x < mapSize.Width; ++x)
            {
                for (int y = 0; y < mapSize.Height; ++y)
                {
                    map[x, y] = temp;
                }
            }

            objectCount = 0;
            levelObjects = new List<ObjectStruct>();

            btnMapLayer.BackColor = Color.ForestGreen;
            btnPaint.BackColor = Color.PowderBlue;
            btnAddEvent.BackColor = Color.PaleGreen;
            btnAddObject.BackColor = Color.Green;

            mapLocation = new Point(0, 0);

            MessageBox.Show("Please select the folder that contains your tilesets and map scripts.\nThis folder must have the following 2 folders within it:\nTileSets   - Contains the tilesets that are used to paint maps\nTileMaps - Contains the xml scripts that are used to build levels");
            FolderBrowserDialog folder = new FolderBrowserDialog();
            if (DialogResult.OK == folder.ShowDialog())
            {
                filePath = System.IO.Path.GetFullPath(folder.SelectedPath);
            }

            this.Focus();
        }
Пример #3
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tileSetID > 0)
            {
                TM.UnloadTexture(0);
                --tileSetID;
            }

            toolTileSetWidth.SelectedIndex = 3;
            toolTileSetHeight.SelectedIndex = 1;
            toolTileWidth.SelectedIndex = 6;
            toolTileHeight.SelectedIndex = 6;
            toolTileMapWidth.SelectedIndex = 4;
            toolTileMapHeight.SelectedIndex = 4;

            tileSetSize.Width = (int)toolTileSetWidth.SelectedItem;
            tileSetSize.Height = (int)toolTileSetHeight.SelectedItem;
            tileSize.Width = (int)toolTileWidth.SelectedItem;
            tileSize.Height = (int)toolTileHeight.SelectedItem;
            mapSize.Width = (int)toolTileMapWidth.SelectedItem;
            mapSize.Height = (int)toolTileMapHeight.SelectedItem;

            levelObjects.Clear();
            lstObjects.Items.Clear();
            lstWaypoints.Items.Clear();

            Tile temp = new Tile(0, 0);
            temp.TileID = 0;
            temp.CollisionID = 0;
            temp.EventID = "none";
            for (int x = 0; x < mapSize.Width; ++x)
            {
                for (int y = 0; y < mapSize.Height; ++y)
                {
                    map[x, y] = temp;
                }
            }
        }
Пример #4
0
        private void toolTileMapWidth_TextChanged(object sender, EventArgs e)
        {
            toolTileMapWidth.SelectionStart = toolTileMapWidth.Text.Length;
            toolTileMapWidth.SelectionLength = 0;
            if (toolTileMapWidth.FindStringExact(toolTileMapWidth.Text) >= 0)
                toolTileMapWidth.SelectedIndex = toolTileMapWidth.FindStringExact(toolTileMapWidth.Text);
            else
            {
                toolTileMapWidth.SelectedIndex = 199;
                toolTileMapWidth.SelectionStart = 0;
                toolTileMapWidth.SelectionLength = toolTileMapWidth.Text.Length;
            }
            int smallX;
            Tile[,] newMap = new Tile[(int)toolTileMapWidth.SelectedItem, mapSize.Height];
            Tile temp = new Tile(0, 0);
            temp.EventID = "none";
            for (int x = 0; x < (int)toolTileMapWidth.SelectedItem; ++x)
            {
                for (int y = 0; y < mapSize.Height; ++y)
                {
                    newMap[x, y] = temp;
                }
            }

            if (mapSize.Width < (int)toolTileMapWidth.SelectedItem)
                smallX = mapSize.Width;
            else
                smallX = (int)toolTileMapWidth.SelectedItem;
            for (int x = 0; x < smallX; ++x)
            {
                for (int y = 0; y < mapSize.Height; ++y)
                {
                    newMap[x, y] = map[x, y];
                }
            }
            mapSize.Width = (int)toolTileMapWidth.SelectedItem;
            map = new Tile[mapSize.Width, mapSize.Height];
            map = newMap;

            Size autoScroll = new Size(0, 0);
            autoScroll.Width = mapSize.Width * tileSize.Width;
            autoScroll.Height = mapSize.Height * tileSize.Height;
            pnlTileMap.AutoScrollMinSize = autoScroll;
            if (over != null)
                over.Render();
        }