Ejemplo n.º 1
0
        public void AddTiles(string folderName)
        {   // add tiles to tile library
            ArrayList tilesArrayList = new ArrayList();

            Cursor.Current = Cursors.WaitCursor;

            if (!Directory.Exists(folderName))
                throw new DirectoryNotFoundException();

            foreach (string f in Directory.GetFiles(folderName))
            {   // load tiles
                if (Path.GetExtension(f) == ".bmp" ||
                    Path.GetExtension(f) == ".png" ||
                    Path.GetExtension(f) == ".jpg" ||
                    Path.GetExtension(f) == ".jpeg")
                    tilesArrayList.Add(f.ToString());
            }

            // delete all controls
            pnlTileLibrary.Controls.Clear();
            pnlTileLibrary.Refresh();

            int t = 0;

            // resize _tile_library
            if (tile_library != null && tile_library.Length > 0)
            {   // add to the library
                t = tile_library.Length;
                Array.Resize(ref tile_library, tilesArrayList.Count + tile_library.Length);
            }
            else
            {   // load new library
                Array.Resize(ref tile_library, tilesArrayList.Count);
            }

            foreach (string i in tilesArrayList)
            {   // update tiles library
                Model.Tile newTile = new Model.Tile();
                PictureBox pB = new PictureBox();
                pB.Left = 20;
                pB.Top = (t * (tile_height + 5)) + 20;
                pB.Width = tile_width;
                pB.Height = tile_height;
                pB.Name = t.ToString();
                pB.Load(i);
                newTile.TileID = t;
                newTile.TileName = t.ToString();
                newTile.TilePictureBox = pB;
                tile_library[t] = newTile;
                pB.MouseClick += new MouseEventHandler(tilePicBox_MouseClick);

                t++;
            }

            RenderTiles();

            Cursor.Current = Cursors.Default;
        }
Ejemplo n.º 2
0
        public void setCodesGenerator(int[,] map, string map_name, int map_width, int map_height,
            Tile[] tile_library, int tile_width, int tile_height,
            System.Windows.Forms.TextBox tbCode,
            Player player, List<Monster> monsters, List<CoinGift> coins, List<BulletGift> bullets, List<Bomb> bombs)
        {
            this.map = map;
            this.map_name = map_name;
            this.map_height = map_height;
            this.map_width = map_width;

            this.tile_library = tile_library;
            this.tile_height = tile_height;
            this.tile_width = tile_width;

            this.tbCode = tbCode;

            this.player = player;
            this.monsters = monsters;
            this.coins = coins;
            this.bullets = bullets;
            this.bombs = bombs;
        }
Ejemplo n.º 3
0
        private void mapPicBox_MouseDown(object sender, MouseEventArgs e)
        {   // mouse click over map
            Point myMouse  = PointToClient(MousePosition);
            int   clickedX = myMouse.X - pnlDesign.Location.X - pbMap.Location.X + pnlDesign.AutoScrollPosition.X - 8;
            int   clickedY = myMouse.Y - pnlDesign.Location.Y - pbMap.Location.Y + pnlDesign.AutoScrollPosition.Y - 26;

            int mapX = clickedX / tile_width;
            int mapY = clickedY / tile_height;

            if (mapX < 0 || mapY < 0 || mapX >= map_width || mapY >= map_height)
            {
                return;
            }

            this.lblMapCoordinate.Text = "Map Coordinate: " + mapX + ", " + mapY;
            this.lblMouse.Text         = "Mouse Position: " + clickedX + ", " + clickedY;

            if (e.Button == MouseButtons.Left)
            {
                if (selected_tool == ToolType.selection)
                {   // selection tool
                    selection            = new Controller.SelectionTool();
                    selection.IsDragging = true;
                    selection.StartDrag  = new Point(mapX, mapY);
                    selection.StopDrag   = new Point(mapX, mapY);
                }
                else if (selected_tool == ToolType.brush)
                {   // brush tool
                    if (pnlTileLibrary.Controls.ContainsKey(pbSelectedTile.Name) == true)
                    {
                        if (map[mapX, mapY] != Convert.ToInt32(pbSelectedTile.Name))
                        {
                            redo.Clear();

                            int id = 0;
                            if (undo.Count > 0)
                            {
                                id = undo.Peek().Id + 1;
                            }

                            undo.Push(new Model.HistoryNode(id, mapX, mapY, map[mapX, mapY]));
                            map[mapX, mapY] = Convert.ToInt32(pbSelectedTile.Name);
                        }
                    }
                }
                else if (selected_tool == ToolType.fill)
                {   // fill tool
                    if (pnlTileLibrary.Controls.ContainsKey(pbSelectedTile.Name) == true)
                    {
                        if (mapX >= selection.TopLeftX && mapX < selection.BottomRightX && mapY >= selection.TopLeftY && mapY < selection.BottomRightY)
                        {
                            redo.Clear();

                            int id = 0;
                            if (undo.Count > 0)
                            {
                                id = undo.Peek().Id + 1;
                            }

                            if (selection.BottomRightX > map_width)
                            {
                                selection.BottomRightX = map_width;
                            }
                            if (selection.BottomRightY > map_height)
                            {
                                selection.BottomRightY = map_height;
                            }

                            for (int i = selection.TopLeftX; i < selection.BottomRightX; i++)
                            {   // fill selected tiles
                                for (int j = selection.TopLeftY; j < selection.BottomRightY; j++)
                                {
                                    undo.Push(new Model.HistoryNode(id, i, j, map[i, j]));
                                    map[i, j] = Convert.ToInt32(pbSelectedTile.Name);
                                }
                            }
                        }
                    }
                }
                else if (selected_tool == ToolType.selectTile)
                {   // select color tool
                    if (map[mapX, mapY] > -1)
                    {
                        Model.Tile selectedTile = tile_library[map[mapX, mapY]];

                        selected_tile            = selectedTile.TilePictureBox;
                        lblTileIDValue.Text      = selected_tile.Name;
                        tbTileName.Text          = selectedTile.TileName;
                        cbTileWalkable.Checked   = selectedTile.TileWalkable;
                        pbSelectedTile.Image     = selected_tile.Image;
                        pbSelectedTile.Name      = selected_tile.Name;
                        gbTileProperties.Enabled = true;
                    }
                    else
                    {
                        ClearSelectedTile();
                    }
                }
                else if (selected_tool == ToolType.eraser)
                {     // eraser tool
                    if (selection.StartDrag.X != -1 && selection.StartDrag.Y != -1 && selection.StopDrag.X != -1 && selection.StopDrag.Y != -1)
                    { // selection was made
                        if (mapX >= selection.TopLeftX && mapX < selection.BottomRightX && mapY >= selection.TopLeftY && mapY < selection.BottomRightY)
                        {
                            // is in selection
                        }
                        else
                        {
                            return;
                        }
                    }

                    if (map[mapX, mapY] != -1)
                    {
                        redo.Clear();

                        int id = 0;
                        if (undo.Count > 0)
                        {
                            id = undo.Peek().Id + 1;
                        }

                        undo.Push(new Model.HistoryNode(id, mapX, mapY, map[mapX, mapY]));
                        map[mapX, mapY] = -1;
                    }
                }

                RenderMap();

                if (choosingPlayer)
                {
                    player.StartPoint = new Point(mapX, mapY);
                    choosingPlayer    = false;
                    MessageBox.Show("Player Start Point x: " + player.StartPoint.X + ", y: " + player.StartPoint.Y);
                    return;
                }

                if (choosingMonster)
                {
                    int index = monsters.Count - 1;
                    if (monsters[index].Start)
                    {
                        monsters[index].StartPoint = new Point(mapX, mapY);
                        monsters[index].Start      = false;
                        monsters[index].End        = true;
                        return;
                    }
                    if (monsters[index].End)
                    {
                        monsters[index].EndPoint = new Point(mapX, mapY);
                        monsters[index].End      = false;
                        choosingMonster          = false;
                        MessageBox.Show("Monster " + (index + 1) + " Start Point x: " + monsters[index].StartPoint.X + ", y: " + monsters[index].StartPoint.Y + "\n" +
                                        "Monster " + (index + 1) + " End Point x: " + monsters[index].EndPoint.X + ", y: " + monsters[index].EndPoint.Y);
                        return;
                    }
                }

                if (choosingBomb)
                {
                    bombs[bombs.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingBomb = false;
                    MessageBox.Show("Bomb " + bombs.Count + " Point x: " + bombs[bombs.Count - 1].StartPoint.X + ", y: " + bombs[bombs.Count - 1].StartPoint.Y);
                    return;
                }

                if (choosingCoin)
                {
                    coins[coins.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingCoin = false;
                    MessageBox.Show("Coin " + coins.Count + " Point x: " + coins[coins.Count - 1].StartPoint.X + ", y: " + coins[coins.Count - 1].StartPoint.Y);
                    return;
                }

                if (choosingBullet)
                {
                    bullets[bullets.Count - 1].StartPoint = new Point(mapX, mapY);
                    choosingBullet = false;
                    MessageBox.Show("Bullet " + bullets.Count + " Point x: " + bullets[bullets.Count - 1].StartPoint.X + ", y: " + bullets[bullets.Count - 1].StartPoint.Y);
                    return;
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                selection = new Controller.SelectionTool();
                RenderMap();
            }

            if (undo.Count > 0)
            {
                undoToolStripMenuItem.Enabled = true;
            }
            else
            {
                undoToolStripMenuItem.Enabled = false;
            }
        }
Ejemplo n.º 4
0
        public void LoadTiles(string fileName)
        {   // load tiles from the saved tile library
            // clear tile library
            if (tile_library != null)
                Array.Clear(tile_library, 0, tile_library.Length);

            // load tiles
            ///////////////
            string pbDirName = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName);

            ArrayList tilesArrayList = new ArrayList();

            // delete all controls
            pnlTileLibrary.Controls.Clear();
            pnlTileLibrary.Refresh();

            if (Directory.Exists(pbDirName))
            {
                foreach (string f in Directory.GetFiles(pbDirName))
                {   // load tiles
                    if (Path.GetExtension(f) == ".bmp" ||
                        Path.GetExtension(f) == ".png" ||
                        Path.GetExtension(f) == ".jpg" ||
                        Path.GetExtension(f) == ".jpeg")
                        tilesArrayList.Add(f.ToString());
                }

                int t = 0;

                // resize _tile_library
                Array.Resize(ref tile_library, tilesArrayList.Count);

                foreach (string i in tilesArrayList)
                {   // update tiles library
                    Model.Tile newTile = new Model.Tile();
                    PictureBox pB = new PictureBox();
                    pB.Left = 20;
                    pB.Top = (t * (tile_height + 5)) + 20;
                    pB.Width = tile_width;
                    pB.Height = tile_height;
                    pB.Name = t.ToString();
                    pB.Load(i);
                    newTile.TileID = t;
                    newTile.TileName = t.ToString();
                    newTile.TilePictureBox = pB;
                    tile_library[t] = newTile;
                    pB.MouseClick += new MouseEventHandler(tilePicBox_MouseClick);

                    t++;
                }
            }
            else
            {
                MessageBox.Show(pbDirName + " doesn't exist! This folder is needed for the Tiles Library.", "Cannot Find Folder", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            string tileLibraryFileName = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "-tile.xml";
            FileStream tfs = new FileStream(tileLibraryFileName, FileMode.Open);
            XmlDocument textReader = new XmlDocument();
            textReader.Load(tfs);

            XmlNodeList tileList = textReader.GetElementsByTagName("Tile");

            foreach (XmlNode node in tileList)
            {
                XmlElement tileElement = (XmlElement)node;

                int tileID = Convert.ToInt32(tileElement.Attributes["ID"].InnerText);

                tile_library[tileID].TileName = tileElement.GetElementsByTagName("Name")[0].InnerText;
                tile_library[tileID].TileWidth = Convert.ToInt32(tileElement.GetElementsByTagName("Width")[0].InnerText);
                tile_library[tileID].TileHeight = Convert.ToInt32(tileElement.GetElementsByTagName("Height")[0].InnerText);
                tile_library[tileID].TileWalkable = Convert.ToBoolean(tileElement.GetElementsByTagName("Walkable")[0].InnerText);
            }

            tfs.Close();
        }
Ejemplo n.º 5
0
        public void AddTiles(string folderName)
        {   // add tiles to tile library
            ArrayList tilesArrayList = new ArrayList();

            Cursor.Current = Cursors.WaitCursor;

            if (!Directory.Exists(folderName))
            {
                throw new DirectoryNotFoundException();
            }

            foreach (string f in Directory.GetFiles(folderName))
            {   // load tiles
                if (Path.GetExtension(f) == ".bmp" ||
                    Path.GetExtension(f) == ".png" ||
                    Path.GetExtension(f) == ".jpg" ||
                    Path.GetExtension(f) == ".jpeg")
                {
                    tilesArrayList.Add(f.ToString());
                }
            }

            // delete all controls
            pnlTileLibrary.Controls.Clear();
            pnlTileLibrary.Refresh();

            int t = 0;

            // resize _tile_library
            if (tile_library != null && tile_library.Length > 0)
            {   // add to the library
                t = tile_library.Length;
                Array.Resize(ref tile_library, tilesArrayList.Count + tile_library.Length);
            }
            else
            {   // load new library
                Array.Resize(ref tile_library, tilesArrayList.Count);
            }

            foreach (string i in tilesArrayList)
            {   // update tiles library
                Model.Tile newTile = new Model.Tile();
                PictureBox pB      = new PictureBox();
                pB.Left   = 20;
                pB.Top    = (t * (tile_height + 5)) + 20;
                pB.Width  = tile_width;
                pB.Height = tile_height;
                pB.Name   = t.ToString();
                pB.Load(i);
                newTile.TileID         = t;
                newTile.TileName       = t.ToString();
                newTile.TilePictureBox = pB;
                tile_library[t]        = newTile;
                pB.MouseClick         += new MouseEventHandler(tilePicBox_MouseClick);

                t++;
            }

            RenderTiles();

            Cursor.Current = Cursors.Default;
        }
Ejemplo n.º 6
0
        public void LoadTiles(string fileName)
        {   // load tiles from the saved tile library
            // clear tile library
            if (tile_library != null)
            {
                Array.Clear(tile_library, 0, tile_library.Length);
            }

            // load tiles
            ///////////////
            string pbDirName = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName);

            ArrayList tilesArrayList = new ArrayList();

            // delete all controls
            pnlTileLibrary.Controls.Clear();
            pnlTileLibrary.Refresh();

            if (Directory.Exists(pbDirName))
            {
                foreach (string f in Directory.GetFiles(pbDirName))
                {   // load tiles
                    if (Path.GetExtension(f) == ".bmp" ||
                        Path.GetExtension(f) == ".png" ||
                        Path.GetExtension(f) == ".jpg" ||
                        Path.GetExtension(f) == ".jpeg")
                    {
                        tilesArrayList.Add(f.ToString());
                    }
                }

                int t = 0;

                // resize _tile_library
                Array.Resize(ref tile_library, tilesArrayList.Count);

                foreach (string i in tilesArrayList)
                {   // update tiles library
                    Model.Tile newTile = new Model.Tile();
                    PictureBox pB      = new PictureBox();
                    pB.Left   = 20;
                    pB.Top    = (t * (tile_height + 5)) + 20;
                    pB.Width  = tile_width;
                    pB.Height = tile_height;
                    pB.Name   = t.ToString();
                    pB.Load(i);
                    newTile.TileID         = t;
                    newTile.TileName       = t.ToString();
                    newTile.TilePictureBox = pB;
                    tile_library[t]        = newTile;
                    pB.MouseClick         += new MouseEventHandler(tilePicBox_MouseClick);

                    t++;
                }
            }
            else
            {
                MessageBox.Show(pbDirName + " doesn't exist! This folder is needed for the Tiles Library.", "Cannot Find Folder", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            string      tileLibraryFileName = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + "-tile.xml";
            FileStream  tfs        = new FileStream(tileLibraryFileName, FileMode.Open);
            XmlDocument textReader = new XmlDocument();

            textReader.Load(tfs);

            XmlNodeList tileList = textReader.GetElementsByTagName("Tile");

            foreach (XmlNode node in tileList)
            {
                XmlElement tileElement = (XmlElement)node;

                int tileID = Convert.ToInt32(tileElement.Attributes["ID"].InnerText);

                tile_library[tileID].TileName     = tileElement.GetElementsByTagName("Name")[0].InnerText;
                tile_library[tileID].TileWidth    = Convert.ToInt32(tileElement.GetElementsByTagName("Width")[0].InnerText);
                tile_library[tileID].TileHeight   = Convert.ToInt32(tileElement.GetElementsByTagName("Height")[0].InnerText);
                tile_library[tileID].TileWalkable = Convert.ToBoolean(tileElement.GetElementsByTagName("Walkable")[0].InnerText);
            }

            tfs.Close();
        }