示例#1
0
        private TileMap getMap(String mapfile, int playerx, int playery)
        {
            TileMap ret = null;
            if (maps.ContainsKey(mapfile))
            {
                ret = maps[mapfile];
                if(playerx != -1 && playery != -1)
                    ret.setPlayerLocation(ret.getTileAt(playerx, playery));
            }
            else
            {
                FileStream fileStream = new FileStream(@mapfile, FileMode.Open);
                StreamReader reader = new StreamReader(fileStream);
                ret = new TileMap(10, 10, 17, DEFAULT_X_TILES, DEFAULT_Y_TILES, whitepixel, toolmap, font, mapfile);
                ret.LoadMap(reader, mapfile, toolmap);

                if (playerx != -1 && playery != -1)
                ret.setPlayerLocation(ret.getTileAt(playerx, playery));

                maps.Add(mapfile, ret);
                reader.Close();
                fileStream.Close();
            }
            return ret;
        }
示例#2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            whitepixel  = new Texture2D(GraphicsDevice, 1, 1);
            whitepixel.SetData(new Color[] { Color.White });
            astartiles = new List<Tile>();
            astarwaypoint = Content.Load<Texture2D>("AStarWayPoint");
            edited = true;

            font = Content.Load<SpriteFont>("gameFont");
            titlefont = Content.Load<SpriteFont>("titleFont");
            helpText = Content.Load<SpriteFont>("worldText");

            evindicator = Content.Load<Texture2D>("AStarWayPoint");
            cave = Content.Load<Song>("cavemusic");
            town = Content.Load<Song>("Townmusic");
            battle = Content.Load<Song>("battlemusic");
            currSong = town;

            fire = Content.Load<Texture2D>("Tiles/FireBall");
            heal = Content.Load<Texture2D>("Tiles/HealBall");
            sword = Content.Load<Texture2D>("Tiles/SwordAttack1");

            firesound = Content.Load<SoundEffect>("FireballSound");
            healSound = Content.Load<SoundEffect>("Healing");
            swordSound = Content.Load<SoundEffect>("SwordAttack");

            /*tools = new Tool[2][];
            tools[0] = new Tool[4];
            tools[1] = new Tool[4];

            tools[0][0] = new Tool(TileType.GRASS, Content.Load<Texture2D>("Tiles/Grass"), false, 1);
            tools[0][1] = new Tool(TileType.TREES, Content.Load<Texture2D>("Tiles/Trees"), false, 2);
            tools[0][2] = new Tool(TileType.SWAMP, Content.Load<Texture2D>("Tiles/Swamp"), false, 4);
            tools[0][3] = new Tool(TileType.PLAYER, Content.Load<Texture2D>("Tiles/Player"), false, 0);
            tools[1][0] = new Tool(TileType.WATER, Content.Load<Texture2D>("Tiles/Water"), false, 6);
            tools[1][1] = new Tool(TileType.ROCKS, Content.Load<Texture2D>("Tiles/LavaRocks"), false, 8);
            tools[1][2] = new Tool(TileType.WALL, Content.Load<Texture2D>("Tiles/Wall"), true, 0);
            tools[1][3] = new Tool(TileType.MONSTER, Content.Load<Texture2D>("Tiles/Monster"), false, 0);
            */

            System.Collections.ArrayList tiles = new System.Collections.ArrayList();
            foreach (WorldTile t in Enum.GetValues(typeof(WorldTile)))
            {
                tiles.Add(t);

                if(DEBUG)
                Console.WriteLine(t.GetInformation());

                try
                {
                    Texture2D cur = Content.Load<Texture2D>(t.GetTexture());
                    if (cur != null && !texmap.ContainsKey(t.GetTexture()))
                        texmap.Add(t.GetTexture(), cur);
                }
                catch (Microsoft.Xna.Framework.Content.ContentLoadException e)
                {
                }

            }
            worldtiles = tiles.ToArray(typeof(WorldTile)) as WorldTile[];
            Array.Sort(worldtiles, delegate(WorldTile a, WorldTile b)
                                    {
                                        return a.ToString().CompareTo(b.ToString());
                                    });
            if(DEBUG)
            Console.WriteLine(worldtiles.Length);

            //map = new TileMap(10, 10, 17, 512, 512, whitepixel, tools[0][0]);
            toolmap = new ToolMap(578, 100, whitepixel, texmap, worldtiles, font, Window.Handle);
            if (!STARTPLAY)
            {
                toolmap.enable();
            }
            map = new TileMap(10, 10, 17, DEFAULT_X_TILES, DEFAULT_Y_TILES, whitepixel, toolmap, font, FIRSTMAP);
            if (STARTPLAY)
            {
                 FileStream fileStream = new FileStream(@FIRSTMAP, FileMode.Open);
                 StreamReader reader = new StreamReader(fileStream);
                 map.LoadMap(reader, FIRSTMAP, toolmap);
                 maps.Add(FIRSTMAP, map);
                 reader.Close();
                 fileStream.Close();

                 state = GameState.TITLE;
            }
            PlayMusic(Content.Load<Song>("Townmusic"));
            // TODO: use this.Content to load your game content here
        }