コード例 #1
0
        void newLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewLayer frmNewLayer = new FormNewLayer(levelData.MapWidth, levelData.MapHeight))
            {
                frmNewLayer.ShowDialog();

                if (frmNewLayer.OKPressed)
                {
                    MapLayerData data = frmNewLayer.MapLayerData;
                    if (clbLayers.Items.Contains(data.MapLayerName))
                    {
                        MessageBox.Show("Layer with name " + data.MapLayerName + " exists.", "Existing layer");
                        return;
                    }

                    MapLayer layer = MapLayer.FromMapLayerData(data);

                    clbLayers.Items.Add(data.MapLayerName, true);
                    clbLayers.SelectedIndex = clbLayers.Items.Count - 1;
                    layers.Add(layer);

                    if (map == null)
                    {
                        map = new TileMap(tileSets, layers);
                    }

                    charactersToolStripMenuItem.Enabled = true;
                    chestsToolStripMenuItem.Enabled     = true;
                    keysToolStripMenuItem.Enabled       = true;
                }
            }
        }
コード例 #2
0
ファイル: DataManager.cs プロジェクト: Metasynic/PkmnEngine
        /* This is the more complex data reader. It reads in the levels from the LevelData and MapData objects in the content. */
        public static void ReadLevelData(ContentManager Content)
        {
            /* It starts off the same way as all the other data readers, collecting a list of filenames and loading the content into temporary variables. */
            string[] filenames = Directory.GetFiles(@"Content/GameData/LevelData", "*.xnb");
            foreach (string filename in filenames)
            {
                string    name        = @"GameData/LevelData/" + Path.GetFileNameWithoutExtension(filename);
                LevelData lvlData     = Content.Load <LevelData>(name);
                string    mapfilename = @"GameData/LevelData/MapData/" + lvlData.MapName;
                MapData   mapData     = Content.Load <MapData>(mapfilename);

                /* This part is where things get interesting. For each level, a new list of Tilesets is created.
                 * Each tileset image in the level is then loaded from the "Tilesets" folder.
                 * A new Tileset object is made using the image and information in the TilesetData objects in the MapData.
                 * Each Tileset is added to the list of Tilesets. */
                List <Tileset> tilesets = new List <Tileset>();
                foreach (TilesetData data in mapData.Tilesets)
                {
                    Texture2D image = Content.Load <Texture2D>(@"Tilesets/" + Path.GetFileNameWithoutExtension(data.TilesetImageName));
                    Tileset   t     = new Tileset(image, data.TilesWide, data.TilesHigh, data.TileWidthInPixels, data.TileHeightInPixels);
                    tilesets.Add(t);
                }

                /* The same happens with the list of MapLayers in the Level.
                 * It's somewhat neater here since the MapLayer class has a function to parse a MapLayer from a MapLayerData. */
                List <MapLayer> layers = new List <MapLayer>();
                foreach (MapLayerData data in mapData.Layers)
                {
                    layers.Add(MapLayer.FromMapLayerData(data));
                }

                /* Next, a new TileMap object is created for the Level, and the tilesets and layers are added to it. */
                TileMap map = new TileMap(tilesets[0], null, layers[0]);
                if (tilesets.Count > 1)
                {
                    for (int i = 1; i < tilesets.Count; i++)
                    {
                        map.AddTileset(tilesets[i]);
                    }
                }
                if (layers.Count > 1)
                {
                    for (int i = 1; i < layers.Count; i++)
                    {
                        map.AddLayer(layers[i]);
                    }
                }

                /* Finally, the Level object is initialized and added to the dictionary. */
                Level level = new Level(map, lvlData.LevelName);
                levels.Add(level.LevelName, level);
            }

            ((MapLayer)(levels["Level 1"].Map.MapLayers[0])).SetTile(18, 1, new WarpTile(((MapLayer)(levels["Level 1"].Map.MapLayers[0])).GetTile(18, 1).TileIndex, ((MapLayer)(levels["Level 1"].Map.MapLayers[0])).GetTile(18, 1).Tileset, "Level 2", 1, 1));
            ((MapLayer)(levels["Level 2"].Map.MapLayers[0])).SetTile(2, 1, new WarpTile(((MapLayer)(levels["Level 2"].Map.MapLayers[0])).GetTile(2, 1).TileIndex, ((MapLayer)(levels["Level 2"].Map.MapLayers[0])).GetTile(2, 1).Tileset, "Level 3", 1, 1));
            ((MapLayer)(levels["Level 3"].Map.MapLayers[0])).SetTile(5, 1, new WarpTile(((MapLayer)(levels["Level 3"].Map.MapLayers[0])).GetTile(5, 1).TileIndex, ((MapLayer)(levels["Level 3"].Map.MapLayers[0])).GetTile(5, 1).Tileset, "Level 1", 1, 1));
        }
コード例 #3
0
        private void LoadIsoTileMap()
        {
            List <Tileset>  tileSets  = new List <Tileset>();
            List <MapLayer> mapLayers = new List <MapLayer>();

            engine = new Engine(64, 32);

            foreach (TilesetData data in newMap.Tilesets)
            {
                Texture2D tilesetTexture = null;
                int       pos            = data.TilesetImageName.IndexOf("TileSets\\");
                //if (pos == -1)
                //{
                //    //tilesetTexture = Game.Content.Load<Texture2D>(@data.TilesetImageName);

                //}
                //else
                //{
                int lenght = data.TilesetImageName.Length - 4 - pos;

                tilesetTexture = Game.Content.Load <Texture2D>(@data.TilesetImageName.Substring(pos, lenght).Trim());
                //}



                //using (Stream stream = new FileStream(data.TilesetImageName, FileMode.Open, FileAccess.Read))
                //{
                //    texture = Texture2D.FromStream(GraphicsDevice, stream);
                tileSets.Add(
                    new Tileset(
                        tilesetTexture,
                        data.TilesWide,
                        data.TilesHigh,
                        data.TileWidthInPixels,
                        data.TileHeightInPixels));
                //}
            }

            foreach (MapLayerData data in newMap.Layers)
            {
                mapLayers.Add(MapLayer.FromMapLayerData(data));
            }

            map = new TileMapIso(tileSets[0], (MapLayer)mapLayers[0]);

            for (int i = 1; i < tileSets.Count; i++)
            {
                map.AddTileset(tileSets[i]);
            }

            for (int i = 1; i < mapLayers.Count; i++)
            {
                map.AddLayer(mapLayers[i]);
            }
        }
コード例 #4
0
        void newLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewLayer frmNewLayer = new FormNewLayer(levelData.MapWidth,
                                                               levelData.MapHeight))
            {
                frmNewLayer.ShowDialog();

                if (frmNewLayer.OKPressed)
                {
                    MapLayerData data = frmNewLayer.MapLayerData;

                    if (clbLayers.Items.Contains(data.MapLayerName))
                    {
                        MessageBox.Show("Layer with name " + data.MapLayerName + " exists.",
                                        "Existing layer");
                        return;
                    }

                    MapLayer layer = MapLayer.FromMapLayerData(data);

                    clbLayers.Items.Add(data.MapLayerName, true);
                    clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

                    layers.Add(layer);

                    if (map == null)
                    {
                        map = new TileMap(tileSets[0], animatedSet, (MapLayer)layers[0]);

                        for (int i = 1; i < tileSets.Count; i++)
                        {
                            map.AddTileset(tileSets[1]);
                        }

                        for (int i = 1; i < layers.Count; i++)
                        {
                            map.AddLayer(layers[1]);
                        }
                    }

                    charactersToolStripMenuItem.Enabled = true;
                    chestsToolStripMenuItem.Enabled     = true;
                    keysToolStripMenuItem.Enabled       = true;

                    if (animatedSet != null)
                    {
                        chkPaintAnimated.Enabled = true;
                    }

                    chkPaintCollision.Enabled = true;
                }
            }
        }
コード例 #5
0
ファイル: FormMain.cs プロジェクト: AlanWills/Mythology
        void openLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();

            ofDialog.Filter          = "Map Layer Data (*.mldt)|*.mldt";
            ofDialog.CheckPathExists = true;
            ofDialog.CheckFileExists = true;

            DialogResult result = ofDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            MapLayerData data = null;

            try
            {
                data = XnaSerializer.Deserialize <MapLayerData>(ofDialog.FileName);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error reading map layer");
                return;
            }

            for (int i = 0; i < clbLayers.Items.Count; i++)
            {
                if (clbLayers.Items[i].ToString() == data.MapLayerName)
                {
                    MessageBox.Show("Layer by that name already exists.", "Existing layer");
                    return;
                }
            }

            clbLayers.Items.Add(data.MapLayerName, true);

            layers.Add(MapLayer.FromMapLayerData(data));

            if (map == null)
            {
                map = new TileMap(tileSets[0], (MapLayer)layers[0]);

                for (int i = 0; i < tileSets.Count; i++)
                {
                    map.AddTileset(tileSets[i]);
                }
            }
        }
コード例 #6
0
        private void LoudDefaultLayers()
        {
            MapLayerData mapLayerData1 = new MapLayerData("Water", mData.MapWidth, mData.MapHeight, 0, 0, 6);

            MapLayer layer = MapLayer.FromMapLayerData(mapLayerData1);

            clbLayers.Items.Add(mapLayerData1.MapLayerName, true);
            clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

            layers.Add(layer);

            MapLayerData mapLayerData2 = new MapLayerData("Level 1", mData.MapWidth, mData.MapHeight, 1, -1, -1);

            layer = MapLayer.FromMapLayerData(mapLayerData2);
            clbLayers.Items.Add(mapLayerData2.MapLayerName, true);
            clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

            layers.Add(layer);

            MapLayerData mapLayerData3 = new MapLayerData("Level 2", mData.MapWidth, mData.MapHeight, 2, -1, -1);

            layer = MapLayer.FromMapLayerData(mapLayerData3);
            clbLayers.Items.Add(mapLayerData3.MapLayerName, true);
            clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

            layers.Add(layer);
            if (map == null)
            {
                map = new TileMapIso(tileSets[0], (MapLayer)layers[0]);

                for (int i = 1; i < tileSets.Count; i++)
                {
                    map.AddTileset(tileSets[1]);
                }

                for (int i = 1; i < layers.Count; i++)
                {
                    map.AddLayer(layers[1]);
                }
            }
        }
コード例 #7
0
        void newLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewLayer frmNewLayer = new FormNewLayer(mData.MapWidth, mData.MapHeight))
            {
                frmNewLayer.ShowDialog();

                if (frmNewLayer.OKPressed)
                {
                    MapLayerData data = frmNewLayer.MapLayerData;

                    if (clbLayers.Items.Contains(data.MapLayerName))
                    {
                        MessageBox.Show("Layer with name " + data.MapLayerName + " exists.", "Existing layer");
                        return;
                    }

                    MapLayer layer = MapLayer.FromMapLayerData(data);
                    clbLayers.Items.Add(data.MapLayerName, true);
                    clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

                    layers.Add(layer);

                    if (map == null)
                    {
                        map = new TileMapIso(tileSets[0], (MapLayer)layers[0]);

                        for (int i = 1; i < tileSets.Count; i++)
                        {
                            map.AddTileset(tileSets[1]);
                        }

                        for (int i = 1; i < layers.Count; i++)
                        {
                            map.AddLayer(layers[1]);
                        }
                    }
                }
            }
        }
コード例 #8
0
ファイル: FormMain.cs プロジェクト: AlanWills/Mythology
        void openLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();

            ofDialog.Filter          = "Level Files (*.xml)|*.xml";
            ofDialog.CheckFileExists = true;
            ofDialog.CheckPathExists = true;

            DialogResult result = ofDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            string path = Path.GetDirectoryName(ofDialog.FileName);

            LevelData newLevel = null;
            MapData   mapData  = null;

            try
            {
                newLevel = XnaSerializer.Deserialize <LevelData>(ofDialog.FileName);
                mapData  = XnaSerializer.Deserialize <MapData>(path + @"\Maps\" + newLevel.MapName + ".xml");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error reading level");
                return;
            }

            tileSetImages.Clear();
            tileSetData.Clear();
            tileSets.Clear();
            layers.Clear();
            lbTileset.Items.Clear();
            clbLayers.Items.Clear();

            levelData = newLevel;

            foreach (TilesetData data in mapData.Tilesets)
            {
                Texture2D texture = null;

                tileSetData.Add(data);
                lbTileset.Items.Add(data.TilesetName);

                GDIImage image = (GDIImage)GDIBitmap.FromFile(data.TilesetImageName);
                tileSetImages.Add(image);

                using (Stream stream = new FileStream(data.TilesetImageName, FileMode.Open, FileAccess.Read))
                {
                    texture = Texture2D.FromStream(GraphicsDevice, stream);
                    tileSets.Add(
                        new Tileset(
                            texture,
                            data.TilesWide,
                            data.TilesHigh,
                            data.TileWidthInPixels,
                            data.TileHeightInPixels));
                }
            }

            foreach (MapLayerData data in mapData.Layers)
            {
                clbLayers.Items.Add(data.MapLayerName, true);
                layers.Add(MapLayer.FromMapLayerData(data));
            }

            lbTileset.SelectedIndex = 0;
            clbLayers.SelectedIndex = 0;
            nudCurrentTile.Value    = 0;

            map = new TileMap(tileSets[0], (MapLayer)layers[0]);

            for (int i = 1; i < tileSets.Count; i++)
            {
                map.AddTileset(tileSets[i]);
            }

            for (int i = 1; i < layers.Count; i++)
            {
                map.AddLayer(layers[i]);
            }

            tilesetToolStripMenuItem.Enabled    = true;
            mapLayerToolStripMenuItem.Enabled   = true;
            charactersToolStripMenuItem.Enabled = true;
            chestsToolStripMenuItem.Enabled     = true;
            keysToolStripMenuItem.Enabled       = true;
        }
コード例 #9
0
        void openMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();

            ofDialog.Filter          = "Level Files (*.xml)|*.xml";
            ofDialog.CheckFileExists = true;
            ofDialog.CheckPathExists = true;

            DialogResult result = ofDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            string path = Path.GetDirectoryName(ofDialog.FileName);

            MapData mapData = null;

            try
            {
                mapData = XnaSerializer.Deserialize <MapData>(ofDialog.FileName);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error reading level");
                return;
            }

            tileSetImages.Clear();
            tileSetData.Clear();
            tileSets.Clear();
            layers.Clear();
            lbTileset.Items.Clear();
            clbLayers.Items.Clear();

            mData = new MapData(mapData.MapName, mapData.MapWidth, mapData.MapHeight);

            string directory = System.IO.Directory.GetCurrentDirectory();
            int    pos       = directory.IndexOf("ZombocalypseRevised\\") + 20;

            directory = directory.Substring(0, pos).Trim() + "ZombocalypseRevised\\ZombocalypseRevisedContent\\";

            foreach (TilesetData data in mapData.Tilesets)
            {
                Texture2D texture = null;

                tileSetData.Add(data);

                int    posLoadLoc        = data.TilesetImageName.IndexOf("TileSets\\");
                int    lenghtFull        = data.TilesetImageName.Length - posLoadLoc;
                string fileDirectoryFull = directory + data.TilesetImageName.Substring(posLoadLoc, lenghtFull).Trim();
                lbTileset.Items.Add(data.TilesetName);

                GDIImage image = (GDIImage)GDIBitmap.FromFile(fileDirectoryFull);
                tileSetImages.Add(image);

                using (Stream stream = new FileStream(fileDirectoryFull, FileMode.Open, FileAccess.Read))
                {
                    texture = Texture2D.FromStream(GraphicsDevice, stream);
                    tileSets.Add(
                        new Tileset(
                            texture,
                            data.TilesWide,
                            data.TilesHigh,
                            data.TileWidthInPixels,
                            data.TileHeightInPixels));
                }
            }

            foreach (MapLayerData data in mapData.Layers)
            {
                clbLayers.Items.Add(data.MapLayerName, true);
                layers.Add(MapLayer.FromMapLayerData(data));
            }

            lbTileset.SelectedIndex = 0;
            clbLayers.SelectedIndex = 0;
            nudCurrentTile.Value    = 0;

            map = new TileMapIso(tileSets[0], (MapLayer)layers[0]);

            for (int i = 1; i < tileSets.Count; i++)
            {
                map.AddTileset(tileSets[i]);
            }

            for (int i = 1; i < layers.Count; i++)
            {
                map.AddLayer(layers[i]);
            }

            tilesetToolStripMenuItem.Enabled  = true;
            mapLayerToolStripMenuItem.Enabled = true;
        }
コード例 #10
0
        void openLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();

            ofDialog.Filter          = "Level Files (*.xml)|*.xml";
            ofDialog.CheckFileExists = true;
            ofDialog.CheckPathExists = true;

            DialogResult result = ofDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            string path = Path.GetDirectoryName(ofDialog.FileName);

            LevelData          newLevel = null;
            MapData            mapData  = null;
            CharacterLayerData charData = null;

            try
            {
                newLevel = XnaSerializer.Deserialize <LevelData>(ofDialog.FileName);
                mapData  = XnaSerializer.Deserialize <MapData>(path + @"\Maps\" + newLevel.MapName +
                                                               ".xml");
                charData = XnaSerializer.Deserialize <CharacterLayerData>(path + @"\Chars\" + newLevel.LevelName + ".xml");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error reading level");
                return;
            }

            tileSetImages.Clear();
            tileSetData.Clear();
            tileSets.Clear();

            layers.Clear();

            lbTileset.Items.Clear();
            clbLayers.Items.Clear();

            collisionLayer.Collisions.Clear();
            animatedLayer.AnimatedTiles.Clear();
            characters.Characters.Clear();

            levelData = newLevel;

            foreach (TilesetData data in mapData.Tilesets)
            {
                Texture2D texture = null;

                tileSetData.Add(data);
                lbTileset.Items.Add(data.TilesetName);

                GDIImage image = (GDIImage)GDIBitmap.FromFile(data.TilesetImageName);
                tileSetImages.Add(image);
                using (Stream stream = new FileStream(data.TilesetImageName, FileMode.Open,
                                                      FileAccess.Read))
                {
                    texture = Texture2D.FromStream(GraphicsDevice, stream);

                    tileSets.Add(
                        new Tileset(
                            texture,
                            data.TilesWide,
                            data.TilesHigh,
                            data.TileWidthInPixels,
                            data.TileHeightInPixels));
                }
            }

            using (Stream textureStream = new FileStream(mapData.AnimatedTileset.TilesetImageName,
                                                         FileMode.Open, FileAccess.Read))
            {
                Texture2D aniamtedTexture = Texture2D.FromStream(GraphicsDevice, textureStream);

                animatedSet = new AnimatedTileset(
                    aniamtedTexture,
                    mapData.AnimatedTileset.FramesAcross,
                    mapData.AnimatedTileset.TilesHigh,
                    mapData.AnimatedTileset.TileWidthInPixels,
                    mapData.AnimatedTileset.TileHeightInPixels);
                animatedSetData = mapData.AnimatedTileset;
            }

            foreach (MapLayerData data in mapData.Layers)
            {
                clbLayers.Items.Add(data.MapLayerName, true);
                layers.Add(MapLayer.FromMapLayerData(data));
            }

            lbTileset.SelectedIndex = 0;
            clbLayers.SelectedIndex = 0;
            nudCurrentTile.Value    = 0;
            sbAnimatedTile.Maximum  = 0;

            map = new TileMap(tileSets[0], animatedSet, (MapLayer)layers[0]);

            for (int i = 1; i < tileSets.Count; i++)
            {
                map.AddTileset(tileSets[i]);
            }

            for (int i = 1; i < layers.Count; i++)
            {
                map.AddLayer(layers[i]);
            }

            foreach (var collision in mapData.Collisions.Collisions)
            {
                collisionLayer.Collisions.Add(collision.Key, collision.Value);
            }

            foreach (var tile in mapData.AnimatedTiles.AnimatedTiles)
            {
                animatedLayer.AnimatedTiles.Add(tile.Key, tile.Value);
            }

            foreach (var c in charData.Characters)
            {
                Character character;

                if (c.Value is NonPlayerCharacterData)
                {
                    Entity entity = new Entity(c.Value.Name, c.Value.EntityData, c.Value.Gender, EntityType.NPC);

                    using (Stream stream = new FileStream(c.Value.TextureName, FileMode.Open, FileAccess.Read))
                    {
                        Texture2D      texture = Texture2D.FromStream(GraphicsDevice, stream);
                        AnimatedSprite sprite  = new AnimatedSprite(texture, Animations);
                        sprite.Position = new Vector2(c.Key.X * Engine.TileWidth, c.Key.Y * Engine.TileHeight);
                        character       = new NonPlayerCharacter(entity, sprite);

                        ((NonPlayerCharacter)character).SetConversation(
                            ((NonPlayerCharacterData)c.Value).CurrentConversation);

                        characters.Characters.Add(c.Key, character);
                    }
                }
            }
            tilesetToolStripMenuItem.Enabled    = true;
            mapLayerToolStripMenuItem.Enabled   = true;
            charactersToolStripMenuItem.Enabled = true;
            chestsToolStripMenuItem.Enabled     = true;
            keysToolStripMenuItem.Enabled       = true;
        }