Exemple #1
0
        protected override void Initialize()
        {
            _graphics.PreferredBackBufferWidth  = windowWidth;
            _graphics.PreferredBackBufferHeight = windowHeight;
            _graphics.IsFullScreen = false;
            _graphics.ApplyChanges();

            nMap = NewMap.Load(@"..\..\..\MapData\Map2.1.tmx");
            //nMap = NewMap.Load(@"..\..\..\MapData\Map.tmx");
            // map = new Map(@"..\..\..\MapData\Map2.tmx", @"..\..\..\MapData\GrassTileset.tsx", Content);

            allPlayers = new Dictionary <int, Player>();
            player     = new Player(nMap.playerStart, "Conjurer", Content);

            //camera = new Camera(GraphicsDevice.Viewport);

            nCamera        = new NewCamera(GraphicsDevice.Viewport);
            nCamera.Limits = new Rectangle(0, 0, nMap._width * nMap.tileset._tileWidth, nMap._height * nMap.tileset._tileHeight);

            client = new UDPClient();
            if (!client.Connect("79.114.16.172", 5555))
            {
                Console.WriteLine("Cannot connect to server!");

                // Exit();
            }

            player.ID = client.ClientID;
            client.SendMessageExceptOne(player.toPlayerInfo(), player.ID);

            allPlayers.Add(player.ID, player);

            base.Initialize();
        }
Exemple #2
0
        public static NewMap Load(string filename)
        {
            NewMap map = new NewMap();

            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            // <map>
            XmlNode root = doc.SelectSingleNode("map");

            map._width      = int.Parse(root.Attributes["width"].InnerText);
            map._height     = int.Parse(root.Attributes["height"].InnerText);
            map._tileWidth  = int.Parse(root.Attributes["tilewidth"].InnerText);
            map._tileHeight = int.Parse(root.Attributes["tileheight"].InnerText);
            // </map>

            // <tileset>
            XmlNode tilesetInfo = root.SelectSingleNode("tileset");
            string  tilesetPath = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + tilesetInfo.Attributes["source"].InnerText;

            map.tileset = new Tileset(tilesetPath);
            // </tileset>

            // <layer>
            foreach (XmlNode layerNode in root.SelectNodes("layer"))
            {
                NewLayer layer = new NewLayer(
                    layerNode.Attributes["name"].InnerText,
                    int.Parse(layerNode.Attributes["width"].InnerText),
                    int.Parse(layerNode.Attributes["height"].InnerText),
                    layerNode.SelectSingleNode("data").InnerText
                    );

                map.layers.Add(layer);
            }
            // </layer>

            // <start position>
            foreach (XmlNode objectGroup in root.SelectNodes("objectgroup"))
            {
                if (objectGroup.Attributes["name"].InnerText.Equals("Start"))
                {
                    map.playerStart.X = float.Parse(objectGroup["object"].Attributes["x"].InnerText);
                    map.playerStart.Y = float.Parse(objectGroup["object"].Attributes["y"].InnerText);
                }
            }
            // </start position>

            string clearCSV = "";

            for (int i = 0; i < map._height; i++)
            {
                for (int j = 0; j < map._width; j++)
                {
                    clearCSV += "0,";
                }
                clearCSV += "\n";
            }
            clearCSV = clearCSV.Trim();
            clearCSV = clearCSV[0..^ 1];